quantum-coin-js-sdk
v2.1.1
Published
Quantum Coin - Q SDK in JavaScript
Downloads
1,141
Maintainers
Readme
quantum-coin-js-sdk
Quantum Coin JS SDK provides low level functionality to interact with the Quantum Coin Blockchain. Example Project
Example
Requires Node.js version v20.18.1 or higher
Installation:
npm install quantum-coin-js-sdk --save
//Adding reference:
var qcsdk = require('quantum-coin-js-sdk');
//Example initialization with defaults for mainnet
//Initialize the SDK first before invoking any other function
qcsdk.initialize(null).then((initResult) => {
}
//Example initialization with specific values
//Initialize the SDK first before invoking any other function
var clientConfigVal = new qcsdk.Config(123123); //Initialization with Mainnet Config (Block Explorer: https://QuantumScan.com)
qcsdk.initialize(clientConfigVal).then((initResult) => {
}
Example Project: https://github.com/quantumcoinproject/quantum-coin-js-sdk/tree/main/exampleBrowser usage
The SDK runs in modern browsers as well as Node.js (Node 16+ / a browser with WebAssembly and the Web Crypto API). Load wasm_exec.js before index.js (or bundle them together) and call initialize() as usual.
- quantum-coin-js-sdk
- ~Config
- new Config(chainId)
- .chainId : number
- ~Wallet
- new Wallet(address, privateKey, publicKey, [preExpansionSeed])
- .address : string
- .privateKey : Array.<number>
- .publicKey : Array.<number>
- .preExpansionSeed : Uint8Array | Array.<number> | null
- ~SignResult
- .resultCode : number
- .txnHash : string
- .txnData : string
- ~TransactionSigningRequest
- new TransactionSigningRequest(wallet, toAddress, valueInWei, nonce, data, gasLimit, remarks, chainId, signingContext)
- .wallet : Wallet
- .toAddress : string | null
- .valueInWei : string | BigInt | null
- .nonce : number
- .data : string | null
- .gasLimit : number
- .remarks : string | null
- .chainId : number | null
- .signingContext : number | null
- ~PackUnpackResult
- new PackUnpackResult(error, result)
- .error : string
- .result : string
- ~EventLogEncodeResult
- new EventLogEncodeResult(error, result)
- .error : string
- .result : Object | null
- ~EventLogEncodeResult
- new EventLogEncodeResult(error, result)
- .error : string
- .result : Object | null
- ~circl
- ~initialize(clientConfig) ⇒ Promise.<boolean>
- ~isAddressValid(address) ⇒ boolean
- ~getKeyTypeFromPrivateKey(privateKey) ⇒ number | null
- ~getKeyTypeFromPublicKey(publicKey) ⇒ number | null
- ~toUint8Array(key) ⇒ Uint8Array
- ~newWallet(keyType) ⇒ Wallet | number
- ~newWalletSeedWords(keyType) ⇒ Array.<string> | number | null
- ~openWalletFromSeed(seedArray) ⇒ Wallet | number | null
- ~openWalletFromSeedWords(seedWordList) ⇒ Wallet | number | null
- ~deserializeEncryptedWallet(walletJsonString, passphrase) ⇒ Wallet
- ~serializeEncryptedWallet(wallet, passphrase) ⇒ string
- ~serializeSeedAsEncryptedWallet(seedArray, passphrase) ⇒ string | number | null
- ~verifyWallet(wallet) ⇒ boolean
- ~serializeWallet(wallet) ⇒ string
- ~deserializeWallet(walletJson) ⇒ Wallet | null
- ~~~signSendCoinTransaction(wallet, toAddress, coins, nonce) ⇒ Promise.<SignResult>~~
- ~~~signTransaction(wallet, toAddress, coins, nonce, data) ⇒ Promise.<SignResult>~~
- ~hexStringToUint8Array(hex) ⇒ Uint8Array
- ~signRawTransaction(transactionSigningRequest) ⇒ SignResult
- ~getGasPrice(keyType, [fullSign]) ⇒ Object
- ~sign(privateKey, message, [signingContext]) ⇒ Object
- ~verify(publicKey, signature, message) ⇒ Object
- ~publicKeyFromSignature(digest, signature) ⇒ string
- ~publicKeyFromPrivateKey(privateKey) ⇒ string
- ~addressFromPublicKey(publicKey) ⇒ string
- ~scryptDeriveKey(secret, salt, N, r, p, dkLen) ⇒ Array.<number>
- ~sha256(data) ⇒ Array.<number>
- ~sha512(data) ⇒ Array.<number>
- ~keccak256(data) ⇒ Array.<number>
- ~ripemd160(data) ⇒ Array.<number>
- ~computeHmac(algorithm, key, data) ⇒ Array.<number>
- ~pbkdf2(password, salt, iterations, keylen, algorithm) ⇒ Array.<number>
- ~combinePublicKeySignature(publicKey, signature) ⇒ string
- ~packMethodData(abiJSON, methodName, ...args) ⇒ PackUnpackResult
- ~unpackMethodData(abiJSON, methodName, hexData) ⇒ PackUnpackResult
- ~packCreateContractData(abiJSON, bytecode, ...args) ⇒ PackUnpackResult
- ~encodeEventLog(abiJSON, eventName, ...args) ⇒ EventLogEncodeResult
- ~decodeEventLog(abiJSON, eventName, topics, data) ⇒ PackUnpackResult
- ~encodeRlp(value) ⇒ PackUnpackResult
- ~decodeRlp(data) ⇒ PackUnpackResult
- ~createAddress(address, nonce) ⇒ string | null
- ~createAddress2(address, salt, initHash) ⇒ string | null
- ~Config
quantum-coin-js-sdk~Config
This is the configuration class required to initialize the Quantum Coin SDK for offline operations such as wallet management and transaction signing.
Kind: inner class of quantum-coin-js-sdk
Access: public
- ~Config
- new Config(chainId)
- .chainId : number
new Config(chainId)
Creates a config class
| Param | Type | Description | | --- | --- | --- | | chainId | number | The chain id of the blockchain. Mainnet chainId is 123123. Testnet T4 chainId is 310324. |
config.chainId : number
The chain id of the blockchain. Mainnet chainId is 123123. Testnet T4 chainId is 310324.
Kind: instance property of Config
Access: public
quantum-coin-js-sdk~Wallet
This class represents a Wallet. Use the verifyWallet function to verify if a wallet is valid. Verifying the wallet is highly recommended, especially if it comes from an untrusted source. For more details on the underlying cryptography of the Wallet, see https://github.com/quantumcoinproject/circl
Kind: inner class of quantum-coin-js-sdk
Access: public
- ~Wallet
- new Wallet(address, privateKey, publicKey, [preExpansionSeed])
- .address : string
- .privateKey : Array.<number>
- .publicKey : Array.<number>
- .preExpansionSeed : Uint8Array | Array.<number> | null
new Wallet(address, privateKey, publicKey, [preExpansionSeed])
Creates a Wallet class. The constructor does not verify the wallet. To verify a wallet, call the verifyWallet function explicitly.
| Param | Type | Default | Description | | --- | --- | --- | --- | | address | string | | Address of the wallet | | privateKey | Array.<number> | | Private Key byte array of the wallet | | publicKey | Array.<number> | | Public Key byte array of the wallet | | [preExpansionSeed] | Uint8Array | Array.<number> | null | | Optional pre-expansion seed bytes. Non-null only for seed-derived wallets. |
wallet.address : string
Address of the wallet. Is 66 bytes in length including 0x (if the wallet is valid).
Kind: instance property of Wallet
Access: public
wallet.privateKey : Array.<number>
Private Key byte array of the wallet. Is 4064 bytes in length (if the wallet is valid).
Kind: instance property of Wallet
Access: public
wallet.publicKey : Array.<number>
Public Key byte array of the wallet. Is 1408 bytes in length (if the wallet is valid).
Kind: instance property of Wallet
Access: public
wallet.preExpansionSeed : Uint8Array | Array.<number> | null
Pre-expansion seed bytes. Can be null if the wallet was not created from a seed.
Kind: instance property of Wallet
Access: public
quantum-coin-js-sdk~SignResult
This class represents a result from invoking the signSendCoinTransaction function.
Kind: inner class of quantum-coin-js-sdk
Access: public
- ~SignResult
- .resultCode : number
- .txnHash : string
- .txnData : string
signResult.resultCode : number
Represents the result of the operation. A value of 0 represents that the operation succeeded. Any other value indicates the operation failed. See the result code section for more details.
Kind: instance property of SignResult
Access: public
signResult.txnHash : string
Hash of the Transaction, to uniquely identify it. Is 66 bytes in length including 0x. This value is null if the value of resultCode is not 0.
Kind: instance property of SignResult
Access: public
signResult.txnData : string
A payload representing the signed transaction. To actually send a transaction, this payload can then be broadcast to the blockchain from a connected device (for example, via a relay or RPC endpoint). This value is null if the value of resultCode is not 0.
Kind: instance property of SignResult
Access: public
quantum-coin-js-sdk~TransactionSigningRequest
This class represents a signing request that can be passed to signTransaction.
Kind: inner class of quantum-coin-js-sdk
Access: public
- ~TransactionSigningRequest
- new TransactionSigningRequest(wallet, toAddress, valueInWei, nonce, data, gasLimit, remarks, chainId, signingContext)
- .wallet : Wallet
- .toAddress : string | null
- .valueInWei : string | BigInt | null
- .nonce : number
- .data : string | null
- .gasLimit : number
- .remarks : string | null
- .chainId : number | null
- .signingContext : number | null
new TransactionSigningRequest(wallet, toAddress, valueInWei, nonce, data, gasLimit, remarks, chainId, signingContext)
Creates a TransactionSigningRequest class.
| Param | Type | Description | | --- | --- | --- | | wallet | Wallet | The wallet with which the transaction has to be signed. The constructor does not verify the wallet. To verify a wallet, call the verifyWallet function explicitly. | | toAddress | string | The address to which the transaction request is made. Can be null (for example, for contract creation). | | valueInWei | string | BigInt | The value in wei-units. Can be provided as either a hex string (including 0x prefix) or a BigInt. For example, to represent 1 coin, which is 1000000000000000000 in wei-units, set the value to "0xDE0B6B3A7640000" or BigInt("1000000000000000000"). Conversion Examples | | nonce | number | A monotonically increasing number representing the nonce of the account signing the transaction. After each transaction from the account that gets registered in the blockchain, the nonce increases by 1. | | data | string | An optional hex string (including 0x) that represents the contract data. Can be null if not invoking or creating a contract. | | gasLimit | number | A limit of gas to be used. Set 21000 for basic non smart contract transactions. | | remarks | string | An optional hex string (including 0x) that represents a remark (such as a comment). Maximum 32 bytes length (in bytes). Warning, do not store any sensitive information in this field. | | chainId | number | null | The chain id of the blockchain. Mainnet chainId is 123123. Testnet T4 chainId is 310324. If null, the chainId specified in the initialize() function will be used. | | signingContext | number | null | It is recommended that you pass null for this parameter, unless the context needs to be set explicitly. Signing context determines the cryptographic scheme used to sign. The wallet key type should compatible with the signing context. Applicable values are 0,1,2. Default value if not specified will be determined dynamically from the wallet key type. Signing context 1,2 will incur additional gas fee. For information on the schemes, see https://github.com/quantumcoinproject/circl?tab=readme-ov-file#hybrid-schemes Signing context 0: Scheme used is hybrid-ed-mldsa-slhdsa compact (scheme id 3) Signing context 1: Scheme used is hybrid-ed-mldsa-slhdsa-5 (scheme id 5 : 20x the gas fee of scheme 0) Signing context 2: hybrid-ed-mldsa-slhdsa full (scheme id 4 : 30x the gas fee of scheme 0) |
transactionSigningRequest.wallet : Wallet
The wallet that should be used to sign the transaction.
Kind: instance property of TransactionSigningRequest
Access: public
transactionSigningRequest.toAddress : string | null
The address to which the transaction request is made. Can be null (for example, for contract creation).
Kind: instance property of TransactionSigningRequest
Access: public
transactionSigningRequest.valueInWei : string | BigInt | null
The value in wei-units. Can be provided as either a hex string (including 0x prefix) or a BigInt. For example, to represent 1 coin, which is 1000000000000000000 in wei-units, set the value to "0xDE0B6B3A7640000" or BigInt("1000000000000000000"). Conversion Examples
Kind: instance property of TransactionSigningRequest
Access: public
transactionSigningRequest.nonce : number
A monotonically increasing number representing the nonce of the account signing the transaction. After each transaction from the account that gets registered in the blockchain, the nonce increases by 1.
Kind: instance property of TransactionSigningRequest
Access: public
transactionSigningRequest.data : string | null
An optional hex string (including 0x) that represents the contract data. Can be null if not invoking or creating a contract.
Kind: instance property of TransactionSigningRequest
Access: public
transactionSigningRequest.gasLimit : number
A limit of gas to be used. Set 21000 for basic non smart contract transactions.
Kind: instance property of TransactionSigningRequest
Access: public
transactionSigningRequest.remarks : string | null
An optional hex string (including 0x) that represents a remark (such as a comment). Maximum 32 bytes length (in bytes). Warning, do not store any sensitive information in this field.
Kind: instance property of TransactionSigningRequest
Access: public
transactionSigningRequest.chainId : number | null
The chain id of the blockchain. Mainnet chainId is 123123. If null, the chainId specified in the initialize() function will be used.
Kind: instance property of TransactionSigningRequest
Access: public
transactionSigningRequest.signingContext : number | null
It is recommended that you pass null for this parameter, unless the context needs to be set explicitly. Signing context determines the cryptographic scheme used to sign. Gas fee varies by context.
Kind: instance property of TransactionSigningRequest
Access: public
quantum-coin-js-sdk~PackUnpackResult
This class represents a result from invoking the packMethodData or unpackMethodData functions.
Kind: inner class of quantum-coin-js-sdk
Access: public
- ~PackUnpackResult
- new PackUnpackResult(error, result)
- .error : string
- .result : string
new PackUnpackResult(error, result)
Creates a PackUnpackResult class.
| Param | Type | Description | | --- | --- | --- | | error | string | Error message if any. Empty string if no error. | | result | string | The actual result as a string. Empty string if there was an error. |
packUnpackResult.error : string
Error message if any. Empty string if no error.
Kind: instance property of PackUnpackResult
Access: public
packUnpackResult.result : string
The actual result as a string. Empty string if there was an error.
Kind: instance property of PackUnpackResult
Access: public
quantum-coin-js-sdk~EventLogEncodeResult
This class represents a result from invoking the encodeEventLog function.
Kind: inner class of quantum-coin-js-sdk
- ~EventLogEncodeResult
- new EventLogEncodeResult(error, result)
- .error : string
- .result : Object | null
new EventLogEncodeResult(error, result)
Creates an EventLogEncodeResult class.
| Param | Type | Description | | --- | --- | --- | | error | string | Error message if any. Empty string if no error. | | result | Object | null | The actual result object with topics and data. Null if there was an error. | | result.topics | Array.<string> | Array of topic hex strings (with 0x prefix) | | result.data | string | Hex-encoded data string (with 0x prefix) |
eventLogEncodeResult.error : string
Error message if any. Empty string if no error.
Kind: instance property of EventLogEncodeResult
Access: public
eventLogEncodeResult.result : Object | null
The actual result object with topics and data. Null if there was an error.
Kind: instance property of EventLogEncodeResult
Access: public
Properties
| Name | Type | Description | | --- | --- | --- | | topics | Array.<string> | Array of topic hex strings (with 0x prefix) | | data | string | Hex-encoded data string (with 0x prefix) |
quantum-coin-js-sdk~EventLogEncodeResult
Kind: inner class of quantum-coin-js-sdk
- ~EventLogEncodeResult
- new EventLogEncodeResult(error, result)
- .error : string
- .result : Object | null
new EventLogEncodeResult(error, result)
Creates an EventLogEncodeResult class.
| Param | Type | Description | | --- | --- | --- | | error | string | Error message if any. Empty string if no error. | | result | Object | null | The actual result object with topics and data. Null if there was an error. | | result.topics | Array.<string> | Array of topic hex strings (with 0x prefix) | | result.data | string | Hex-encoded data string (with 0x prefix) |
eventLogEncodeResult.error : string
Error message if any. Empty string if no error.
Kind: instance property of EventLogEncodeResult
Access: public
eventLogEncodeResult.result : Object | null
The actual result object with topics and data. Null if there was an error.
Kind: instance property of EventLogEncodeResult
Access: public
Properties
| Name | Type | Description | | --- | --- | --- | | topics | Array.<string> | Array of topic hex strings (with 0x prefix) | | data | string | Hex-encoded data string (with 0x prefix) |
quantum-coin-js-sdk~circl
CIRCL WASM namespace (set after InitAccountsWebAssembly). Use getCircl() for access.
Kind: inner property of quantum-coin-js-sdk
quantum-coin-js-sdk~initialize(clientConfig) ⇒ Promise.<boolean>
The initialize function has to be called before attempting to invoke any other function. This function should be called only once.
Kind: inner method of quantum-coin-js-sdk
Returns: Promise.<boolean> - Returns a promise of type boolean; true if the initialization succeeded, else false.
| Param | Type | Description | | --- | --- | --- | | clientConfig | Config | undefined | A configuration represented by the Config class. A default configuration is used, if not specified. |
quantum-coin-js-sdk~isAddressValid(address) ⇒ boolean
The isAddressValid function validates whether an address is valid or not. An address is of length 66 characters including 0x.
Kind: inner method of quantum-coin-js-sdk
Returns: boolean - Returns true if the address validation succeeded, else returns false.
| Param | Type | Description | | --- | --- | --- | | address | string | A string representing the address to validate. |
quantum-coin-js-sdk~getKeyTypeFromPrivateKey(privateKey) ⇒ number | null
Internal: get key type (KEY_TYPE_HYBRIDEDMLDSASLHDSA or KEY_TYPE_HYBRIDEDMLDSASLHDSA5) from private key length.
Kind: inner method of quantum-coin-js-sdk
Returns: number | null - KEY_TYPE_HYBRIDEDMLDSASLHDSA (3), KEY_TYPE_HYBRIDEDMLDSASLHDSA5 (5), or null on error.
| Param | Type | Description | | --- | --- | --- | | privateKey | Array.<number> | Uint8Array | Wallet private key bytes. |
quantum-coin-js-sdk~getKeyTypeFromPublicKey(publicKey) ⇒ number | null
Internal: get key type (KEY_TYPE_HYBRIDEDMLDSASLHDSA or KEY_TYPE_HYBRIDEDMLDSASLHDSA5) from public key length.
Kind: inner method of quantum-coin-js-sdk
Returns: number | null - KEY_TYPE_HYBRIDEDMLDSASLHDSA (3), KEY_TYPE_HYBRIDEDMLDSASLHDSA5 (5), or null on error.
| Param | Type | Description | | --- | --- | --- | | publicKey | Array.<number> | Uint8Array | Public key bytes. |
quantum-coin-js-sdk~toUint8Array(key) ⇒ Uint8Array
Convert key (number[] or Uint8Array) to Uint8Array for CIRCL.
Kind: inner method of quantum-coin-js-sdk
| Param | Type | Description | | --- | --- | --- | | key | Array.<number> | Uint8Array | Key bytes. |
quantum-coin-js-sdk~newWallet(keyType) ⇒ Wallet | number
The newWallet function creates a new Wallet.
Kind: inner method of quantum-coin-js-sdk
Returns: Wallet | number - Returns a Wallet object, or -1000 (not initialized), -1001 (invalid key type), -1002 (crypto failure).
| Param | Type | Description | | --- | --- | --- | | keyType | number | null | Optional. KEY_TYPE_HYBRIDEDMLDSASLHDSA (3) or KEY_TYPE_HYBRIDEDMLDSASLHDSA5 (5). null/undefined defaults to 3. |
quantum-coin-js-sdk~newWalletSeedWords(keyType) ⇒ Array.<string> | number | null
The newWalletSeedWords function creates a new wallet seed word list. The returned array can then be passed to the openWalletFromSeedWords function to create a new wallet.
Kind: inner method of quantum-coin-js-sdk
Returns: Array.<string> | number | null - Returns an array of seed words (32 or 36 words depending on keyType). Returns -1000 if not initialized, null on failure.
| Param | Type | Description | | --- | --- | --- | | keyType | number | null | Optional. KEY_TYPE_HYBRIDEDMLDSASLHDSA (3) or KEY_TYPE_HYBRIDEDMLDSASLHDSA5 (5). null/undefined defaults to 3. |
quantum-coin-js-sdk~openWalletFromSeed(seedArray) ⇒ Wallet | number | null
The openWalletFromSeed function creates a wallet from a raw seed byte array. Determines the key scheme from the array length: 96 bytes (hybrideds), 72 bytes (hybrid5), or 64 bytes (hybrid).
Kind: inner method of quantum-coin-js-sdk
Returns: Wallet | number | null - Returns a Wallet object. Returns -1000 if not initialized, null if the operation failed.
| Param | Type | Description | | --- | --- | --- | | seedArray | Array.<number> | Uint8Array | The raw seed bytes. Length 96, 72, or 64 depending on scheme. |
quantum-coin-js-sdk~openWalletFromSeedWords(seedWordList) ⇒ Wallet | number | null
The openWalletFromSeedWords function creates a wallet from a seed word list. The seed word list is available for wallets created from Desktop/Web/Mobile wallets. Supports 48 words (hybrideds), 36 words (hybrid5), or 32 words (hybrid) per seed length.
Kind: inner method of quantum-coin-js-sdk
Returns: Wallet | number | null - Returns a Wallet object. Returns -1000 if not initialized, null if the operation failed.
| Param | Type | Description | | --- | --- | --- | | seedWordList | Array.<string> | An array of seed words. Length 48, 36, or 32 depending on scheme. |
quantum-coin-js-sdk~deserializeEncryptedWallet(walletJsonString, passphrase) ⇒ Wallet
The deserializeEncryptedWallet function opens a wallet backed-up using an application such as the Desktop/Mobile/CLI/Web wallet. This function can take upto a minute or so to execute. You should open wallets only from trusted sources.
Kind: inner method of quantum-coin-js-sdk
Returns: Wallet - Returns a Wallet object. Returns null if opening the wallet fails.
| Param | Type | Description | | --- | --- | --- | | walletJsonString | string | The json string from a wallet file. | | passphrase | string | The passphrase used to encrypt the wallet. |
quantum-coin-js-sdk~serializeEncryptedWallet(wallet, passphrase) ⇒ string
The serializeEncryptedWallet function encrypts and serializes a Wallet object to a JSON string readable by the Desktop/Mobile/Web/CLI wallet applications. You can save this string to a file and open the file in one of these wallet applications. You may also open this string using the deserializeEncryptedWallet function. If you loose the passphrase, you will be unable to open the wallet. This function can take upto a minute or so to execute.
Kind: inner method of quantum-coin-js-sdk
Returns: string - Returns the Wallet in JSON string format. If the wallet is invalid, null is returned.
| Param | Type | Description | | --- | --- | --- | | wallet | Wallet | A Wallet object representing the wallet to serialize. | | passphrase | string | A passphrase used to encrypt the wallet. It should atleast be 12 characters long. |
quantum-coin-js-sdk~serializeSeedAsEncryptedWallet(seedArray, passphrase) ⇒ string | number | null
The serializeSeedAsEncryptedWallet function encrypts a raw seed byte array into a wallet JSON string that can be opened with deserializeEncryptedWallet or Desktop/Mobile/Web/CLI wallet applications. The seed is stored in its pre-expansion form (version 5 wallet format). This function can take up to a minute or so to execute due to key derivation.
Kind: inner method of quantum-coin-js-sdk
Returns: string | number | null - Returns the encrypted wallet JSON string. Returns -1000 if not initialized, null if the operation failed.
| Param | Type | Description | | --- | --- | --- | | seedArray | Array.<number> | Uint8Array | The raw seed bytes. Length must be 96, 72, or 64 depending on scheme. | | passphrase | string | A passphrase used to encrypt the wallet. Must be at least 12 characters long. |
quantum-coin-js-sdk~verifyWallet(wallet) ⇒ boolean
The verifyWallet function verifies whether a Wallet is valid or not. To mitigate spoofing and other attachs, it is highly recommended to verify a wallet, especially if it is from an untrusted source.
Kind: inner method of quantum-coin-js-sdk
Returns: boolean - Returns true if the Wallet verification succeeded, else returns false.
| Param | Type | Description | | --- | --- | --- | | wallet | Wallet | A Wallet object representing the wallet to verify. |
quantum-coin-js-sdk~serializeWallet(wallet) ⇒ string
The serializeWallet function serializes a Wallet object to a JSON string. You should encrypt the string before saving it to disk or a database.
Kind: inner method of quantum-coin-js-sdk
Returns: string - Returns the Wallet in JSON string format. If the wallet is invalid, null is returned.
| Param | Type | Description | | --- | --- | --- | | wallet | Wallet | A Wallet object representing the wallet to serialize. |
quantum-coin-js-sdk~deserializeWallet(walletJson) ⇒ Wallet | null
The deserializeWallet function creates a Wallet object from a JSON string.
Kind: inner method of quantum-coin-js-sdk
Returns: Wallet | null - Returns the Wallet corresponding to the walletJson. If the wallet is invalid or the JSON is malformed, null is returned.
| Param | Type | Description | | --- | --- | --- | | walletJson | string | A JSON string representing the wallet to deserialize. |
~~quantum-coin-js-sdk~signSendCoinTransaction(wallet, toAddress, coins, nonce) ⇒ Promise.<SignResult>~~
Use signRawTransaction instead.
The signSendCoinTransaction function returns a signed transaction. The chainId used for signing should be provided in the initialize() function. Since the gas fee for sending coins is fixed at 1000 coins, there is no option to set the gas fee explicitly. This function is useful for offline (cold storage) wallets, where you can sign a transaction offline and then broadcast it from a connected device (for example, via a relay or RPC endpoint). Another usecase for this function is when you want to first store a signed transaction to a database, then queue it and finally broadcast the transaction from a connected device.
Kind: inner method of quantum-coin-js-sdk
Returns: Promise.<SignResult> - Returns a promise of type SignResult.
| Param | Type | Description | | --- | --- | --- | | wallet | Wallet | A Wallet object from which the transaction has to be sent. The address corresponding to the Wallet should have enough coins to cover gas fees as well. A minimum of 1000 coins (1000000000000000000000 wei) are required for gas fees. | | toAddress | string | The address to which the coins should be sent. | | coins | string | The string representing the number of coins (in ether) to send. To convert between ethers and wei, see https://docs.ethers.org/v4/api-utils.html#ether-strings-and-wei | | nonce | number | A monotonically increasing number representing the nonce of the account. You have to carefully manage the state of the nonce to avoid sending the coins multiple times, such as when retrying after an error. |
~~quantum-coin-js-sdk~signTransaction(wallet, toAddress, coins, nonce, data) ⇒ Promise.<SignResult>~~
Use signRawTransaction instead.
The signTransaction function returns a signed transaction. The chainId used for signing should be provided in the initialize() function. Since the gas fee for sending coins is fixed at 1000 coins, there is no option to set the gas fee explicitly. This function is useful for offline (cold storage) wallets, where you can sign a transaction offline and then broadcast it from a connected device (for example, via a relay or RPC endpoint). Another usecase for this function is when you want to first store a signed transaction to a database, then queue it and finally broadcast the transaction from a connected device.
Kind: inner method of quantum-coin-js-sdk
Returns: Promise.<SignResult> - Returns a promise of type SignResult.
| Param | Type | Description | | --- | --- | --- | | wallet | Wallet | A Wallet object from which the transaction has to be sent. The address corresponding to the Wallet should have enough coins to cover gas fees as well. A minimum of 1000 coins (1000000000000000000000 wei) are required for gas fees. | | toAddress | string | The address to which the coins should be sent. | | coins | string | The string representing the number of coins (in ether) to send. To convert between ethers and wei, see https://docs.ethers.org/v4/api-utils.html#ether-strings-and-wei | | nonce | number | A monotonically increasing number representing the nonce of the account. You have to carefully manage the state of the nonce to avoid sending the coins multiple times, such as when retrying after an error. | | data | string | Ignored. This parameter is accepted but not used. Use signRawTransaction to pass contract data. |
quantum-coin-js-sdk~hexStringToUint8Array(hex) ⇒ Uint8Array
Helper function to convert a hex string to Uint8Array
Kind: inner method of quantum-coin-js-sdk
Returns: Uint8Array - Uint8Array representation of the hex string, or empty array if null/undefined
| Param | Type | Description | | --- | --- | --- | | hex | string | Hex string with or without 0x prefix |
quantum-coin-js-sdk~signRawTransaction(transactionSigningRequest) ⇒ SignResult
The signRawTransaction function returns a signed transaction. The chainId used for signing can be provided in the TransactionSigningRequest, or if null, the chainId specified in the initialize() function will be used. With this function, you can set the gasLimit explicitly compared to signTransaction. You can also pass data to be signed, such as when creating or invoking a smart contract. Since the gas fee is fixed at 1000 coins for 21000 units of gas, there is no option to set the gas fee explicitly. This function is useful for offline (cold storage) wallets, where you can sign a transaction offline and then broadcast it from a connected device (for example, via a relay or RPC endpoint). Another usecase for this function is when you want to first store a signed transaction to a database, then queue it and finally broadcast the transaction from a connected device.
Kind: inner method of quantum-coin-js-sdk
Returns: SignResult - Returns a promise of type SignResult.
| Param | Type | Description | | --- | --- | --- | | transactionSigningRequest | TransactionSigningRequest | An object of type TransactionSigningRequest with the transaction signing details. |
quantum-coin-js-sdk~getGasPrice(keyType, [fullSign]) ⇒ Object
Returns the gas price per unit of gas (per-gas-unit), in wei, for the signing context implied by keyType and fullSign. This is NOT the total transaction fee (total fee = gasPrice * gasLimit). fullSign is ignored for keyType 5 (always context 1); it only affects keyType 3 (false = compact/context 0, true = full/context 2).
Kind: inner method of quantum-coin-js-sdk
Returns: Object - { resultCode, gasPrice }: resultCode 0 and gasPrice as a decimal wei string on success; negative resultCode with null gasPrice on invalid keyType.
| Param | Type | Description | | --- | --- | --- | | keyType | number | 3 (HYBRIDEDMLDSASLHDSA) or 5 (HYBRIDEDMLDSASLHDSA5). | | [fullSign] | boolean | null | Optional. Use full (non-compact) signing for keyType 3. Ignored for keyType 5. Defaults to false. |
quantum-coin-js-sdk~sign(privateKey, message, [signingContext]) ⇒ Object
Sign a message with a private key. Optional signingContext selects algorithm (same pattern as signRawTransaction); if null/omitted, derived from private key type.
Kind: inner method of quantum-coin-js-sdk
Returns: Object - resultCode 0 on success, signature bytes; negative on error (e.g. -1000 not initialized, -700 invalid args, -701 unknown key type, -702/-703 CIRCL sign error, -704 unsupported key type or context).
| Param | Type | Description | | --- | --- | --- | | privateKey | Array.<number> | Uint8Array | Private key bytes. | | message | Array.<number> | Uint8Array | Message bytes (e.g. 32-byte hash). | | [signingContext] | number | null | Optional. 0 = hybridedmldsaslhdsa compact, 1 = hybridedmldsaslhdsa5, 2 = hybridedmldsaslhdsa full. If null/omitted, derived from private key type. |
quantum-coin-js-sdk~verify(publicKey, signature, message) ⇒ Object
Verify a signature over a message with a public key. Algorithm is determined by the first byte of the signature: 1=hybrideds verifyCompact, 2=hybrideds verify, 3=hybridedmldsaslhdsa verifyCompact, 4=hybridedmldsaslhdsa verify, 5=hybridedmldsaslhdsa5 verify.
Kind: inner method of quantum-coin-js-sdk
Returns: Object - resultCode 0 and valid true if signature is valid; negative on error (e.g. -1000 not initialized, -715 invalid args, -717 CIRCL verify error, -719 signature invalid, -718 unknown signature type).
| Param | Type | Description | | --- | --- | --- | | publicKey | Array.<number> | Uint8Array | Public key bytes. | | signature | Array.<number> | Uint8Array | Signature bytes from sign(); first byte selects verify function (1-5). | | message | Array.<number> | Uint8Array | Message bytes (same as passed to sign). |
quantum-coin-js-sdk~publicKeyFromSignature(digest, signature) ⇒ string
The publicKeyFromSignature extracts the public key from a signature.
Kind: inner method of quantum-coin-js-sdk
Returns: string - - Returns the public key as a hex string. Returns null if the operation failed.
| Param | Type | Description | | --- | --- | --- | | digest | Array.<number> | An array of bytes containing the digestHash. Should be of length 32. | | signature | Array.<number> | An array of bytes containing the signature. |
quantum-coin-js-sdk~publicKeyFromPrivateKey(privateKey) ⇒ string
The publicKeyFromPrivateKey extracts the public key from a private key.
Kind: inner method of quantum-coin-js-sdk
Returns: string - - Returns the public key as a hex string. Returns null if the operation failed.
| Param | Type | Description | | --- | --- | --- | | privateKey | Array.<number> | An array of bytes containing the privateKey. |
quantum-coin-js-sdk~addressFromPublicKey(publicKey) ⇒ string
The addressFromPublicKey returns the address corresponding to the public key.
Kind: inner method of quantum-coin-js-sdk
Returns: string - - Returns the address corresponding to the public key as a hex string. Returns null if the operation failed.
| Param | Type | Description | | --- | --- | --- | | publicKey | Array.<number> | An array of bytes containing the public key. |
quantum-coin-js-sdk~scryptDeriveKey(secret, salt, N, r, p, dkLen) ⇒ Array.<number>
The scryptDeriveKey function derives a key from a secret and salt using the scrypt KDF.
Arbitrary scrypt parameters are supported. The classic set N=262144, r=8, p=1, dkLen=32 remains fully supported and byte-for-byte compatible with previous versions.
Kind: inner method of quantum-coin-js-sdk
Returns: Array.<number> - - Returns the derived key as a byte array. Returns -1000 before initialize(), or null if the operation failed or the parameters are invalid.
| Param | Type | Description | | --- | --- | --- | | secret | string | Uint8Array | Array.<number> | The secret/passphrase. A string is encoded as UTF-8 bytes. | | salt | Uint8Array | Array.<number> | The salt as a byte array. | | N | number | The scrypt CPU/memory cost parameter (power of two, > 1). | | r | number | The scrypt block size parameter. | | p | number | The scrypt parallelization parameter. | | dkLen | number | The derived key length in bytes. |
quantum-coin-js-sdk~sha256(data) ⇒ Array.<number>
The sha256 function computes the SHA-256 digest of the input.
Kind: inner method of quantum-coin-js-sdk
Returns: Array.<number> - - The 32-byte digest as a byte array. Returns -1000 before initialize(), or null on invalid input.
| Param | Type | Description | | --- | --- | --- | | data | string | Uint8Array | Array.<number> | The data to hash (string -> UTF-8 bytes). |
quantum-coin-js-sdk~sha512(data) ⇒ Array.<number>
The sha512 function computes the SHA-512 digest of the input.
Kind: inner method of quantum-coin-js-sdk
Returns: Array.<number> - - The 64-byte digest as a byte array. Returns -1000 before initialize(), or null on invalid input.
| Param | Type | Description | | --- | --- | --- | | data | string | Uint8Array | Array.<number> | The data to hash (string -> UTF-8 bytes). |
quantum-coin-js-sdk~keccak256(data) ⇒ Array.<number>
The keccak256 function computes the Keccak-256 digest of the input. This is the Ethereum-style Keccak-256 (legacy padding), not SHA3-256.
Kind: inner method of quantum-coin-js-sdk
Returns: Array.<number> - - The 32-byte digest as a byte array. Returns -1000 before initialize(), or null on invalid input.
| Param | Type | Description | | --- | --- | --- | | data | string | Uint8Array | Array.<number> | The data to hash (string -> UTF-8 bytes). |
quantum-coin-js-sdk~ripemd160(data) ⇒ Array.<number>
The ripemd160 function computes the RIPEMD-160 digest of the input.
Kind: inner method of quantum-coin-js-sdk
Returns: Array.<number> - - The 20-byte digest as a byte array. Returns -1000 before initialize(), or null on invalid input.
| Param | Type | Description | | --- | --- | --- | | data | string | Uint8Array | Array.<number> | The data to hash (string -> UTF-8 bytes). |
quantum-coin-js-sdk~computeHmac(algorithm, key, data) ⇒ Array.<number>
The computeHmac function computes an HMAC over the data using the given key.
Kind: inner method of quantum-coin-js-sdk
Returns: Array.<number> - - The HMAC as a byte array. Returns -1000 before initialize(), or null on invalid input.
| Param | Type | Description | | --- | --- | --- | | algorithm | string | The hash algorithm: "sha256" or "sha512". | | key | string | Uint8Array | Array.<number> | The HMAC key (string -> UTF-8 bytes). | | data | string | Uint8Array | Array.<number> | The data to authenticate (string -> UTF-8 bytes). |
quantum-coin-js-sdk~pbkdf2(password, salt, iterations, keylen, algorithm) ⇒ Array.<number>
The pbkdf2 function derives a key using PBKDF2.
Kind: inner method of quantum-coin-js-sdk
Returns: Array.<number> - - The derived key as a byte array. Returns -1000 before initialize(), or null on invalid input.
| Param | Type | Description | | --- | --- | --- | | password | string | Uint8Array | Array.<number> | The password (string -> UTF-8 bytes). | | salt | Uint8Array | Array.<number> | The salt as a byte array. | | iterations | number | The iteration count (positive integer). | | keylen | number | The derived key length in bytes (positive integer). | | algorithm | string | The PRF hash algorithm: "sha256" or "sha512". |
quantum-coin-js-sdk~combinePublicKeySignature(publicKey, signature) ⇒ string
The combinePublicKeySignature combines the public key and signature.
Kind: inner method of quantum-coin-js-sdk
Returns: string - - Returns a hex string corresponding to combined signature. Returns null if the operation failed.
| Param | Type | Description | | --- | --- | --- | | publicKey | Array.<number> | An array of bytes containing the public key. | | signature | Array.<number> | An array of bytes containing the signature. |
quantum-coin-js-sdk~packMethodData(abiJSON, methodName, ...args) ⇒ PackUnpackResult
The packMethodData function packs a Solidity method call with the given ABI, method name, and arguments. It returns the transaction data as a hex string that can be included in a transaction.
Kind: inner method of quantum-coin-js-sdk
Returns: PackUnpackResult - - Returns a PackUnpackResult object containing the error (if any) and the packed transaction data as a hex string.
| Param | Type | Description | | --- | --- | --- | | abiJSON | string | The Solidity ABI file content as a JSON string | | methodName | string | The name of the method to call | | ...args | * | The parameters to pass to the method (variable arguments) |
quantum-coin-js-sdk~unpackMethodData(abiJSON, methodName, hexData) ⇒ PackUnpackResult
The unpackMethodData function unpacks the return values of a Solidity method call. It returns the unpacked values as a JavaScript array or object.
Kind: inner method of quantum-coin-js-sdk
Returns: PackUnpackResult - - Returns a PackUnpackResult object containing the error (if any) and the unpacked return values as a JSON string.
| Param | Type | Description | | --- | --- | --- | | abiJSON | string | The Solidity ABI file content as a JSON string | | methodName | string | The name of the method whose return values to unpack | | hexData | string | The hex-encoded return data (with or without 0x prefix) |
quantum-coin-js-sdk~packCreateContractData(abiJSON, bytecode, ...args) ⇒ PackUnpackResult
The packCreateContractData function packs constructor data for contract creation. It combines the contract bytecode with the ABI-encoded constructor parameters. This matches the Go pattern: Pack("", params...) and append(bytecode, input...)
Kind: inner method of quantum-coin-js-sdk
Returns: PackUnpackResult - - Returns a PackUnpackResult object containing the error (if any) and the packed contract creation data as a hex string.
| Param | Type | Description | | --- | --- | --- | | abiJSON | string | The Solidity ABI file content as a JSON string | | bytecode | string | The contract bytecode as a hex string (with or without 0x prefix) | | ...args | * | The constructor parameters (variable arguments, can be 0 or more) |
quantum-coin-js-sdk~encodeEventLog(abiJSON, eventName, ...args) ⇒ EventLogEncodeResult
The encodeEventLog function encodes event parameters into topics and data according to the ABI specification. It returns the topics array and data hex string that can be used to create event logs.
Kind: inner method of quantum-coin-js-sdk
Returns: EventLogEncodeResult - - Returns an EventLogEncodeResult object containing the error (if any) and the encoded event log with topics and data.
| Param | Type | Description | | --- | --- | --- | | abiJSON | string | The Solidity ABI file content as a JSON string | | eventName | string | The name of the event to encode | | ...args | * | The event parameter values (variable arguments) |
quantum-coin-js-sdk~decodeEventLog(abiJSON, eventName, topics, data) ⇒ PackUnpackResult
The decodeEventLog function decodes event log topics and data back into event parameters. It returns the decoded values as a JavaScript object.
Kind: inner method of quantum-coin-js-sdk
Returns:
