Class: KeyRing

primitives.KeyRing

new KeyRing(options, network)

Represents a key ring which amounts to an address.

Parameters:
Name Type Description
options Object
network Network
Source:

Methods

(static) fromJSON(json) → {KeyRing}

Instantiate an KeyRing from a jsonified transaction object.

Parameters:
Name Type Description
json Object

The jsonified transaction object.

Source:
Returns:
Type
KeyRing

(static) fromKey(publicKey, network) → {KeyRing}

Instantiate keyring from a public key.

Parameters:
Name Type Description
publicKey Buffer
network NetworkType | Network
Source:
Returns:
Type
KeyRing

(static) fromOptions(options) → {KeyRing}

Instantiate key ring from options.

Parameters:
Name Type Description
options Object
Source:
Returns:
Type
KeyRing

(static) fromPrivate(key, compressednullable, network) → {KeyRing}

Instantiate keyring from a private key.

Parameters:
Name Type Attributes Description
key Buffer
compressed Boolean <nullable>
network NetworkType | Network
Source:
Returns:
Type
KeyRing

(static) fromPublic(publicKey, network) → {KeyRing}

Instantiate keyring from a public key.

Parameters:
Name Type Description
publicKey Buffer
network NetworkType | Network
Source:
Returns:
Type
KeyRing

(static) fromRaw(data) → {KeyRing}

Instantiate a keyring from serialized data.

Parameters:
Name Type Description
data Buffer
Source:
Returns:
Type
KeyRing

(static) fromReader(br) → {KeyRing}

Instantiate a keyring from buffer reader.

Parameters:
Name Type Description
br BufferReader
Source:
Returns:
Type
KeyRing

(static) fromScript(key, script, network) → {KeyRing}

Instantiate keyring from script.

Parameters:
Name Type Description
key Buffer
script Script
network NetworkType | Network
Source:
Returns:
Type
KeyRing

(static) fromSecret(secret) → {KeyRing}

Instantiate a keyring from a serialized CBitcoinSecret.

Parameters:
Name Type Description
secret Base58String
Source:
Returns:
Type
KeyRing

(static) generate(networknullable) → {KeyRing}

Generate a keyring.

Parameters:
Name Type Attributes Description
network Network | NetworkType <nullable>
Source:
Returns:
Type
KeyRing

(static) isKeyRing(obj) → {Boolean}

Test whether an object is a KeyRing.

Parameters:
Name Type Description
obj Object
Source:
Returns:
Type
Boolean

(private) fromJSON(json)

Inject properties from json object.

Parameters:
Name Type Description
json Object
Source:

(private) fromKey(privateKey, network)

Inject data from public key.

Parameters:
Name Type Description
privateKey Buffer
network NetworkType | Network
Source:

(private) fromOptions(options)

Inject properties from options object.

Parameters:
Name Type Description
options Object
Source:

(private) fromPrivate(key, compressednullable, network)

Inject data from private key.

Parameters:
Name Type Attributes Description
key Buffer
compressed Boolean <nullable>
network NetworkType | Network
Source:

(private) fromPublic(key, network)

Inject data from public key.

Parameters:
Name Type Description
key Buffer
network NetworkType | Network
Source:

(private) fromRaw(data, networknullable)

Inject properties from serialized data.

Parameters:
Name Type Attributes Description
data Buffer
network Network <nullable>
Source:

(private) fromReader(br, networknullable)

Inject properties from buffer reader.

Parameters:
Name Type Attributes Description
br BufferReader
network Network <nullable>
Source:

(private) fromScript(key, script, network)

Inject data from script.

Parameters:
Name Type Description
key Buffer
script Script
network NetworkType | Network
Source:

(private) fromSecret(secret)

Inject properties from serialized CBitcoinSecret.

Parameters:
Name Type Description
secret Base58String
Source:

(private) generate(networknullable) → {KeyRing}

Generate a keyring.

Parameters:
Name Type Attributes Description
network Network | NetworkType <nullable>
Source:
Returns:
Type
KeyRing

getAddress(encnullable) → {Address|Base58Address}

Get base58 address.

Parameters:
Name Type Attributes Description
enc String <nullable>

"base58" or null.

Source:
Returns:
Type
Address | Base58Address

getHash(encnullable) → {Buffer}

Get hash.

Parameters:
Name Type Attributes Description
enc String <nullable>

"hex" or null.

Source:
Returns:
Type
Buffer

getKeyAddress(encnullable) → {Address|Base58Address}

Get pubkeyhash address.

