new Address(options)
Represents an address.
Parameters:
Name | Type | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
Properties
|
Properties:
Name | Type | Description |
---|---|---|
hash |
Buffer | |
type |
AddressPrefix | |
version |
Number | |
network |
Network |
- Source:
Members
(static) types :Number
Address types. Note that the values
have a direct mapping to script types.
These also represent the "prefix type"
as a network-agnostic version of the
prefix byte. They DO NOT represent the
script type. For example, script type
WITNESSMASTHASH
would be prefix type
WITNESSSCRIPTHASH
with a version
of 1.
Type:
- Number
Properties:
Name | Type | Description |
---|---|---|
PUBKEYHASH |
Number | |
SCRIPTHASH |
Number | |
WITNESSSCRIPTHASH |
Number | |
WITNESSPUBKEYHASH |
Number |
- Source:
(static, constant) typesByVal :RevMap
Address types by value.
Type:
- Source:
Methods
(static) fromBase58(address) → {Address}
Create an address object from a base58 address.
Parameters:
Name | Type | Description |
---|---|---|
address |
Base58Address |
- Source:
Throws:
Parse error.
Returns:
- Type
- Address
(static) fromHash(hash, type, versionopt, networknullable) → {Address}
Create a naked address from hash/type/version.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
hash |
Hash | |||
type |
AddressPrefix | |||
version |
Number |
<optional> |
-1 | |
network |
Network | NetworkType |
<nullable> |
- Source:
Throws:
on bad hash size
Returns:
- Type
- Address
(static) fromInputScript(script) → {Address|null}
Create an Address from an input script. Attempt to extract address properties from an input script.
Parameters:
Name | Type | Description |
---|---|---|
script |
Script |
- Source:
Returns:
- Type
- Address | null
(static) fromOptions(options) → {Address}
Insantiate address from options.
Parameters:
Name | Type | Description |
---|---|---|
options |
Object |
- Source:
Returns:
- Type
- Address
(static) fromProgram(version, hash, networknullable) → {Address}
Instantiate address from witness program.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
version |
Number | ||
hash |
Buffer | ||
network |
Network |
<nullable> |
- Source:
Returns:
- Type
- Address
(static) fromPubkeyhash(hash, networknullable) → {Address}
Instantiate address from pubkeyhash.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
hash |
Buffer | ||
network |
Network |
<nullable> |
- Source:
Returns:
- Type
- Address
(static) fromRaw(data) → {Address}
Create an address object from a serialized address.
Parameters:
Name | Type | Description |
---|---|---|
data |
Buffer |
- Source:
Throws:
Parse error.
Returns:
- Type
- Address
(static) fromScript(script) → {Address|null}
Create an Address from an output script. Parse an output script and extract address properties. Converts pubkey and multisig scripts to pubkeyhash and scripthash addresses.
Parameters:
Name | Type | Description |
---|---|---|
script |
Script |
- Source:
Returns:
- Type
- Address | null
(static) fromScripthash(hash, networknullable) → {Address}
Instantiate address from scripthash.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
hash |
Buffer | ||
network |
Network |
<nullable> |
- Source:
Returns:
- Type
- Address
(static) fromWitness(witness) → {Address|null}
Create an Address from a witness. Attempt to extract address properties from a witness.
Parameters:
Name | Type | Description |
---|---|---|
witness |
Witness |
- Source:
Returns:
- Type
- Address | null
(static) fromWitnessPubkeyhash(hash, networknullable) → {Address}
Instantiate address from witness pubkeyhash.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
hash |
Buffer | ||
network |
Network |
<nullable> |
- Source:
Returns:
- Type
- Address
(static) fromWitnessScripthash(hash, networknullable) → {Address}
Instantiate address from witness scripthash.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
hash |
Buffer | ||
network |
Network |
<nullable> |
- Source:
Returns:
- Type
- Address
(static) getHash(data, enc) → {Hash|null}
Get the hash of a base58 address or address-related object.
Parameters:
Name | Type | Description |
---|---|---|
data |
Base58Address | Address | Hash | |
enc |
String |
- Source:
Returns:
- Type
- Hash | null
(static) getPrefix(type, network) → {Number}
Get a network address prefix for a specified address type.
Parameters:
Name | Type | Description |
---|---|---|
type |
AddressPrefix | |
network |
Network |
- Source:
Returns:
- Type
- Number
(static) getType(prefix, network) → {AddressPrefix}
Get an address type for a specified network address prefix.
Parameters:
Name | Type | Description |
---|---|---|
prefix |
Number | |
network |
Network |
- Source:
Returns:
- Type
- AddressPrefix
(static) isWitness(type) → {Boolean}
Test whether an address type is a witness program.
Parameters:
Name | Type | Description |
---|---|---|
type |
AddressPrefix |
- Source:
Returns:
- Type
- Boolean
(private) fromBase58(data)
Inject properties from base58 address.
Parameters:
Name | Type | Description |
---|---|---|
data |
Base58Address |
- Source:
Throws:
Parse error
(private) fromHash(hash, type, versionopt, networknullable)
Inject properties from a hash.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
hash |
Buffer | Hash | |||
type |
AddressPrefix | |||
version |
Number |
<optional> |
-1 | |
network |
Network | NetworkType |
<nullable> |
- Source:
Throws:
on bad hash size
(private) fromInputScript(script)
Inject properties from input script.
Parameters:
Name | Type | Description |
---|---|---|
script |
Script |
- Source:
(private) fromOptions(options)
Inject properties from options object.
Parameters:
Name | Type | Description |
---|---|---|
options |
Object |
- Source:
(private) fromProgram(version, hash, networknullable) → {Address}
Inject properties from witness program.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
version |
Number | ||
hash |
Buffer | ||
network |
Network |
<nullable> |
- Source:
Returns:
- Type
- Address
(private) fromPubkeyhash(hash, networknullable) → {Address}
Inject properties from pubkeyhash.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
hash |
Buffer | ||
network |
Network |
<nullable> |
- Source:
Returns:
- Type
- Address
(private) fromRaw(data)
Inject properties from serialized data.
Parameters:
Name | Type | Description |
---|---|---|
data |
Buffer |
- Source:
Throws:
Parse error
(private) fromScript(script)
Inject properties from output script.
Parameters:
Name | Type | Description |
---|---|---|
script |
Script |
- Source:
(private) fromScripthash(hash, networknullable) → {Address}
Inject properties from scripthash.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
hash |
Buffer | ||
network |
Network |
<nullable> |
- Source:
Returns:
- Type
- Address
(private) fromWitness(witness)
Inject properties from witness.
Parameters:
Name | Type | Description |
---|---|---|
witness |
Witness |
- Source:
(private) fromWitnessPubkeyhash(hash, networknullable) → {Address}
Inject properties from witness pubkeyhash.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
hash |
Buffer | ||
network |
Network |
<nullable> |
- Source:
Returns:
- Type
- Address
(private) fromWitnessScripthash(hash, networknullable) → {Address}
Inject properties from witness scripthash.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
hash |
Buffer | ||
network |
Network |
<nullable> |
- Source:
Returns:
- Type
- Address
getHash(encnullable) → {Hash|Buffer}
Get the address hash.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
enc |
String |
<nullable> |
Can be |
- Source:
Returns:
- Type
- Hash | Buffer
getPrefix(networknullable) → {Number}
Get a network address prefix for the address.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
network |
Network |
<nullable> |
- Source:
Returns:
- Type
- Number
getSize() → {Number}
Calculate size of serialized address.
- Source:
Returns:
- Type
- Number
getType() → {AddressPrefix}
Get the address type as a string.
- Source:
Returns:
- Type
- AddressPrefix
inspect() → {Object}
Inspect the Address.
- Source:
Returns:
- Type
- Object
isNull() → {Boolean}
Test whether the address is null.
- Source:
Returns:
- Type
- Boolean
isProgram() → {Boolean}
Test whether the address is a witness program.
- Source:
Returns:
- Type
- Boolean
isPubkeyhash() → {Boolean}
Test whether the address is pubkeyhash.
- Source:
Returns:
- Type
- Boolean
isScripthash() → {Boolean}
Test whether the address is scripthash.
- Source:
Returns:
- Type
- Boolean
isWitnessMasthash() → {Boolean}
Test whether the address is witness masthash.
- Source:
Returns:
- Type
- Boolean
isWitnessPubkeyhash() → {Boolean}
Test whether the address is witness pubkeyhash.
- Source:
Returns:
- Type
- Boolean
isWitnessScripthash() → {Boolean}
Test whether the address is witness scripthash.
- Source:
Returns:
- Type
- Boolean
toBase58({{NetworkType|Network)?}) → {Base58Address}
Compile the address object to a base58 address.
Parameters:
Name | Type | Description |
---|---|---|
{{NetworkType|Network)?} |
network |
- Source:
Throws:
Error on bad hash/prefix.
Returns:
- Type
- Base58Address
toRaw({{NetworkType|Network)?}) → {Buffer}
Compile the address object to its raw serialization.
Parameters:
Name | Type | Description |
---|---|---|
{{NetworkType|Network)?} |
network |
- Source:
Throws:
Error on bad hash/prefix.
Returns:
- Type
- Buffer
toString() → {Base58Address}
Convert the Address to a string.
- Source:
Returns:
- Type
- Base58Address
verifyNetwork(network) → {Boolean}
Verify an address network (compares prefixes).
Parameters:
Name | Type | Description |
---|---|---|
network |
Network |
- Source:
Returns:
- Type
- Boolean