bsv-wasm-bundler
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -18,3 +18,66 @@ /* tslint:disable */ | ||
/** | ||
*/ | ||
export enum SigHash { | ||
FORKID, | ||
ALL, | ||
NONE, | ||
SINGLE, | ||
ANYONECANPAY, | ||
/** | ||
* | ||
* * ALL | FORKID | ||
* | ||
*/ | ||
InputsOutputs, | ||
/** | ||
* | ||
* * NONE | FORKID | ||
* | ||
*/ | ||
Inputs, | ||
/** | ||
* | ||
* * SINGLE | FORKID | ||
* | ||
*/ | ||
InputsOutput, | ||
/** | ||
* | ||
* * ALL | ANYONECANPAY | FORKID | ||
* | ||
*/ | ||
InputOutputs, | ||
/** | ||
* | ||
* * NONE | ANYONECANPAY | FORKID | ||
* | ||
*/ | ||
Input, | ||
/** | ||
* | ||
* * SINGLE | ANYONECANPAY | FORKID | ||
* | ||
*/ | ||
InputOutput, | ||
/** | ||
* | ||
* * ALL | ANYONECANPAY | ||
* | ||
*/ | ||
Legacy_InputOutputs, | ||
/** | ||
* | ||
* * NONE | ANYONECANPAY | ||
* | ||
*/ | ||
Legacy_Input, | ||
/** | ||
* | ||
* * SINGLE | ANYONECANPAY | ||
* | ||
*/ | ||
Legacy_InputOutput, | ||
} | ||
/** | ||
* | ||
* * This entire page is borrowed from rust-sv (https://github.com/brentongunning/rust-sv/blob/master/src/script/op_codes.rs) | ||
@@ -489,65 +552,2 @@ * | ||
*/ | ||
export enum SigHash { | ||
FORKID, | ||
ALL, | ||
NONE, | ||
SINGLE, | ||
ANYONECANPAY, | ||
/** | ||
* | ||
* * ALL | FORKID | ||
* | ||
*/ | ||
InputsOutputs, | ||
/** | ||
* | ||
* * NONE | FORKID | ||
* | ||
*/ | ||
Inputs, | ||
/** | ||
* | ||
* * SINGLE | FORKID | ||
* | ||
*/ | ||
InputsOutput, | ||
/** | ||
* | ||
* * ALL | ANYONECANPAY | FORKID | ||
* | ||
*/ | ||
InputOutputs, | ||
/** | ||
* | ||
* * NONE | ANYONECANPAY | FORKID | ||
* | ||
*/ | ||
Input, | ||
/** | ||
* | ||
* * SINGLE | ANYONECANPAY | FORKID | ||
* | ||
*/ | ||
InputOutput, | ||
/** | ||
* | ||
* * ALL | ANYONECANPAY | ||
* | ||
*/ | ||
Legacy_InputOutputs, | ||
/** | ||
* | ||
* * NONE | ANYONECANPAY | ||
* | ||
*/ | ||
Legacy_Input, | ||
/** | ||
* | ||
* * SINGLE | ANYONECANPAY | ||
* | ||
*/ | ||
Legacy_InputOutput, | ||
} | ||
/** | ||
*/ | ||
export enum PBKDF2Hashes { | ||
@@ -581,2 +581,36 @@ SHA1, | ||
* | ||
* * Bitcoin Signed Message | ||
* | ||
*/ | ||
export class BSM { | ||
free(): void; | ||
/** | ||
* | ||
* * Sign a message with the intention of verifying with this same Address. | ||
* * Used when using Bitcoin Signed Messages | ||
* * | ||
* * Returns boolean | ||
* | ||
* @param {Uint8Array} message | ||
* @param {Signature} signature | ||
* @param {P2PKHAddress} address | ||
* @returns {boolean} | ||
*/ | ||
static isValidMessage(message: Uint8Array, signature: Signature, address: P2PKHAddress): boolean; | ||
/** | ||
* @param {Uint8Array} message | ||
* @param {Signature} signature | ||
* @param {P2PKHAddress} address | ||
* @returns {boolean} | ||
*/ | ||
static verifyMessage(message: Uint8Array, signature: Signature, address: P2PKHAddress): boolean; | ||
/** | ||
* @param {PrivateKey} priv_key | ||
* @param {Uint8Array} message | ||
* @returns {Signature} | ||
*/ | ||
static signMessage(priv_key: PrivateKey, message: Uint8Array): Signature; | ||
} | ||
/** | ||
* | ||
* * A handy struct to allow calling of various utility methods | ||
@@ -609,3 +643,35 @@ * | ||
/** | ||
* | ||
* * Utility struct for low level ECDSA primitives | ||
* | ||
*/ | ||
export class ECDSA { | ||
free(): void; | ||
/** | ||
* @param {Uint8Array} message | ||
* @param {PublicKey} pub_key | ||
* @param {Signature} signature | ||
* @param {number} hash_algo | ||
* @returns {boolean} | ||
*/ | ||
static verify(message: Uint8Array, pub_key: PublicKey, signature: Signature, hash_algo: number): boolean; | ||
/** | ||
* @param {PrivateKey} private_key | ||
* @param {Uint8Array} preimage | ||
* @param {number} hash_algo | ||
* @param {boolean} reverse_k | ||
* @returns {Signature} | ||
*/ | ||
static signWithRandomK(private_key: PrivateKey, preimage: Uint8Array, hash_algo: number, reverse_k: boolean): Signature; | ||
/** | ||
* @param {PrivateKey} private_key | ||
* @param {Uint8Array} preimage | ||
* @param {number} hash_algo | ||
* @param {boolean} reverse_k | ||
* @returns {Signature} | ||
*/ | ||
static sign(private_key: PrivateKey, preimage: Uint8Array, hash_algo: number, reverse_k: boolean): Signature; | ||
} | ||
/** | ||
*/ | ||
export class ExtendedPrivateKey { | ||
@@ -815,4 +881,4 @@ free(): void; | ||
* | ||
* * Implementation of PBKDF2 - when None is specified for salt, a random salt will be generated | ||
* | ||
* * Implementation of PBKDF2 - when None is specified for salt, a random salt will be generated | ||
* | ||
* @param {Uint8Array} password | ||
@@ -848,2 +914,13 @@ * @param {Uint8Array | undefined} salt | ||
/** | ||
* | ||
* * Check if message is signed by this Address. | ||
* * | ||
* * Returns a boolean | ||
* | ||
* @param {Uint8Array} message | ||
* @param {Signature} signature | ||
* @returns {boolean} | ||
*/ | ||
isValidBitcoinMessage(message: Uint8Array, signature: Signature): boolean; | ||
/** | ||
* @param {Uint8Array} hash_bytes | ||
@@ -867,2 +944,23 @@ * @returns {P2PKHAddress} | ||
static fromP2PKHString(address_string: string): P2PKHAddress; | ||
/** | ||
* @returns {Script} | ||
*/ | ||
toLockingScript(): Script; | ||
/** | ||
* @param {PublicKey} pub_key | ||
* @param {Signature} sig | ||
* @returns {Script} | ||
*/ | ||
toUnlockingScript(pub_key: PublicKey, sig: Signature): Script; | ||
/** | ||
* | ||
* * Verify if message is signed by this Address. | ||
* * | ||
* * Throws an error if invalid. | ||
* | ||
* @param {Uint8Array} message | ||
* @param {Signature} signature | ||
* @returns {boolean} | ||
*/ | ||
verifyBitcoinMessage(message: Uint8Array, signature: Signature): boolean; | ||
} | ||
@@ -886,7 +984,16 @@ /** | ||
/** | ||
* @param {boolean} compressed | ||
* | ||
* * Finds the Public Key Point. | ||
* * Always returns the compressed point. | ||
* * To get the decompressed point: PublicKey::from_bytes(point).to_decompressed() | ||
* | ||
* @returns {Uint8Array} | ||
*/ | ||
getPoint(compressed: boolean): Uint8Array; | ||
getPoint(): Uint8Array; | ||
/** | ||
* @param {boolean} should_compress | ||
* @returns {PrivateKey} | ||
*/ | ||
compressPublicKey(should_compress: boolean): PrivateKey; | ||
/** | ||
* @param {string} wif_string | ||
@@ -903,14 +1010,12 @@ * @returns {PrivateKey} | ||
* | ||
* * SHA256s and then signs the specified message. | ||
* * Secp256k1 signature inputs must be 32 bytes in length, SHA256 is to ensure this. | ||
* | ||
* * Standard ECDSA Message Signing using SHA256 as the digestg | ||
* | ||
* @param {Uint8Array} msg | ||
* @returns {Signature} | ||
*/ | ||
sign(msg: Uint8Array): Signature; | ||
signMessage(msg: Uint8Array): Signature; | ||
/** | ||
* @param {boolean} compressed | ||
* @returns {string} | ||
*/ | ||
toWIF(compressed: boolean): string; | ||
toWIF(): string; | ||
/** | ||
@@ -921,2 +1026,6 @@ * @param {Uint8Array} bytes | ||
static fromBytes(bytes: Uint8Array): PrivateKey; | ||
/** | ||
* @returns {PublicKey} | ||
*/ | ||
getPublicKey(): PublicKey; | ||
} | ||
@@ -928,13 +1037,21 @@ /** | ||
/** | ||
* @param {Uint8Array} message | ||
* @param {Signature} signature | ||
* @returns {boolean} | ||
*/ | ||
isValidMessage(message: Uint8Array, signature: Signature): boolean; | ||
/** | ||
* @returns {boolean} | ||
*/ | ||
isCompressed(): boolean; | ||
/** | ||
* @param {string} hex_str | ||
* @param {boolean | undefined} compress | ||
* @returns {PublicKey} | ||
*/ | ||
static fromHex(hex_str: string, compress?: boolean): PublicKey; | ||
static fromHex(hex_str: string): PublicKey; | ||
/** | ||
* @param {Uint8Array} bytes | ||
* @param {boolean | undefined} compress | ||
* @returns {PublicKey} | ||
*/ | ||
static fromBytes(bytes: Uint8Array, compress?: boolean): PublicKey; | ||
static fromBytes(bytes: Uint8Array): PublicKey; | ||
/** | ||
@@ -950,6 +1067,23 @@ * @returns {Uint8Array} | ||
* @param {PrivateKey} priv_key | ||
* @param {boolean | undefined} compress | ||
* @returns {PublicKey} | ||
*/ | ||
static fromPrivateKey(priv_key: PrivateKey, compress?: boolean): PublicKey; | ||
static fromPrivateKey(priv_key: PrivateKey): PublicKey; | ||
/** | ||
* @param {Uint8Array} message | ||
* @param {Signature} signature | ||
* @returns {boolean} | ||
*/ | ||
verifyMessage(message: Uint8Array, signature: Signature): boolean; | ||
/** | ||
* @returns {P2PKHAddress} | ||
*/ | ||
toAddress(): P2PKHAddress; | ||
/** | ||
* @returns {PublicKey} | ||
*/ | ||
toCompressed(): PublicKey; | ||
/** | ||
* @returns {PublicKey} | ||
*/ | ||
toDecompressed(): PublicKey; | ||
} | ||
@@ -1000,2 +1134,8 @@ /** | ||
/** | ||
* @param {Signature} signature | ||
* @param {number} sighash_type | ||
* @param {Uint8Array} sighash_buffer | ||
*/ | ||
constructor(signature: Signature, sighash_type: number, sighash_buffer: Uint8Array); | ||
/** | ||
* @returns {string} | ||
@@ -1014,2 +1154,6 @@ */ | ||
/** | ||
* @returns {string} | ||
*/ | ||
toHex(): string; | ||
/** | ||
* @returns {Uint8Array} | ||
@@ -1019,21 +1163,34 @@ */ | ||
/** | ||
* @returns {Uint8Array} | ||
*/ | ||
toCompactBytes(): Uint8Array; | ||
/** | ||
* @param {Uint8Array} message | ||
* @param {PublicKey} pub_key | ||
* @returns {boolean} | ||
*/ | ||
verifyMessage(message: Uint8Array, pub_key: PublicKey): boolean; | ||
/** | ||
* @param {Uint8Array} bytes | ||
* @param {boolean} is_recoverable | ||
* @returns {Signature} | ||
*/ | ||
static fromDER(bytes: Uint8Array): Signature; | ||
static fromDER(bytes: Uint8Array, is_recoverable: boolean): Signature; | ||
/** | ||
* @param {string} hex | ||
* @param {boolean} is_recoverable | ||
* @returns {Signature} | ||
*/ | ||
static fromHexDER(hex: string): Signature; | ||
static fromHexDER(hex: string, is_recoverable: boolean): Signature; | ||
/** | ||
* @returns {string} | ||
* @param {Uint8Array} compact_bytes | ||
* @returns {Signature} | ||
*/ | ||
toHex(): string; | ||
static fromCompactBytes(compact_bytes: Uint8Array): Signature; | ||
/** | ||
* @param {Uint8Array} message | ||
* @param {PublicKey} pub_key | ||
* @returns {boolean} | ||
* @param {number} hash_algo | ||
* @returns {PublicKey} | ||
*/ | ||
verify(message: Uint8Array, pub_key: PublicKey): boolean; | ||
recoverPublicKey(message: Uint8Array, hash_algo: number): PublicKey; | ||
} | ||
@@ -1045,2 +1202,25 @@ /** | ||
/** | ||
* @param {PublicKey} pub_key | ||
* @param {SighashSignature} sig | ||
* @returns {boolean} | ||
*/ | ||
verify(pub_key: PublicKey, sig: SighashSignature): boolean; | ||
/** | ||
* @param {PrivateKey} priv_key | ||
* @param {number} sighash | ||
* @param {number} n_tx_in | ||
* @param {Script} unsigned_script | ||
* @param {BigInt} value | ||
* @returns {SighashSignature} | ||
*/ | ||
sign(priv_key: PrivateKey, sighash: number, n_tx_in: number, unsigned_script: Script, value: BigInt): SighashSignature; | ||
/** | ||
* @param {number} sighash | ||
* @param {number} n_tx_in | ||
* @param {Script} unsigned_script | ||
* @param {BigInt} value | ||
* @returns {Uint8Array} | ||
*/ | ||
sighashPreimage(sighash: number, n_tx_in: number, unsigned_script: Script, value: BigInt): Uint8Array; | ||
/** | ||
* @returns {number} | ||
@@ -1077,5 +1257,5 @@ */ | ||
* | ||
* * Creates a new empty transaction where you need to add inputs and outputs | ||
* * Transaction.add_input(TxIn) and Transaction.add_output(TxOut) | ||
* | ||
* * Creates a new empty transaction where you need to add inputs and outputs | ||
* * Transaction.add_input(TxIn) and Transaction.add_output(TxOut) | ||
* | ||
* @param {number} version | ||
@@ -1131,5 +1311,5 @@ * @param {number} n_locktime | ||
* | ||
* * Adds an array of TxIn's to the transaction | ||
* * @param {TxIn[]} tx_ins | ||
* | ||
* * Adds an array of TxIn's to the transaction | ||
* * @param {TxIn[]} tx_ins | ||
* | ||
* @param {any[]} tx_ins | ||
@@ -1140,5 +1320,5 @@ */ | ||
* | ||
* * Adds an array of TxOuts to the transaction | ||
* * @param {TxOut[]} tx_outs | ||
* | ||
* * Adds an array of TxOuts to the transaction | ||
* * @param {TxOut[]} tx_outs | ||
* | ||
* @param {any[]} tx_outs | ||
@@ -1149,4 +1329,4 @@ */ | ||
* | ||
* * Gets the ID of the current transaction as a hex string. | ||
* | ||
* * Gets the ID of the current transaction as a hex string. | ||
* | ||
* @returns {string} | ||
@@ -1157,24 +1337,7 @@ */ | ||
* | ||
* * Gets the ID of the current transaction as a Uint8Array. | ||
* | ||
* * Gets the ID of the current transaction as a Uint8Array. | ||
* | ||
* @returns {Uint8Array} | ||
*/ | ||
getIdBytes(): Uint8Array; | ||
/** | ||
* @param {PrivateKey} priv_key | ||
* @param {number} sighash | ||
* @param {number} n_tx_in | ||
* @param {Script} unsigned_script | ||
* @param {BigInt} value | ||
* @returns {SighashSignature} | ||
*/ | ||
sign(priv_key: PrivateKey, sighash: number, n_tx_in: number, unsigned_script: Script, value: BigInt): SighashSignature; | ||
/** | ||
* @param {number} sighash | ||
* @param {number} n_tx_in | ||
* @param {Script} unsigned_script | ||
* @param {BigInt} value | ||
* @returns {Uint8Array} | ||
*/ | ||
sighashPreimage(sighash: number, n_tx_in: number, unsigned_script: Script, value: BigInt): Uint8Array; | ||
} | ||
@@ -1181,0 +1344,0 @@ /** |
@@ -7,3 +7,3 @@ { | ||
"description": "A Bitcoin SV library with WASM in mind.", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"license": "MIT", | ||
@@ -10,0 +10,0 @@ "files": [ |
@@ -18,2 +18,14 @@ # BSV.WASM | ||
## Usage | ||
### Note: Rust and JS/TS method names and structs are the same | ||
- Derive private key from XPriv and log out P2PKH String | ||
`ExtendedPrivateKey.fromWIF('LMyWif...').getPrivateKey().getPublicKey().toAddress().toString()` | ||
## Caveats | ||
- Bitcoin Signed Message (BSM) struct does not implement any base64 string parsing, please pass the raw Signature type or call `fromCompactBytes` on the Signature struct and pass it to the BSM.verify function. | ||
## Features | ||
@@ -20,0 +32,0 @@ - Hash (SHA256, SHA256d, SHA1, RIPEMD160, Hash160, SHA512) |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
629729
4536
56