@hiero-ledger/sdk 2.81.0 → 2.82.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/umd.js +14018 -16573
- package/dist/umd.js.map +1 -1
- package/dist/umd.min.js +14 -21
- package/dist/umd.min.js.map +1 -1
- package/lib/EntityIdHelper.cjs +4 -4
- package/lib/EntityIdHelper.js +1 -1
- package/lib/EntityIdHelper.js.map +1 -1
- package/lib/EthereumFlow.d.ts +2 -2
- package/lib/EthereumTransaction.d.ts +2 -2
- package/lib/EthereumTransactionDataEip1559.cjs +3 -3
- package/lib/EthereumTransactionDataEip1559.js +1 -1
- package/lib/EthereumTransactionDataEip1559.js.map +1 -1
- package/lib/EthereumTransactionDataEip2930.cjs +3 -3
- package/lib/EthereumTransactionDataEip2930.js +1 -1
- package/lib/EthereumTransactionDataEip2930.js.map +1 -1
- package/lib/EthereumTransactionDataEip7702.cjs +3 -3
- package/lib/EthereumTransactionDataEip7702.js +1 -1
- package/lib/EthereumTransactionDataEip7702.js.map +1 -1
- package/lib/EthereumTransactionDataLegacy.cjs +3 -3
- package/lib/EthereumTransactionDataLegacy.js +1 -1
- package/lib/EthereumTransactionDataLegacy.js.map +1 -1
- package/lib/PrivateKey.cjs +2 -2
- package/lib/PrivateKey.js +1 -1
- package/lib/PrivateKey.js.map +1 -1
- package/lib/Transfer.d.ts +1 -1
- package/lib/account/AccountAllowanceAdjustTransaction.d.ts +1 -1
- package/lib/account/AccountAllowanceApproveTransaction.d.ts +1 -1
- package/lib/account/AccountAllowanceDeleteTransaction.d.ts +1 -1
- package/lib/account/AccountCreateTransaction.d.ts +2 -2
- package/lib/account/AccountInfoQuery.cjs +7 -8
- package/lib/account/AccountInfoQuery.d.ts +8 -0
- package/lib/account/AccountInfoQuery.js +1 -1
- package/lib/account/AccountInfoQuery.js.map +1 -1
- package/lib/account/HbarTransferMap.d.ts +1 -1
- package/lib/account/ProxyStaker.d.ts +1 -1
- package/lib/account/TokenAllowance.d.ts +1 -1
- package/lib/account/TokenTransferMap.d.ts +1 -1
- package/lib/account/TransferTransaction.d.ts +1 -1
- package/lib/client/addressbooks/mainnet.cjs +1 -1
- package/lib/client/addressbooks/mainnet.d.ts +1 -1
- package/lib/client/addressbooks/mainnet.js +1 -1
- package/lib/client/addressbooks/mainnet.js.map +1 -1
- package/lib/client/addressbooks/previewnet.cjs +1 -1
- package/lib/client/addressbooks/previewnet.d.ts +1 -1
- package/lib/client/addressbooks/previewnet.js +1 -1
- package/lib/client/addressbooks/previewnet.js.map +1 -1
- package/lib/contract/ContractByteCodeQuery.cjs +2 -1
- package/lib/contract/ContractByteCodeQuery.d.ts +8 -2
- package/lib/contract/ContractByteCodeQuery.js.map +1 -1
- package/lib/contract/ContractCallQuery.cjs +2 -1
- package/lib/contract/ContractCallQuery.d.ts +8 -2
- package/lib/contract/ContractCallQuery.js.map +1 -1
- package/lib/contract/ContractCreateFlow.d.ts +1 -1
- package/lib/contract/ContractCreateTransaction.d.ts +2 -2
- package/lib/contract/ContractExecuteTransaction.cjs +2 -1
- package/lib/contract/ContractExecuteTransaction.d.ts +6 -8
- package/lib/contract/ContractExecuteTransaction.js.map +1 -1
- package/lib/contract/ContractFunctionParameters.cjs +5 -4
- package/lib/contract/ContractFunctionParameters.js +1 -1
- package/lib/contract/ContractFunctionParameters.js.map +1 -1
- package/lib/contract/ContractFunctionResult.cjs +70 -31
- package/lib/contract/ContractFunctionResult.d.ts +13 -3
- package/lib/contract/ContractFunctionResult.js +1 -1
- package/lib/contract/ContractFunctionResult.js.map +1 -1
- package/lib/contract/ContractId.cjs +3 -1
- package/lib/contract/ContractId.d.ts +6 -2
- package/lib/contract/ContractId.js.map +1 -1
- package/lib/contract/ContractInfoQuery.cjs +2 -1
- package/lib/contract/ContractInfoQuery.d.ts +8 -2
- package/lib/contract/ContractInfoQuery.js.map +1 -1
- package/lib/contract/DelegateContractId.cjs +3 -1
- package/lib/contract/DelegateContractId.d.ts +6 -2
- package/lib/contract/DelegateContractId.js.map +1 -1
- package/lib/cryptography/sha384.browser.cjs +3 -2
- package/lib/cryptography/sha384.browser.d.ts +2 -2
- package/lib/cryptography/sha384.browser.js +1 -1
- package/lib/cryptography/sha384.browser.js.map +1 -1
- package/lib/exports.js +1 -1
- package/lib/exports.js.map +1 -1
- package/lib/node/NodeUpdateTransaction.cjs +3 -3
- package/lib/node/NodeUpdateTransaction.js +1 -1
- package/lib/node/NodeUpdateTransaction.js.map +1 -1
- package/lib/schedule/ScheduleCreateTransaction.d.ts +1 -1
- package/lib/schedule/ScheduleDeleteTransaction.d.ts +1 -1
- package/lib/schedule/ScheduleId.cjs +3 -1
- package/lib/schedule/ScheduleId.d.ts +5 -1
- package/lib/schedule/ScheduleId.js.map +1 -1
- package/lib/schedule/ScheduleSignTransaction.d.ts +1 -1
- package/lib/token/AbstractTokenTransferTransaction.d.ts +1 -1
- package/lib/token/AssessedCustomFee.d.ts +2 -2
- package/lib/token/CustomFixedFee.d.ts +2 -2
- package/lib/token/PendingAirdropId.cjs +22 -21
- package/lib/token/PendingAirdropId.d.ts +16 -16
- package/lib/token/PendingAirdropId.js +1 -1
- package/lib/token/PendingAirdropId.js.map +1 -1
- package/lib/token/PendingAirdropRecord.d.ts +1 -1
- package/lib/token/TokenAirdropTransaction.d.ts +1 -1
- package/lib/token/TokenBurnTransaction.d.ts +2 -2
- package/lib/token/TokenCreateTransaction.d.ts +3 -3
- package/lib/token/TokenFeeScheduleUpdateTransaction.d.ts +1 -1
- package/lib/token/TokenMintTransaction.d.ts +2 -2
- package/lib/token/TokenNftTransfer.d.ts +1 -1
- package/lib/token/TokenTransfer.d.ts +1 -1
- package/lib/token/TokenUpdateTransaction.d.ts +1 -1
- package/lib/token/TokenWipeTransaction.d.ts +2 -2
- package/lib/transaction/Transaction.cjs +45 -1
- package/lib/transaction/Transaction.d.ts +19 -1
- package/lib/transaction/Transaction.js +1 -1
- package/lib/transaction/Transaction.js.map +1 -1
- package/lib/util.cjs +5 -1
- package/lib/util.js +1 -1
- package/lib/util.js.map +1 -1
- package/lib/version.js +1 -1
- package/package.json +8 -11
- package/src/EntityIdHelper.js +4 -4
- package/src/EthereumTransactionDataEip1559.js +3 -3
- package/src/EthereumTransactionDataEip2930.js +3 -3
- package/src/EthereumTransactionDataEip7702.js +3 -3
- package/src/EthereumTransactionDataLegacy.js +3 -3
- package/src/PrivateKey.js +1 -1
- package/src/account/AccountInfoQuery.js +8 -7
- package/src/client/addressbooks/mainnet.js +1 -1
- package/src/client/addressbooks/previewnet.js +1 -1
- package/src/contract/ContractByteCodeQuery.js +2 -1
- package/src/contract/ContractCallQuery.js +2 -1
- package/src/contract/ContractExecuteTransaction.js +2 -1
- package/src/contract/ContractFunctionParameters.js +4 -3
- package/src/contract/ContractFunctionResult.js +48 -3
- package/src/contract/ContractId.js +3 -1
- package/src/contract/ContractInfoQuery.js +2 -1
- package/src/contract/DelegateContractId.js +3 -1
- package/src/cryptography/sha384.browser.js +4 -2
- package/src/node/NodeUpdateTransaction.js +6 -3
- package/src/schedule/ScheduleId.js +3 -1
- package/src/token/PendingAirdropId.js +31 -21
- package/src/transaction/Transaction.js +66 -1
- package/src/util.js +5 -6
package/lib/PrivateKey.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{hexlify as t}from"
|
|
1
|
+
import{hexlify as t}from"ethers";import{PrivateKey as e}from"@hiero-ledger/cryptography";import{proto as r}from"@hiero-ledger/proto";import n from"./Mnemonic.js";import i from"./PublicKey.js";import o from"./Key.js";import s from"./Cache.js";import a from"./transaction/SignatureMap.js";import c from"./account/AccountId.js";import y from"./transaction/TransactionId.js";import{decode as u}from"./encoding/hex.js";import{ASN1Decoder as m}from"./util/ASN1-Decoder.js";class g extends o{constructor(t){super(),this._key=t}static generateED25519(){return new g(e.generateED25519())}static generateECDSA(){return new g(e.generateECDSA())}static generate(){return g.generateED25519()}static async generateAsync(){return new g(await e.generateAsync())}static async generateED25519Async(){return new g(await e.generateED25519Async())}static async generateECDSAAsync(){return new g(await e.generateECDSAAsync())}static fromBytes(r){const n=t(r);return g.isDerKey(n)?"ecdsa"===g.getAlgorithm(n)?new g(e.fromBytesECDSA(r)):new g(e.fromBytesED25519(r)):new g(e.fromBytes(r))}static fromBytesECDSA(t){return new g(e.fromBytesECDSA(t))}static fromBytesED25519(t){return new g(e.fromBytesED25519(t))}static fromString(t){return g.isDerKey(t)?this.fromStringDer(t):new g(e.fromString(t))}static fromStringDer(t){return g.isDerKey(t)?"ecdsa"===g.getAlgorithm(t)?this.fromStringECDSA(t):this.fromStringED25519(t):g.fromString(t)}static fromStringECDSA(t){return new g(e.fromStringECDSA(t))}static fromStringED25519(t){return new g(e.fromStringED25519(t))}static async fromSeedED25519(t){return new g(await e.fromSeedED25519(t))}static async fromSeedECDSAsecp256k1(t){return new g(await e.fromSeedECDSAsecp256k1(t))}static async fromMnemonic(t,r=""){return new g(t instanceof n?await e.fromMnemonic(t._mnemonic,r):await e.fromMnemonic(t,r))}static async fromKeystore(t,r=""){return new g(await e.fromKeystore(t,r))}static async fromPem(t,r=""){return new g(await e.fromPem(t,r))}async derive(t){return new g(await this._key.derive(t))}async legacyDerive(t){return new g(await this._key.legacyDerive(t))}get publicKey(){return new i(this._key.publicKey)}get chainCode(){return this._key._chainCode}sign(t){return this._key.sign(t)}signTransaction(t,e=!1){if(e)return this._signTransactionLegacy(t);const n=new a;for(const e of t._signedTransactions.list){const t=e.bodyBytes;if(!t)throw new Error("Body bytes are missing");const i=r.TransactionBody.decode(t);if(!i.transactionID||!i.nodeAccountID)throw new Error("Transaction ID or Node Account ID not found in the signed transaction");const o=c._fromProtobuf(i.nodeAccountID),s=y._fromProtobuf(i.transactionID),a=this._key.sign(t);n.addSignature(o,s,this.publicKey,a)}return t.addSignature(this.publicKey,n),n}_signTransactionLegacy(t){const e=t._signedTransactions.list.map(t=>{const e=t.bodyBytes;return e?this._key.sign(e):new Uint8Array});return t.addSignature(this.publicKey,e),1===e.length?e[0]:e}isDerivable(){return this._key.isDerivable()}toBytes(){return this._key.toBytes()}toBytesDer(){return this._key.toBytesDer()}toBytesRaw(){return this._key.toBytesRaw()}toString(){return this._key.toStringDer()}toStringDer(){return this._key.toStringDer()}toStringRaw(){return this._key.toStringRaw()}toKeystore(t=""){return this._key.toKeystore(t)}_toProtobufKey(){return this.publicKey._toProtobufKey()}toAccountId(t,e){return this.publicKey.toAccountId(t,e)}get type(){return this._key._type}getRecoveryId(t,e,r){return this._key.getRecoveryId(t,e,r)}static getAlgorithm(t){if(!g.isDerKey(t))throw new Error("Only der keys are supported");const e=new m(Uint8Array.from(u(t)));e.read();return e.getOidKeyTypes()[0]}static isDerKey(t){try{const e=Uint8Array.from(u(t));return new m(e).read(),!0}catch(t){return!1}}}s.setPrivateKeyConstructor(t=>new g(t));export{g as default};
|
|
2
2
|
//# sourceMappingURL=PrivateKey.js.map
|
package/lib/PrivateKey.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrivateKey.js","sources":["../src/PrivateKey.js"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { hexlify } from \"@ethersproject/bytes\";\nimport { PrivateKey as PrivateKeyCrypto } from \"@hiero-ledger/cryptography\";\nimport { proto } from \"@hiero-ledger/proto\";\nimport Mnemonic from \"./Mnemonic.js\";\nimport PublicKey from \"./PublicKey.js\";\nimport Key from \"./Key.js\";\nimport CACHE from \"./Cache.js\";\nimport SignatureMap from \"./transaction/SignatureMap.js\";\nimport AccountId from \"./account/AccountId.js\";\nimport TransactionId from \"./transaction/TransactionId.js\";\nimport { decode } from \"./encoding/hex.js\";\nimport { ASN1Decoder } from \"./util/ASN1-Decoder.js\";\n\n/**\n * @typedef {import(\"./transaction/Transaction.js\").default} Transaction\n */\n\n/**\n * @namespace proto\n * @typedef {import(\"@hiero-ledger/proto\").proto.IKey} HieroProto.proto.IKey\n * @typedef {import(\"@hiero-ledger/proto\").proto.ITransaction} HieroProto.proto.ITransaction\n * @typedef {import(\"@hiero-ledger/proto\").proto.ISignaturePair} HieroProto.proto.ISignaturePair\n * @typedef {import(\"@hiero-ledger/proto\").proto.ISignedTransaction} HieroProto.proto.ISignedTransaction\n * @typedef {import(\"@hiero-ledger/proto\").proto.TransactionBody} HieroProto.proto.TransactionBody\n */\n\nexport default class PrivateKey extends Key {\n /**\n * @internal\n * @hideconstructor\n * @param {PrivateKeyCrypto} key\n */\n constructor(key) {\n super();\n\n this._key = key;\n }\n\n /**\n * Generate a random Ed25519 private key.\n *\n * @returns {PrivateKey}\n */\n static generateED25519() {\n return new PrivateKey(PrivateKeyCrypto.generateED25519());\n }\n\n /**\n * Generate a random EDSA private key.\n *\n * @returns {PrivateKey}\n */\n static generateECDSA() {\n return new PrivateKey(PrivateKeyCrypto.generateECDSA());\n }\n\n /**\n * Depredated - Use `generateED25519()` instead\n * Generate a random Ed25519 private key.\n *\n * @returns {PrivateKey}\n */\n static generate() {\n return PrivateKey.generateED25519();\n }\n\n /**\n * Depredated - Use `generateED25519Async()` instead\n * Generate a random Ed25519 private key.\n *\n * @returns {Promise<PrivateKey>}\n */\n static async generateAsync() {\n return new PrivateKey(await PrivateKeyCrypto.generateAsync());\n }\n\n /**\n * Generate a random Ed25519 private key.\n *\n * @returns {Promise<PrivateKey>}\n */\n static async generateED25519Async() {\n return new PrivateKey(await PrivateKeyCrypto.generateED25519Async());\n }\n\n /**\n * Generate a random ECDSA private key.\n *\n * @returns {Promise<PrivateKey>}\n */\n static async generateECDSAAsync() {\n return new PrivateKey(await PrivateKeyCrypto.generateECDSAAsync());\n }\n\n /**\n * Construct a private key from bytes. Requires DER header.\n *\n * @param {Uint8Array} data\n * @returns {PrivateKey}\n */\n static fromBytes(data) {\n const keyString = hexlify(data);\n if (PrivateKey.isDerKey(keyString)) {\n if (PrivateKey.getAlgorithm(keyString) === \"ecdsa\") {\n return new PrivateKey(PrivateKeyCrypto.fromBytesECDSA(data));\n } else {\n return new PrivateKey(PrivateKeyCrypto.fromBytesED25519(data));\n }\n }\n\n // If the key is not DER, we assume it's a raw private key\n // this will default to ED25519 as we dont have a way\n // to determine the type of the key based on the raw bytes\n return new PrivateKey(PrivateKeyCrypto.fromBytes(data));\n }\n\n /**\n * Construct a ECDSA private key from bytes.\n *\n * @param {Uint8Array} data\n * @returns {PrivateKey}\n */\n static fromBytesECDSA(data) {\n return new PrivateKey(PrivateKeyCrypto.fromBytesECDSA(data));\n }\n\n /**\n * Construct a ED25519 private key from bytes.\n *\n * @param {Uint8Array} data\n * @returns {PrivateKey}\n */\n static fromBytesED25519(data) {\n return new PrivateKey(PrivateKeyCrypto.fromBytesED25519(data));\n }\n\n /**\n * @deprecated - Use fromStringECDSA() or fromStringED2551() on a HEX-encoded string\n * and fromStringDer() on a HEX-encoded string with DER prefix instead.\n * Construct a private key from a hex-encoded string. Requires DER header.\n * @param {string} text\n * @returns {PrivateKey}\n */\n static fromString(text) {\n if (PrivateKey.isDerKey(text)) {\n return this.fromStringDer(text);\n }\n // If the key is not DER, we assume it's a raw private key\n // this will default to ED25519 as we dont have a way\n // to determine the type of the key based on the raw bytes\n return new PrivateKey(PrivateKeyCrypto.fromString(text));\n }\n\n /**\n * Construct a private key from a HEX-encoded string with a der prefix\n *\n * @param {string} text\n * @returns {PrivateKey}\n */\n static fromStringDer(text) {\n // previous versions of the library used to accept non-der encoded private keys here\n // and it fallbacked to PrivateKey.fromString() so we need to keep this behavior\n if (!PrivateKey.isDerKey(text)) {\n // eslint-disable-next-line deprecation/deprecation\n return PrivateKey.fromString(text);\n }\n\n if (PrivateKey.getAlgorithm(text) === \"ecdsa\") {\n return this.fromStringECDSA(text);\n } else {\n return this.fromStringED25519(text);\n }\n }\n\n /**\n * Construct a ECDSA private key from a hex-encoded string.\n *\n * @param {string} text\n * @returns {PrivateKey}\n */\n static fromStringECDSA(text) {\n return new PrivateKey(PrivateKeyCrypto.fromStringECDSA(text));\n }\n\n /**\n * Construct a Ed25519 private key from a hex-encoded string.\n *\n * @param {string} text\n * @returns {PrivateKey}\n */\n static fromStringED25519(text) {\n return new PrivateKey(PrivateKeyCrypto.fromStringED25519(text));\n }\n\n /**\n * Construct a Ed25519 private key from a Uint8Array seed.\n *\n * @param {Uint8Array} seed\n * @returns {Promise<PrivateKey>}\n */\n static async fromSeedED25519(seed) {\n return new PrivateKey(await PrivateKeyCrypto.fromSeedED25519(seed));\n }\n\n /**\n * Construct a Ed25519 private key from a Uint8Array seed.\n *\n * @param {Uint8Array} seed\n * @returns {Promise<PrivateKey>}\n */\n static async fromSeedECDSAsecp256k1(seed) {\n return new PrivateKey(\n await PrivateKeyCrypto.fromSeedECDSAsecp256k1(seed),\n );\n }\n\n /**\n * @deprecated - Use `Mnemonic.from[Words|String]().to[Ed25519|Ecdsa]PrivateKey()` instead\n *\n * Recover a private key from a mnemonic phrase (and optionally a password).\n * @param {Mnemonic | string} mnemonic\n * @param {string} [passphrase]\n * @returns {Promise<PrivateKey>}\n */\n static async fromMnemonic(mnemonic, passphrase = \"\") {\n if (mnemonic instanceof Mnemonic) {\n return new PrivateKey(\n // eslint-disable-next-line deprecation/deprecation\n await PrivateKeyCrypto.fromMnemonic(\n mnemonic._mnemonic,\n passphrase,\n ),\n );\n }\n\n return new PrivateKey(\n // eslint-disable-next-line deprecation/deprecation\n await PrivateKeyCrypto.fromMnemonic(mnemonic, passphrase),\n );\n }\n\n /**\n * Recover a private key from a keystore, previously created by `.toKeystore()`.\n *\n * This key will _not_ support child key derivation.\n *\n * @param {Uint8Array} data\n * @param {string} [passphrase]\n * @returns {Promise<PrivateKey>}\n * @throws {cryptography.BadKeyError} If the passphrase is incorrect or the hash fails to validate.\n */\n static async fromKeystore(data, passphrase = \"\") {\n return new PrivateKey(\n await PrivateKeyCrypto.fromKeystore(data, passphrase),\n );\n }\n\n /**\n * Recover a private key from a pem string; the private key may be encrypted.\n *\n * This method assumes the .pem file has been converted to a string already.\n *\n * If `passphrase` is not null or empty, this looks for the first `ENCRYPTED PRIVATE KEY`\n * section and uses `passphrase` to decrypt it; otherwise, it looks for the first `PRIVATE KEY`\n * section and decodes that as a DER-encoded private key.\n *\n * @param {string} data\n * @param {string} [passphrase]\n * @returns {Promise<PrivateKey>}\n */\n static async fromPem(data, passphrase = \"\") {\n return new PrivateKey(await PrivateKeyCrypto.fromPem(data, passphrase));\n }\n\n /**\n * Derive a new private key at the given wallet index.\n *\n * Only currently supported for keys created with `fromMnemonic()`; other keys will throw\n * an error.\n *\n * You can check if a key supports derivation with `.supportsDerivation()`\n *\n * @param {number} index\n * @returns {Promise<PrivateKey>}\n * @throws If this key does not support derivation.\n */\n async derive(index) {\n return new PrivateKey(await this._key.derive(index));\n }\n\n /**\n * @param {number} index\n * @returns {Promise<PrivateKey>}\n * @throws If this key does not support derivation.\n */\n async legacyDerive(index) {\n return new PrivateKey(await this._key.legacyDerive(index));\n }\n\n /**\n * Get the public key associated with this private key.\n *\n * The public key can be freely given and used by other parties to verify\n * the signatures generated by this private key.\n *\n * @returns {PublicKey}\n */\n get publicKey() {\n return new PublicKey(this._key.publicKey);\n }\n\n /**\n * Get the public key associated with this private key.\n *\n * The public key can be freely given and used by other parties to verify\n * the signatures generated by this private key.\n *\n * @returns {?Uint8Array}\n */\n get chainCode() {\n return this._key._chainCode;\n }\n\n /**\n * Sign a message with this private key.\n *\n * @param {Uint8Array} bytes\n * @returns {Uint8Array} - The signature bytes without the message\n */\n sign(bytes) {\n return this._key.sign(bytes);\n }\n\n /**\n * @deprecated - Use legacy=false flag to use the modern approach\n * or don't pass it at all.\n * @overload\n * @param {Transaction} transaction\n * @param {true} legacy\n * @returns {Uint8Array | Uint8Array[] }\n */\n\n /**\n * @overload\n * @param {Transaction} transaction\n * @param {false} [legacy]\n * @returns {SignatureMap}\n */\n\n /**\n * @param {Transaction} transaction\n * @param {boolean} [legacy]\n * @returns {Uint8Array | Uint8Array[] | SignatureMap}\n */\n signTransaction(transaction, legacy = false) {\n if (legacy) {\n return this._signTransactionLegacy(transaction);\n }\n\n const sigMap = new SignatureMap();\n\n for (const signedTx of transaction._signedTransactions.list) {\n const bodyBytes = signedTx.bodyBytes;\n if (!bodyBytes) throw new Error(\"Body bytes are missing\");\n\n const body = proto.TransactionBody.decode(bodyBytes);\n if (!body.transactionID || !body.nodeAccountID) {\n throw new Error(\n \"Transaction ID or Node Account ID not found in the signed transaction\",\n );\n }\n\n const nodeId = AccountId._fromProtobuf(body.nodeAccountID);\n const transactionId = TransactionId._fromProtobuf(\n body.transactionID,\n );\n const sig = this._key.sign(bodyBytes);\n sigMap.addSignature(nodeId, transactionId, this.publicKey, sig);\n }\n\n transaction.addSignature(this.publicKey, sigMap);\n return sigMap;\n }\n\n /**\n * deprecated - This method is deprecated and will be removed in future versions.\n * Use the `signTransaction` method with the `legacy=false` flag or don't\n * pass it all for the modern approach.\n * @param {Transaction} transaction\n * @returns {Uint8Array | Uint8Array[]}\n */\n _signTransactionLegacy(transaction) {\n const signatures = transaction._signedTransactions.list.map(\n (signedTransaction) => {\n const bodyBytes = signedTransaction.bodyBytes;\n if (!bodyBytes) {\n return new Uint8Array();\n }\n\n return this._key.sign(bodyBytes);\n },\n );\n transaction.addSignature(this.publicKey, signatures);\n // Return directly Uint8Array if there is only one signature\n return signatures.length === 1 ? signatures[0] : signatures;\n }\n\n /**\n * Check if `derive` can be called on this private key.\n *\n * This is only the case if the key was created from a mnemonic.\n *\n * @returns {boolean}\n */\n isDerivable() {\n return this._key.isDerivable();\n }\n\n /**\n * @returns {Uint8Array}\n */\n toBytes() {\n return this._key.toBytes();\n }\n\n /**\n * @returns {Uint8Array}\n */\n toBytesDer() {\n return this._key.toBytesDer();\n }\n\n /**\n * @returns {Uint8Array}\n */\n toBytesRaw() {\n return this._key.toBytesRaw();\n }\n\n /**\n * @returns {string}\n */\n toString() {\n return this._key.toStringDer();\n }\n\n /**\n * @returns {string}\n */\n toStringDer() {\n return this._key.toStringDer();\n }\n\n /**\n * @returns {string}\n */\n toStringRaw() {\n return this._key.toStringRaw();\n }\n\n /**\n * Create a keystore with a given passphrase.\n *\n * The key can be recovered later with `fromKeystore()`.\n *\n * Note that this will not retain the ancillary data used for\n * deriving child keys, thus `.derive()` on the restored key will\n * throw even if this instance supports derivation.\n *\n * @param {string} [passphrase]\n * @returns {Promise<Uint8Array>}\n */\n toKeystore(passphrase = \"\") {\n return this._key.toKeystore(passphrase);\n }\n\n /**\n * @returns {HieroProto.proto.IKey}\n */\n _toProtobufKey() {\n return this.publicKey._toProtobufKey();\n }\n\n /**\n * @param {Long | number} shard\n * @param {Long | number} realm\n * @returns {AccountId}\n */\n toAccountId(shard, realm) {\n return this.publicKey.toAccountId(shard, realm);\n }\n\n /**\n * @returns {string}\n */\n get type() {\n return this._key._type;\n }\n\n /**\n * Recover the recovery ID used in the signature for the given message.\n *\n * **Note:** This method only works for ECDSA secp256k1 keys.\n * @param {Uint8Array} r - 32-byte `r` component of the signature\n * @param {Uint8Array} s - 32-byte `s` component of the signature\n * @param {Uint8Array} message - The original (unhashed) message\n * @returns {number} Recovery ID (0–3), or -1 if not found or not applicable\n */\n getRecoveryId(r, s, message) {\n return this._key.getRecoveryId(r, s, message);\n }\n\n /**\n * @param {string} privateKey\n * @returns { \"ecdsa\" | \"ed25519\"}\n */\n static getAlgorithm(privateKey) {\n if (!PrivateKey.isDerKey(privateKey)) {\n throw new Error(\"Only der keys are supported\");\n }\n\n const decoder = new ASN1Decoder(Uint8Array.from(decode(privateKey)));\n decoder.read();\n const decodedKeyType = decoder.getOidKeyTypes()[0];\n // @ts-ignored\n return decodedKeyType;\n }\n\n /**\n * @internal\n * @param {string} key\n * @returns {boolean}\n */\n static isDerKey(key) {\n try {\n const data = Uint8Array.from(decode(key));\n const decoder = new ASN1Decoder(data);\n decoder.read(); // Attempt to read the ASN.1 structure\n return true;\n } catch (error) {\n return false;\n }\n }\n}\n\nCACHE.setPrivateKeyConstructor((key) => new PrivateKey(key));\n"],"names":["PrivateKey","Key","constructor","key","super","this","_key","generateED25519","PrivateKeyCrypto","generateECDSA","generate","generateAsync","generateED25519Async","generateECDSAAsync","fromBytes","data","keyString","hexlify","isDerKey","getAlgorithm","fromBytesECDSA","fromBytesED25519","fromString","text","fromStringDer","fromStringECDSA","fromStringED25519","fromSeedED25519","seed","fromSeedECDSAsecp256k1","fromMnemonic","mnemonic","passphrase","Mnemonic","_mnemonic","fromKeystore","fromPem","derive","index","legacyDerive","publicKey","PublicKey","chainCode","_chainCode","sign","bytes","signTransaction","transaction","legacy","_signTransactionLegacy","sigMap","SignatureMap","signedTx","_signedTransactions","list","bodyBytes","Error","body","proto","TransactionBody","decode","transactionID","nodeAccountID","nodeId","AccountId","_fromProtobuf","transactionId","TransactionId","sig","addSignature","signatures","map","signedTransaction","Uint8Array","length","isDerivable","toBytes","toBytesDer","toBytesRaw","toString","toStringDer","toStringRaw","toKeystore","_toProtobufKey","toAccountId","shard","realm","type","_type","getRecoveryId","r","s","message","privateKey","decoder","ASN1Decoder","from","read","getOidKeyTypes","error","CACHE","setPrivateKeyConstructor"],"mappings":"ieA2Be,MAAMA,UAAmBC,EAMpC,WAAAC,CAAYC,GACRC,QAEAC,KAAKC,KAAOH,CAChB,CAOA,sBAAOI,GACH,OAAO,IAAIP,EAAWQ,EAAiBD,kBAC3C,CAOA,oBAAOE,GACH,OAAO,IAAIT,EAAWQ,EAAiBC,gBAC3C,CAQA,eAAOC,GACH,OAAOV,EAAWO,iBACtB,CAQA,0BAAaI,GACT,OAAO,IAAIX,QAAiBQ,EAAiBG,gBACjD,CAOA,iCAAaC,GACT,OAAO,IAAIZ,QAAiBQ,EAAiBI,uBACjD,CAOA,+BAAaC,GACT,OAAO,IAAIb,QAAiBQ,EAAiBK,qBACjD,CAQA,gBAAOC,CAAUC,GACb,MAAMC,EAAYC,EAAQF,GAC1B,OAAIf,EAAWkB,SAASF,GACuB,UAAvChB,EAAWmB,aAAaH,GACjB,IAAIhB,EAAWQ,EAAiBY,eAAeL,IAE/C,IAAIf,EAAWQ,EAAiBa,iBAAiBN,IAOzD,IAAIf,EAAWQ,EAAiBM,UAAUC,GACrD,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1E,KAAKC,KAAK0E,aACrB,CAKA,WAAAA,GACI,OAAO3E,KAAKC,KAAK0E,aACrB,CAKA,WAAAC,GACI,OAAO5E,KAAKC,KAAK2E,aACrB,CAcA,UAAAC,CAAWlD,EAAa,IACpB,OAAO3B,KAAKC,KAAK4E,WAAWlD,EAChC,CAKA,cAAAmD,GACI,OAAO9E,KAAKmC,UAAU2C,gBAC1B,CAOA,WAAAC,CAAYC,EAAOC,GACf,OAAOjF,KAAKmC,UAAU4C,YAAYC,EAAOC,EAC7C,CAKA,QAAIC,GACA,OAAOlF,KAAKC,KAAKkF,KACrB,CAWA,aAAAC,CAAcC,EAAGC,EAAGC,GAChB,OAAOvF,KAAKC,KAAKmF,cAAcC,EAAGC,EAAGC,EACzC,CAMA,mBAAOzE,CAAa0E,GAChB,IAAK7F,EAAWkB,SAAS2E,GACrB,MAAM,IAAIrC,MAAM,+BAGpB,MAAMsC,EAAU,IAAIC,EAAYtB,WAAWuB,KAAKpC,EAAOiC,KACvDC,EAAQG,OAGR,OAFuBH,EAAQI,iBAAiB,EAGpD,CAOA,eAAOhF,CAASf,GACZ,IACI,MAAMY,EAAO0D,WAAWuB,KAAKpC,EAAOzD,IAGpC,OAFgB,IAAI4F,EAAYhF,GACxBkF,QACD,CACX,CAAE,MAAOE,GACL,OAAO,CACX,CACJ,EAGJC,EAAMC,yBAA0BlG,GAAQ,IAAIH,EAAWG"}
|
|
1
|
+
{"version":3,"file":"PrivateKey.js","sources":["../src/PrivateKey.js"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { hexlify } from \"ethers\";\nimport { PrivateKey as PrivateKeyCrypto } from \"@hiero-ledger/cryptography\";\nimport { proto } from \"@hiero-ledger/proto\";\nimport Mnemonic from \"./Mnemonic.js\";\nimport PublicKey from \"./PublicKey.js\";\nimport Key from \"./Key.js\";\nimport CACHE from \"./Cache.js\";\nimport SignatureMap from \"./transaction/SignatureMap.js\";\nimport AccountId from \"./account/AccountId.js\";\nimport TransactionId from \"./transaction/TransactionId.js\";\nimport { decode } from \"./encoding/hex.js\";\nimport { ASN1Decoder } from \"./util/ASN1-Decoder.js\";\n\n/**\n * @typedef {import(\"./transaction/Transaction.js\").default} Transaction\n */\n\n/**\n * @namespace proto\n * @typedef {import(\"@hiero-ledger/proto\").proto.IKey} HieroProto.proto.IKey\n * @typedef {import(\"@hiero-ledger/proto\").proto.ITransaction} HieroProto.proto.ITransaction\n * @typedef {import(\"@hiero-ledger/proto\").proto.ISignaturePair} HieroProto.proto.ISignaturePair\n * @typedef {import(\"@hiero-ledger/proto\").proto.ISignedTransaction} HieroProto.proto.ISignedTransaction\n * @typedef {import(\"@hiero-ledger/proto\").proto.TransactionBody} HieroProto.proto.TransactionBody\n */\n\nexport default class PrivateKey extends Key {\n /**\n * @internal\n * @hideconstructor\n * @param {PrivateKeyCrypto} key\n */\n constructor(key) {\n super();\n\n this._key = key;\n }\n\n /**\n * Generate a random Ed25519 private key.\n *\n * @returns {PrivateKey}\n */\n static generateED25519() {\n return new PrivateKey(PrivateKeyCrypto.generateED25519());\n }\n\n /**\n * Generate a random EDSA private key.\n *\n * @returns {PrivateKey}\n */\n static generateECDSA() {\n return new PrivateKey(PrivateKeyCrypto.generateECDSA());\n }\n\n /**\n * Depredated - Use `generateED25519()` instead\n * Generate a random Ed25519 private key.\n *\n * @returns {PrivateKey}\n */\n static generate() {\n return PrivateKey.generateED25519();\n }\n\n /**\n * Depredated - Use `generateED25519Async()` instead\n * Generate a random Ed25519 private key.\n *\n * @returns {Promise<PrivateKey>}\n */\n static async generateAsync() {\n return new PrivateKey(await PrivateKeyCrypto.generateAsync());\n }\n\n /**\n * Generate a random Ed25519 private key.\n *\n * @returns {Promise<PrivateKey>}\n */\n static async generateED25519Async() {\n return new PrivateKey(await PrivateKeyCrypto.generateED25519Async());\n }\n\n /**\n * Generate a random ECDSA private key.\n *\n * @returns {Promise<PrivateKey>}\n */\n static async generateECDSAAsync() {\n return new PrivateKey(await PrivateKeyCrypto.generateECDSAAsync());\n }\n\n /**\n * Construct a private key from bytes. Requires DER header.\n *\n * @param {Uint8Array} data\n * @returns {PrivateKey}\n */\n static fromBytes(data) {\n const keyString = hexlify(data);\n if (PrivateKey.isDerKey(keyString)) {\n if (PrivateKey.getAlgorithm(keyString) === \"ecdsa\") {\n return new PrivateKey(PrivateKeyCrypto.fromBytesECDSA(data));\n } else {\n return new PrivateKey(PrivateKeyCrypto.fromBytesED25519(data));\n }\n }\n\n // If the key is not DER, we assume it's a raw private key\n // this will default to ED25519 as we dont have a way\n // to determine the type of the key based on the raw bytes\n return new PrivateKey(PrivateKeyCrypto.fromBytes(data));\n }\n\n /**\n * Construct a ECDSA private key from bytes.\n *\n * @param {Uint8Array} data\n * @returns {PrivateKey}\n */\n static fromBytesECDSA(data) {\n return new PrivateKey(PrivateKeyCrypto.fromBytesECDSA(data));\n }\n\n /**\n * Construct a ED25519 private key from bytes.\n *\n * @param {Uint8Array} data\n * @returns {PrivateKey}\n */\n static fromBytesED25519(data) {\n return new PrivateKey(PrivateKeyCrypto.fromBytesED25519(data));\n }\n\n /**\n * @deprecated - Use fromStringECDSA() or fromStringED2551() on a HEX-encoded string\n * and fromStringDer() on a HEX-encoded string with DER prefix instead.\n * Construct a private key from a hex-encoded string. Requires DER header.\n * @param {string} text\n * @returns {PrivateKey}\n */\n static fromString(text) {\n if (PrivateKey.isDerKey(text)) {\n return this.fromStringDer(text);\n }\n // If the key is not DER, we assume it's a raw private key\n // this will default to ED25519 as we dont have a way\n // to determine the type of the key based on the raw bytes\n return new PrivateKey(PrivateKeyCrypto.fromString(text));\n }\n\n /**\n * Construct a private key from a HEX-encoded string with a der prefix\n *\n * @param {string} text\n * @returns {PrivateKey}\n */\n static fromStringDer(text) {\n // previous versions of the library used to accept non-der encoded private keys here\n // and it fallbacked to PrivateKey.fromString() so we need to keep this behavior\n if (!PrivateKey.isDerKey(text)) {\n // eslint-disable-next-line deprecation/deprecation\n return PrivateKey.fromString(text);\n }\n\n if (PrivateKey.getAlgorithm(text) === \"ecdsa\") {\n return this.fromStringECDSA(text);\n } else {\n return this.fromStringED25519(text);\n }\n }\n\n /**\n * Construct a ECDSA private key from a hex-encoded string.\n *\n * @param {string} text\n * @returns {PrivateKey}\n */\n static fromStringECDSA(text) {\n return new PrivateKey(PrivateKeyCrypto.fromStringECDSA(text));\n }\n\n /**\n * Construct a Ed25519 private key from a hex-encoded string.\n *\n * @param {string} text\n * @returns {PrivateKey}\n */\n static fromStringED25519(text) {\n return new PrivateKey(PrivateKeyCrypto.fromStringED25519(text));\n }\n\n /**\n * Construct a Ed25519 private key from a Uint8Array seed.\n *\n * @param {Uint8Array} seed\n * @returns {Promise<PrivateKey>}\n */\n static async fromSeedED25519(seed) {\n return new PrivateKey(await PrivateKeyCrypto.fromSeedED25519(seed));\n }\n\n /**\n * Construct a Ed25519 private key from a Uint8Array seed.\n *\n * @param {Uint8Array} seed\n * @returns {Promise<PrivateKey>}\n */\n static async fromSeedECDSAsecp256k1(seed) {\n return new PrivateKey(\n await PrivateKeyCrypto.fromSeedECDSAsecp256k1(seed),\n );\n }\n\n /**\n * @deprecated - Use `Mnemonic.from[Words|String]().to[Ed25519|Ecdsa]PrivateKey()` instead\n *\n * Recover a private key from a mnemonic phrase (and optionally a password).\n * @param {Mnemonic | string} mnemonic\n * @param {string} [passphrase]\n * @returns {Promise<PrivateKey>}\n */\n static async fromMnemonic(mnemonic, passphrase = \"\") {\n if (mnemonic instanceof Mnemonic) {\n return new PrivateKey(\n // eslint-disable-next-line deprecation/deprecation\n await PrivateKeyCrypto.fromMnemonic(\n mnemonic._mnemonic,\n passphrase,\n ),\n );\n }\n\n return new PrivateKey(\n // eslint-disable-next-line deprecation/deprecation\n await PrivateKeyCrypto.fromMnemonic(mnemonic, passphrase),\n );\n }\n\n /**\n * Recover a private key from a keystore, previously created by `.toKeystore()`.\n *\n * This key will _not_ support child key derivation.\n *\n * @param {Uint8Array} data\n * @param {string} [passphrase]\n * @returns {Promise<PrivateKey>}\n * @throws {cryptography.BadKeyError} If the passphrase is incorrect or the hash fails to validate.\n */\n static async fromKeystore(data, passphrase = \"\") {\n return new PrivateKey(\n await PrivateKeyCrypto.fromKeystore(data, passphrase),\n );\n }\n\n /**\n * Recover a private key from a pem string; the private key may be encrypted.\n *\n * This method assumes the .pem file has been converted to a string already.\n *\n * If `passphrase` is not null or empty, this looks for the first `ENCRYPTED PRIVATE KEY`\n * section and uses `passphrase` to decrypt it; otherwise, it looks for the first `PRIVATE KEY`\n * section and decodes that as a DER-encoded private key.\n *\n * @param {string} data\n * @param {string} [passphrase]\n * @returns {Promise<PrivateKey>}\n */\n static async fromPem(data, passphrase = \"\") {\n return new PrivateKey(await PrivateKeyCrypto.fromPem(data, passphrase));\n }\n\n /**\n * Derive a new private key at the given wallet index.\n *\n * Only currently supported for keys created with `fromMnemonic()`; other keys will throw\n * an error.\n *\n * You can check if a key supports derivation with `.supportsDerivation()`\n *\n * @param {number} index\n * @returns {Promise<PrivateKey>}\n * @throws If this key does not support derivation.\n */\n async derive(index) {\n return new PrivateKey(await this._key.derive(index));\n }\n\n /**\n * @param {number} index\n * @returns {Promise<PrivateKey>}\n * @throws If this key does not support derivation.\n */\n async legacyDerive(index) {\n return new PrivateKey(await this._key.legacyDerive(index));\n }\n\n /**\n * Get the public key associated with this private key.\n *\n * The public key can be freely given and used by other parties to verify\n * the signatures generated by this private key.\n *\n * @returns {PublicKey}\n */\n get publicKey() {\n return new PublicKey(this._key.publicKey);\n }\n\n /**\n * Get the public key associated with this private key.\n *\n * The public key can be freely given and used by other parties to verify\n * the signatures generated by this private key.\n *\n * @returns {?Uint8Array}\n */\n get chainCode() {\n return this._key._chainCode;\n }\n\n /**\n * Sign a message with this private key.\n *\n * @param {Uint8Array} bytes\n * @returns {Uint8Array} - The signature bytes without the message\n */\n sign(bytes) {\n return this._key.sign(bytes);\n }\n\n /**\n * @deprecated - Use legacy=false flag to use the modern approach\n * or don't pass it at all.\n * @overload\n * @param {Transaction} transaction\n * @param {true} legacy\n * @returns {Uint8Array | Uint8Array[] }\n */\n\n /**\n * @overload\n * @param {Transaction} transaction\n * @param {false} [legacy]\n * @returns {SignatureMap}\n */\n\n /**\n * @param {Transaction} transaction\n * @param {boolean} [legacy]\n * @returns {Uint8Array | Uint8Array[] | SignatureMap}\n */\n signTransaction(transaction, legacy = false) {\n if (legacy) {\n return this._signTransactionLegacy(transaction);\n }\n\n const sigMap = new SignatureMap();\n\n for (const signedTx of transaction._signedTransactions.list) {\n const bodyBytes = signedTx.bodyBytes;\n if (!bodyBytes) throw new Error(\"Body bytes are missing\");\n\n const body = proto.TransactionBody.decode(bodyBytes);\n if (!body.transactionID || !body.nodeAccountID) {\n throw new Error(\n \"Transaction ID or Node Account ID not found in the signed transaction\",\n );\n }\n\n const nodeId = AccountId._fromProtobuf(body.nodeAccountID);\n const transactionId = TransactionId._fromProtobuf(\n body.transactionID,\n );\n const sig = this._key.sign(bodyBytes);\n sigMap.addSignature(nodeId, transactionId, this.publicKey, sig);\n }\n\n transaction.addSignature(this.publicKey, sigMap);\n return sigMap;\n }\n\n /**\n * deprecated - This method is deprecated and will be removed in future versions.\n * Use the `signTransaction` method with the `legacy=false` flag or don't\n * pass it all for the modern approach.\n * @param {Transaction} transaction\n * @returns {Uint8Array | Uint8Array[]}\n */\n _signTransactionLegacy(transaction) {\n const signatures = transaction._signedTransactions.list.map(\n (signedTransaction) => {\n const bodyBytes = signedTransaction.bodyBytes;\n if (!bodyBytes) {\n return new Uint8Array();\n }\n\n return this._key.sign(bodyBytes);\n },\n );\n transaction.addSignature(this.publicKey, signatures);\n // Return directly Uint8Array if there is only one signature\n return signatures.length === 1 ? signatures[0] : signatures;\n }\n\n /**\n * Check if `derive` can be called on this private key.\n *\n * This is only the case if the key was created from a mnemonic.\n *\n * @returns {boolean}\n */\n isDerivable() {\n return this._key.isDerivable();\n }\n\n /**\n * @returns {Uint8Array}\n */\n toBytes() {\n return this._key.toBytes();\n }\n\n /**\n * @returns {Uint8Array}\n */\n toBytesDer() {\n return this._key.toBytesDer();\n }\n\n /**\n * @returns {Uint8Array}\n */\n toBytesRaw() {\n return this._key.toBytesRaw();\n }\n\n /**\n * @returns {string}\n */\n toString() {\n return this._key.toStringDer();\n }\n\n /**\n * @returns {string}\n */\n toStringDer() {\n return this._key.toStringDer();\n }\n\n /**\n * @returns {string}\n */\n toStringRaw() {\n return this._key.toStringRaw();\n }\n\n /**\n * Create a keystore with a given passphrase.\n *\n * The key can be recovered later with `fromKeystore()`.\n *\n * Note that this will not retain the ancillary data used for\n * deriving child keys, thus `.derive()` on the restored key will\n * throw even if this instance supports derivation.\n *\n * @param {string} [passphrase]\n * @returns {Promise<Uint8Array>}\n */\n toKeystore(passphrase = \"\") {\n return this._key.toKeystore(passphrase);\n }\n\n /**\n * @returns {HieroProto.proto.IKey}\n */\n _toProtobufKey() {\n return this.publicKey._toProtobufKey();\n }\n\n /**\n * @param {Long | number} shard\n * @param {Long | number} realm\n * @returns {AccountId}\n */\n toAccountId(shard, realm) {\n return this.publicKey.toAccountId(shard, realm);\n }\n\n /**\n * @returns {string}\n */\n get type() {\n return this._key._type;\n }\n\n /**\n * Recover the recovery ID used in the signature for the given message.\n *\n * **Note:** This method only works for ECDSA secp256k1 keys.\n * @param {Uint8Array} r - 32-byte `r` component of the signature\n * @param {Uint8Array} s - 32-byte `s` component of the signature\n * @param {Uint8Array} message - The original (unhashed) message\n * @returns {number} Recovery ID (0–3), or -1 if not found or not applicable\n */\n getRecoveryId(r, s, message) {\n return this._key.getRecoveryId(r, s, message);\n }\n\n /**\n * @param {string} privateKey\n * @returns { \"ecdsa\" | \"ed25519\"}\n */\n static getAlgorithm(privateKey) {\n if (!PrivateKey.isDerKey(privateKey)) {\n throw new Error(\"Only der keys are supported\");\n }\n\n const decoder = new ASN1Decoder(Uint8Array.from(decode(privateKey)));\n decoder.read();\n const decodedKeyType = decoder.getOidKeyTypes()[0];\n // @ts-ignored\n return decodedKeyType;\n }\n\n /**\n * @internal\n * @param {string} key\n * @returns {boolean}\n */\n static isDerKey(key) {\n try {\n const data = Uint8Array.from(decode(key));\n const decoder = new ASN1Decoder(data);\n decoder.read(); // Attempt to read the ASN.1 structure\n return true;\n } catch (error) {\n return false;\n }\n }\n}\n\nCACHE.setPrivateKeyConstructor((key) => new PrivateKey(key));\n"],"names":["PrivateKey","Key","constructor","key","super","this","_key","generateED25519","PrivateKeyCrypto","generateECDSA","generate","generateAsync","generateED25519Async","generateECDSAAsync","fromBytes","data","keyString","hexlify","isDerKey","getAlgorithm","fromBytesECDSA","fromBytesED25519","fromString","text","fromStringDer","fromStringECDSA","fromStringED25519","fromSeedED25519","seed","fromSeedECDSAsecp256k1","fromMnemonic","mnemonic","passphrase","Mnemonic","_mnemonic","fromKeystore","fromPem","derive","index","legacyDerive","publicKey","PublicKey","chainCode","_chainCode","sign","bytes","signTransaction","transaction","legacy","_signTransactionLegacy","sigMap","SignatureMap","signedTx","_signedTransactions","list","bodyBytes","Error","body","proto","TransactionBody","decode","transactionID","nodeAccountID","nodeId","AccountId","_fromProtobuf","transactionId","TransactionId","sig","addSignature","signatures","map","signedTransaction","Uint8Array","length","isDerivable","toBytes","toBytesDer","toBytesRaw","toString","toStringDer","toStringRaw","toKeystore","_toProtobufKey","toAccountId","shard","realm","type","_type","getRecoveryId","r","s","message","privateKey","decoder","ASN1Decoder","from","read","getOidKeyTypes","error","CACHE","setPrivateKeyConstructor"],"mappings":"mdA2Be,MAAMA,UAAmBC,EAMpC,WAAAC,CAAYC,GACRC,QAEAC,KAAKC,KAAOH,CAChB,CAOA,sBAAOI,GACH,OAAO,IAAIP,EAAWQ,EAAiBD,kBAC3C,CAOA,oBAAOE,GACH,OAAO,IAAIT,EAAWQ,EAAiBC,gBAC3C,CAQA,eAAOC,GACH,OAAOV,EAAWO,iBACtB,CAQA,0BAAaI,GACT,OAAO,IAAIX,QAAiBQ,EAAiBG,gBACjD,CAOA,iCAAaC,GACT,OAAO,IAAIZ,QAAiBQ,EAAiBI,uBACjD,CAOA,+BAAaC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("@hiero-ledger/proto").proto.IAccountID;
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
-
export type BigNumber = import("bignumber.js")
|
|
74
|
+
export type BigNumber = import("bignumber.js");
|
|
75
75
|
export type Long = import("long");
|
|
76
76
|
import AccountId from "./account/AccountId.js";
|
|
77
77
|
import Hbar from "./Hbar.js";
|
|
@@ -196,7 +196,7 @@ export type Channel = import("../channel/Channel.js").default;
|
|
|
196
196
|
export type MirrorChannel = import("../channel/MirrorChannel.js").default;
|
|
197
197
|
export type Client = import("../client/Client.js").default<Channel, MirrorChannel>;
|
|
198
198
|
export type TransactionId = import("../transaction/TransactionId.js").default;
|
|
199
|
-
export type BigNumber = import("bignumber.js")
|
|
199
|
+
export type BigNumber = import("bignumber.js");
|
|
200
200
|
export type LongObject = import("../long.js").LongObject;
|
|
201
201
|
import Transaction from "../transaction/Transaction.js";
|
|
202
202
|
import HbarAllowance from "./HbarAllowance.js";
|
|
@@ -182,7 +182,7 @@ export type Channel = import("../channel/Channel.js").default;
|
|
|
182
182
|
export type MirrorChannel = import("../channel/MirrorChannel.js").default;
|
|
183
183
|
export type Client = import("../client/Client.js").default<Channel, MirrorChannel>;
|
|
184
184
|
export type TransactionId = import("../transaction/TransactionId.js").default;
|
|
185
|
-
export type BigNumber = import("bignumber.js")
|
|
185
|
+
export type BigNumber = import("bignumber.js");
|
|
186
186
|
export type LongObject = import("../long.js").LongObject;
|
|
187
187
|
import Transaction from "../transaction/Transaction.js";
|
|
188
188
|
import HbarAllowance from "./HbarAllowance.js";
|
|
@@ -84,7 +84,7 @@ export type Channel = import("../channel/Channel.js").default;
|
|
|
84
84
|
export type MirrorChannel = import("../channel/MirrorChannel.js").default;
|
|
85
85
|
export type Client = import("../client/Client.js").default<Channel, MirrorChannel>;
|
|
86
86
|
export type TransactionId = import("../transaction/TransactionId.js").default;
|
|
87
|
-
export type BigNumber = import("bignumber.js")
|
|
87
|
+
export type BigNumber = import("bignumber.js");
|
|
88
88
|
export type LongObject = import("../long.js").LongObject;
|
|
89
89
|
import Transaction from "../transaction/Transaction.js";
|
|
90
90
|
import TokenNftAllowance from "./TokenNftAllowance.js";
|
|
@@ -36,7 +36,7 @@ export default class AccountCreateTransaction extends Transaction {
|
|
|
36
36
|
*/
|
|
37
37
|
constructor(props?: {
|
|
38
38
|
key?: Key | undefined;
|
|
39
|
-
initialBalance?: string | number | Long | import("bignumber.js")
|
|
39
|
+
initialBalance?: string | number | Long | import("bignumber.js") | Hbar | undefined;
|
|
40
40
|
receiverSignatureRequired?: boolean | undefined;
|
|
41
41
|
proxyAccountId?: AccountId | undefined;
|
|
42
42
|
autoRenewPeriod?: number | Long | Duration | undefined;
|
|
@@ -295,7 +295,7 @@ export default class AccountCreateTransaction extends Transaction {
|
|
|
295
295
|
*/
|
|
296
296
|
protected override _makeTransactionData(): HieroProto.proto.ICryptoCreateTransactionBody;
|
|
297
297
|
}
|
|
298
|
-
export type BigNumber = import("bignumber.js")
|
|
298
|
+
export type BigNumber = import("bignumber.js");
|
|
299
299
|
export type Channel = import("../channel/Channel.js").default;
|
|
300
300
|
export type MirrorChannel = import("../channel/MirrorChannel.js").default;
|
|
301
301
|
export type Client = import("../client/Client.js").default<Channel, MirrorChannel>;
|
|
@@ -7,13 +7,10 @@ exports.default = void 0;
|
|
|
7
7
|
var _Query = _interopRequireWildcard(require("../query/Query.cjs"));
|
|
8
8
|
var _AccountId = _interopRequireDefault(require("./AccountId.cjs"));
|
|
9
9
|
var _AccountInfo = _interopRequireDefault(require("./AccountInfo.cjs"));
|
|
10
|
-
var _Hbar = _interopRequireDefault(require("../Hbar.cjs"));
|
|
11
10
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
11
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
13
12
|
// SPDX-License-Identifier: Apache-2.0
|
|
14
13
|
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
16
|
-
|
|
17
14
|
/**
|
|
18
15
|
* @namespace proto
|
|
19
16
|
* @typedef {import("@hiero-ledger/proto").proto.IQuery} HieroProto.proto.IQuery
|
|
@@ -29,6 +26,7 @@ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r
|
|
|
29
26
|
* @typedef {import("../channel/Channel.js").default} Channel
|
|
30
27
|
* @typedef {import("../channel/MirrorChannel.js").default} MirrorChannel
|
|
31
28
|
* @typedef {import("../client/Client.js").default<Channel, MirrorChannel>} Client
|
|
29
|
+
* @typedef {import("../Hbar.js").default} Hbar
|
|
32
30
|
*/
|
|
33
31
|
|
|
34
32
|
/**
|
|
@@ -106,7 +104,7 @@ class AccountInfoQuery extends _Query.default {
|
|
|
106
104
|
|
|
107
105
|
/**
|
|
108
106
|
* @override
|
|
109
|
-
* @param {
|
|
107
|
+
* @param {Client} client
|
|
110
108
|
* @returns {Promise<Hbar>}
|
|
111
109
|
*/
|
|
112
110
|
async getCost(client) {
|
|
@@ -129,12 +127,13 @@ class AccountInfoQuery extends _Query.default {
|
|
|
129
127
|
* @override
|
|
130
128
|
* @internal
|
|
131
129
|
* @param {HieroProto.proto.IResponse} response
|
|
132
|
-
* @param {AccountId}
|
|
133
|
-
* @param {HieroProto.proto.IQuery}
|
|
130
|
+
* @param {AccountId} _nodeAccountId
|
|
131
|
+
* @param {HieroProto.proto.IQuery} _request
|
|
134
132
|
* @returns {Promise<AccountInfo>}
|
|
135
133
|
*/
|
|
136
|
-
|
|
137
|
-
|
|
134
|
+
_mapResponse(response, _nodeAccountId, _request) {
|
|
135
|
+
void _nodeAccountId;
|
|
136
|
+
void _request;
|
|
138
137
|
const info = /** @type {HieroProto.proto.ICryptoGetInfoResponse} */
|
|
139
138
|
response.cryptoGetInfo;
|
|
140
139
|
return Promise.resolve(_AccountInfo.default._fromProtobuf(/** @type {HieroProto.proto.CryptoGetInfoResponse.IAccountInfo} */
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
* @typedef {import("../channel/Channel.js").default} Channel
|
|
13
13
|
* @typedef {import("../channel/MirrorChannel.js").default} MirrorChannel
|
|
14
14
|
* @typedef {import("../client/Client.js").default<Channel, MirrorChannel>} Client
|
|
15
|
+
* @typedef {import("../Hbar.js").default} Hbar
|
|
15
16
|
*/
|
|
16
17
|
/**
|
|
17
18
|
* Retrieves the metadata of an account
|
|
@@ -51,6 +52,12 @@ export default class AccountInfoQuery extends Query<AccountInfo> {
|
|
|
51
52
|
* @param {Client} client
|
|
52
53
|
*/
|
|
53
54
|
_validateChecksums(client: Client): void;
|
|
55
|
+
/**
|
|
56
|
+
* @override
|
|
57
|
+
* @param {Client} client
|
|
58
|
+
* @returns {Promise<Hbar>}
|
|
59
|
+
*/
|
|
60
|
+
override getCost(client: Client): Promise<Hbar>;
|
|
54
61
|
}
|
|
55
62
|
export namespace HieroProto {
|
|
56
63
|
namespace proto {
|
|
@@ -68,6 +75,7 @@ export namespace HieroProto {
|
|
|
68
75
|
export type Channel = import("../channel/Channel.js").default;
|
|
69
76
|
export type MirrorChannel = import("../channel/MirrorChannel.js").default;
|
|
70
77
|
export type Client = import("../client/Client.js").default<Channel, MirrorChannel>;
|
|
78
|
+
export type Hbar = import("../Hbar.js").default;
|
|
71
79
|
import AccountInfo from "./AccountInfo.js";
|
|
72
80
|
import Query from "../query/Query.js";
|
|
73
81
|
import AccountId from "./AccountId.js";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import t,{QUERY_REGISTRY as o}from"../query/Query.js";import n from"./AccountId.js";import
|
|
1
|
+
import t,{QUERY_REGISTRY as o}from"../query/Query.js";import n from"./AccountId.js";import c from"./AccountInfo.js";class e extends t{constructor(t={}){super(),this._accountId=null,null!=t.accountId&&this.setAccountId(t.accountId)}static _fromProtobuf(t){const o=t.cryptoGetInfo;return new e({accountId:null!=o.accountID?n._fromProtobuf(o.accountID):void 0})}get accountId(){return this._accountId}setAccountId(t){return this._accountId="string"==typeof t?n.fromString(t):t.clone(),this}_validateChecksums(t){null!=this._accountId&&this._accountId.validateChecksum(t)}_execute(t,o){return t.crypto.getAccountInfo(o)}async getCost(t){return super.getCost(t)}_mapResponseHeader(t){return t.cryptoGetInfo.header}_mapResponse(t,o,n){const e=t.cryptoGetInfo;return Promise.resolve(c._fromProtobuf(e.accountInfo))}_onMakeRequest(t){return{cryptoGetInfo:{header:t,accountID:null!=this._accountId?this._accountId._toProtobuf():null}}}_getLogId(){return`AccountInfoQuery:${(null!=this._paymentTransactionId&&null!=this._paymentTransactionId.validStart?this._paymentTransactionId.validStart:this._timestamp).toString()}`}}o.set("cryptoGetInfo",e._fromProtobuf);export{e as default};
|
|
2
2
|
//# sourceMappingURL=AccountInfoQuery.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccountInfoQuery.js","sources":["../../src/account/AccountInfoQuery.js"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\nimport Query, { QUERY_REGISTRY } from \"../query/Query.js\";\nimport AccountId from \"./AccountId.js\";\nimport AccountInfo from \"./AccountInfo.js\";\n
|
|
1
|
+
{"version":3,"file":"AccountInfoQuery.js","sources":["../../src/account/AccountInfoQuery.js"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\nimport Query, { QUERY_REGISTRY } from \"../query/Query.js\";\nimport AccountId from \"./AccountId.js\";\nimport AccountInfo from \"./AccountInfo.js\";\n\n/**\n * @namespace proto\n * @typedef {import(\"@hiero-ledger/proto\").proto.IQuery} HieroProto.proto.IQuery\n * @typedef {import(\"@hiero-ledger/proto\").proto.IQueryHeader} HieroProto.proto.IQueryHeader\n * @typedef {import(\"@hiero-ledger/proto\").proto.IResponse} HieroProto.proto.IResponse\n * @typedef {import(\"@hiero-ledger/proto\").proto.IResponseHeader} HieroProto.proto.IResponseHeader\n * @typedef {import(\"@hiero-ledger/proto\").proto.CryptoGetInfoResponse.IAccountInfo} HieroProto.proto.CryptoGetInfoResponse.IAccountInfo\n * @typedef {import(\"@hiero-ledger/proto\").proto.ICryptoGetInfoQuery} HieroProto.proto.ICryptoGetInfoQuery\n * @typedef {import(\"@hiero-ledger/proto\").proto.ICryptoGetInfoResponse} HieroProto.proto.ICryptoGetInfoResponse\n */\n\n/**\n * @typedef {import(\"../channel/Channel.js\").default} Channel\n * @typedef {import(\"../channel/MirrorChannel.js\").default} MirrorChannel\n * @typedef {import(\"../client/Client.js\").default<Channel, MirrorChannel>} Client\n * @typedef {import(\"../Hbar.js\").default} Hbar\n */\n\n/**\n * Retrieves the metadata of an account\n * @augments {Query<AccountInfo>}\n */\nexport default class AccountInfoQuery extends Query {\n /**\n * @param {object} props\n * @param {AccountId | string} [props.accountId]\n */\n constructor(props = {}) {\n super();\n\n /**\n * @private\n * @type {?AccountId}\n */\n this._accountId = null;\n if (props.accountId != null) {\n this.setAccountId(props.accountId);\n }\n }\n\n /**\n * @internal\n * @param {HieroProto.proto.IQuery} query\n * @returns {AccountInfoQuery}\n */\n static _fromProtobuf(query) {\n const info = /** @type {HieroProto.proto.ICryptoGetInfoQuery} */ (\n query.cryptoGetInfo\n );\n\n return new AccountInfoQuery({\n accountId:\n info.accountID != null\n ? AccountId._fromProtobuf(info.accountID)\n : undefined,\n });\n }\n\n /**\n * @returns {?AccountId}\n */\n get accountId() {\n return this._accountId;\n }\n\n /**\n * Set the account ID for which the info is being requested.\n *\n * @param {AccountId | string} accountId\n * @returns {AccountInfoQuery}\n */\n setAccountId(accountId) {\n this._accountId =\n typeof accountId === \"string\"\n ? AccountId.fromString(accountId)\n : accountId.clone();\n\n return this;\n }\n\n /**\n * @param {Client} client\n */\n _validateChecksums(client) {\n if (this._accountId != null) {\n this._accountId.validateChecksum(client);\n }\n }\n\n /**\n * @override\n * @internal\n * @param {Channel} channel\n * @param {HieroProto.proto.IQuery} request\n * @returns {Promise<HieroProto.proto.IResponse>}\n */\n _execute(channel, request) {\n return channel.crypto.getAccountInfo(request);\n }\n\n /**\n * @override\n * @param {Client} client\n * @returns {Promise<Hbar>}\n */\n async getCost(client) {\n return super.getCost(client);\n }\n\n /**\n * @override\n * @internal\n * @param {HieroProto.proto.IResponse} response\n * @returns {HieroProto.proto.IResponseHeader}\n */\n _mapResponseHeader(response) {\n const cryptoGetInfo =\n /** @type {HieroProto.proto.ICryptoGetInfoResponse} */ (\n response.cryptoGetInfo\n );\n return /** @type {HieroProto.proto.IResponseHeader} */ (\n cryptoGetInfo.header\n );\n }\n\n /**\n * @override\n * @internal\n * @param {HieroProto.proto.IResponse} response\n * @param {AccountId} _nodeAccountId\n * @param {HieroProto.proto.IQuery} _request\n * @returns {Promise<AccountInfo>}\n */\n _mapResponse(response, _nodeAccountId, _request) {\n void _nodeAccountId;\n void _request;\n\n const info = /** @type {HieroProto.proto.ICryptoGetInfoResponse} */ (\n response.cryptoGetInfo\n );\n\n return Promise.resolve(\n AccountInfo._fromProtobuf(\n /** @type {HieroProto.proto.CryptoGetInfoResponse.IAccountInfo} */ (\n info.accountInfo\n ),\n ),\n );\n }\n\n /**\n * @override\n * @internal\n * @param {HieroProto.proto.IQueryHeader} header\n * @returns {HieroProto.proto.IQuery}\n */\n _onMakeRequest(header) {\n return {\n cryptoGetInfo: {\n header,\n accountID:\n this._accountId != null\n ? this._accountId._toProtobuf()\n : null,\n },\n };\n }\n\n /**\n * @returns {string}\n */\n _getLogId() {\n const timestamp =\n this._paymentTransactionId != null &&\n this._paymentTransactionId.validStart != null\n ? this._paymentTransactionId.validStart\n : this._timestamp;\n return `AccountInfoQuery:${timestamp.toString()}`;\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/unbound-method\nQUERY_REGISTRY.set(\"cryptoGetInfo\", AccountInfoQuery._fromProtobuf);\n"],"names":["AccountInfoQuery","Query","constructor","props","super","this","_accountId","accountId","setAccountId","_fromProtobuf","query","info","accountID","AccountId","undefined","fromString","clone","_validateChecksums","client","validateChecksum","_execute","channel","request","crypto","getAccountInfo","getCost","_mapResponseHeader","response","_mapResponse","_nodeAccountId","_request","Promise","resolve","AccountInfo","_onMakeRequest","header","cryptoGetInfo","_toProtobuf","_getLogId","_paymentTransactionId","validStart","_timestamp","toString","QUERY_REGISTRY","set"],"mappings":"oHA4Be,MAAMA,UAAyBC,EAK1C,WAAAC,CAAYC,EAAQ,IAChBC,QAMAC,KAAKC,WAAa,KACK,MAAnBH,EAAMI,WACNF,KAAKG,aAAaL,EAAMI,UAEhC,CAOA,oBAAOE,CAAcC,GACjB,MAAMC,EACFD,EACZ,cAEQ,OAAO,IAAIV,EAAiB,CACxBO,UACsB,MAAlBI,EAAKC,UACCC,EAAUJ,cAAcE,EAAKC,gBAC7BE,GAElB,CAKA,aAAIP,GACA,OAAOF,KAAKC,UAChB,CAQA,YAAAE,CAAaD,GAMT,OALAF,KAAKC,WACoB,iBAAdC,EACDM,EAAUE,WAAWR,GACrBA,EAAUS,QAEbX,IACX,CAKA,kBAAAY,CAAmBC,GACQ,MAAnBb,KAAKC,YACLD,KAAKC,WAAWa,iBAAiBD,EAEzC,CASA,QAAAE,CAASC,EAASC,GACd,OAAOD,EAAQE,OAAOC,eAAeF,EACzC,CAOA,aAAMG,CAAQP,GACV,OAAOd,MAAMqB,QAAQP,EACzB,CAQA,kBAAAQ,CAAmBC,GAKf,OAFQA,EAChB,cAGA,MACI,CAUA,YAAAC,CAAaD,EAAUE,EAAgBC,GAInC,MAAMnB,EACFgB,EACZ,cAEQ,OAAOI,QAAQC,QACXC,EAAYxB,cAEJE,EACpB,aAGI,CAQA,cAAAuB,CAAeC,GACX,MAAO,CACHC,cAAe,CACXD,SACAvB,UACuB,MAAnBP,KAAKC,WACCD,KAAKC,WAAW+B,cAChB,MAGtB,CAKA,SAAAC,GAMI,MAAO,qBAJ2B,MAA9BjC,KAAKkC,uBACoC,MAAzClC,KAAKkC,sBAAsBC,WACrBnC,KAAKkC,sBAAsBC,WAC3BnC,KAAKoC,YACsBC,YACzC,EAIJC,EAAeC,IAAI,gBAAiB5C,EAAiBS"}
|
|
@@ -25,7 +25,7 @@ export namespace HieroProto {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
export type LongObject = import("../long.js").LongObject;
|
|
28
|
-
export type BigNumber = import("bignumber.js")
|
|
28
|
+
export type BigNumber = import("bignumber.js");
|
|
29
29
|
import AccountId from "./AccountId.js";
|
|
30
30
|
import Hbar from "../Hbar.js";
|
|
31
31
|
import ObjectMap from "../ObjectMap.js";
|
|
@@ -48,6 +48,6 @@ export namespace HieroProto {
|
|
|
48
48
|
type IAccountID = import("@hiero-ledger/proto").proto.IAccountID;
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
export type BigNumber = import("bignumber.js")
|
|
51
|
+
export type BigNumber = import("bignumber.js");
|
|
52
52
|
import AccountId from "./AccountId.js";
|
|
53
53
|
import Hbar from "../Hbar.js";
|
|
@@ -93,7 +93,7 @@ export namespace HieroProto {
|
|
|
93
93
|
export type Channel = import("../channel/Channel.js").default;
|
|
94
94
|
export type MirrorChannel = import("../channel/MirrorChannel.js").default;
|
|
95
95
|
export type Client = import("../client/Client.js").default<Channel, MirrorChannel>;
|
|
96
|
-
export type BigNumber = import("bignumber.js")
|
|
96
|
+
export type BigNumber = import("bignumber.js");
|
|
97
97
|
import TokenId from "../token/TokenId.js";
|
|
98
98
|
import AccountId from "./AccountId.js";
|
|
99
99
|
import Long from "long";
|
|
@@ -38,7 +38,7 @@ export namespace HieroProto {
|
|
|
38
38
|
type IAccountID = import("@hiero-ledger/proto").proto.IAccountID;
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
export type BigNumber = import("bignumber.js")
|
|
41
|
+
export type BigNumber = import("bignumber.js");
|
|
42
42
|
import TokenId from "../token/TokenId.js";
|
|
43
43
|
import TokenTransferAccountMap from "./TokenTransferAccountMap.js";
|
|
44
44
|
import ObjectMap from "../ObjectMap.js";
|
|
@@ -132,7 +132,7 @@ export default class TransferTransaction extends AbstractTokenTransferTransactio
|
|
|
132
132
|
protected override _makeTransactionData(): HieroProto.proto.ICryptoTransferTransactionBody;
|
|
133
133
|
}
|
|
134
134
|
export type LongObject = import("../long.js").LongObject;
|
|
135
|
-
export type BigNumber = import("bignumber.js")
|
|
135
|
+
export type BigNumber = import("bignumber.js");
|
|
136
136
|
export namespace HieroProto {
|
|
137
137
|
namespace proto {
|
|
138
138
|
type ITransaction = import("@hiero-ledger/proto").proto.ITransaction;
|