Parameters:
Name Type Attributes Description
enc String <nullable>

"base58" or null.

Source:
Returns:
Type
Address | Base58Address

getKeyHash(encnullable) → {Buffer}

Get public key hash.

Parameters:
Name Type Attributes Description
enc String <nullable>

"hex" or null.

Source:
Returns:
Type
Buffer

getNestedAddress(encnullable) → {Address|Base58Address}

Get address' scripthash address for witness program.

Parameters:
Name Type Attributes Description
enc String <nullable>

"base58" or null.

Source:
Returns:
Type
Address | Base58Address

getNestedHash(encnullable) → {Buffer}

Get address' ripemd160 program scripthash (for witness programs behind a scripthash).

Parameters:
Name Type Attributes Description
enc String <nullable>

"hex" or null.

Source:
Returns:
Type
Buffer

getPrivateKey(encnullable) → {Buffer}

Get private key.

Parameters:
Name Type Attributes Description
enc String <nullable>

Can be "hex", "base58", or null.

Source:
Returns:

Private key.

Type
Buffer

getProgram() → {Buffer}

Get witness program.

Source:
Returns:
Type
Buffer

getPublicKey(encnullable) → {Buffer}

Get public key.

Parameters:
Name Type Attributes Description
enc String <nullable>

"hex" or null.

Source:
Returns:
Type
Buffer

getRedeem(hash) → {Script|null}

Test a hash against script hashes to find the correct redeem script, if any.

Parameters:
Name Type Description
hash Buffer
Source:
Returns:
Type
Script | null

getScript() → {Script}

Get redeem script.

Source:
Returns:
Type
Script

getScriptAddress(encnullable) → {Address|Base58Address}

Get scripthash address.

Parameters:
Name Type Attributes Description
enc String <nullable>

"base58" or null.

Source:
Returns:
Type
Address | Base58Address

getScriptHash(encnullable) → {Buffer}

Get scripthash.

Parameters:
Name Type Attributes Description
enc String <nullable>

"hex" or null.

Source:
Returns:
Type
Buffer

getScriptHash160(encnullable) → {Buffer}

Get ripemd160 scripthash.

Parameters:
Name Type Attributes Description
enc String <nullable>

"hex" or null.

Source:
Returns:
Type
Buffer

getScriptHash256(encnullable) → {Buffer}

Get sha256 scripthash.

Parameters:
Name Type Attributes Description
enc String <nullable>

"hex" or null.

Source:
Returns:
Type
Buffer

getSecretSize() → {Number}

Calculate WIF serialization size.

Source:
Returns:
Type
Number

getSize() → {Number}

Calculate serialization size.

Source:
Returns:
Type
Number

getType() → {ScriptType}

Get address type.

Source:
Returns:
Type
ScriptType

getVersion() → {Number}

Get witness program version.

Source:
Returns:
Type
Number

inspect() → {Object}

Inspect keyring.

Source:
Returns:
Type
Object

ownHash(hash) → {Boolean}

Test an address hash against hash and program hash.

Parameters:
Name Type Description
hash Buffer
Source:
Returns:
Type
Boolean

ownOutput(tx, indexnullable) → {Boolean}

Check whether transaction output belongs to this address.

Parameters:
Name Type Attributes Description
tx TX | Output

Transaction or Output.

index Number <nullable>

Output index.

Source:
Returns:
Type
Boolean

refresh()

Clear cached key/script hashes.

Source:

sign(msg) → {Buffer}

Sign a message.

Parameters:
Name Type Description
msg Buffer
Source:
Returns:

Signature in DER format.

Type
Buffer

toJSON() → {Object}

Convert an KeyRing to a more json-friendly object.

Source:
Returns:
Type
Object

toRaw() → {Buffer}

Serialize the keyring.

Source:
Returns:
Type
Buffer

toSecret(networknullable) → {Base58String}

Convert key to a CBitcoinSecret.

Parameters:
Name Type Attributes Description
network Network | NetworkType <nullable>
Source:
Returns:
Type
Base58String

toWriter(bw)

Write the keyring to a buffer writer.

Parameters:
Name Type Description
bw BufferWriter
Source:

verify(msg, sig) → {Boolean}

Verify a message.

Parameters:
Name Type Description
msg Buffer
sig Buffer

Signature in DER format.

Source:
Returns:
Type
Boolean

verifyNetwork(network) → {Boolean}

Verify network.

Parameters:
Name Type Description
network NetworkType | Network
Source:
Returns:
Type
Boolean