phantasma-sdk-ts 0.1.71
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/.eslintignore +13 -0
- package/.eslintrc.cjs +15 -0
- package/.github/workflows/npm-publish.yml +47 -0
- package/.prettierignore +13 -0
- package/.prettierrc +8 -0
- package/LICENSE +201 -0
- package/README.md +842 -0
- package/babel.config.js +6 -0
- package/core/index.d.ts +10 -0
- package/core/index.d.ts.map +1 -0
- package/core/index.js +25 -0
- package/core/interfaces/IContract.d.ts +27 -0
- package/core/interfaces/IContract.d.ts.map +1 -0
- package/core/interfaces/IContract.js +25 -0
- package/core/interfaces/IKeyPair.d.ts +7 -0
- package/core/interfaces/IKeyPair.d.ts.map +1 -0
- package/core/interfaces/IKeyPair.js +2 -0
- package/core/interfaces/ISerializable.d.ts +6 -0
- package/core/interfaces/ISerializable.d.ts.map +1 -0
- package/core/interfaces/ISerializable.js +9 -0
- package/core/interfaces/IStack.d.ts +7 -0
- package/core/interfaces/IStack.d.ts.map +1 -0
- package/core/interfaces/IStack.js +2 -0
- package/core/interfaces/IToken.d.ts +29 -0
- package/core/interfaces/IToken.d.ts.map +1 -0
- package/core/interfaces/IToken.js +22 -0
- package/core/interfaces/Signature.d.ts +21 -0
- package/core/interfaces/Signature.d.ts.map +1 -0
- package/core/interfaces/Signature.js +31 -0
- package/core/interfaces/index.d.ts +7 -0
- package/core/interfaces/index.d.ts.map +1 -0
- package/core/interfaces/index.js +22 -0
- package/core/ledger/Address-Transcode.d.ts +20 -0
- package/core/ledger/Address-Transcode.d.ts.map +1 -0
- package/core/ledger/Address-Transcode.js +70 -0
- package/core/ledger/Ledger-Commands.d.ts +76 -0
- package/core/ledger/Ledger-Commands.d.ts.map +1 -0
- package/core/ledger/Ledger-Commands.js +530 -0
- package/core/ledger/Ledger-Utils.d.ts +74 -0
- package/core/ledger/Ledger-Utils.d.ts.map +1 -0
- package/core/ledger/Ledger-Utils.js +609 -0
- package/core/ledger/LedgerConfig.d.ts +17 -0
- package/core/ledger/LedgerConfig.d.ts.map +1 -0
- package/core/ledger/LedgerConfig.js +2 -0
- package/core/ledger/Mnemonic.d.ts +35 -0
- package/core/ledger/Mnemonic.d.ts.map +1 -0
- package/core/ledger/Mnemonic.js +65 -0
- package/core/ledger/Transaction-Sign.d.ts +10 -0
- package/core/ledger/Transaction-Sign.d.ts.map +1 -0
- package/core/ledger/Transaction-Sign.js +149 -0
- package/core/ledger/Transaction-Transcode.d.ts +24 -0
- package/core/ledger/Transaction-Transcode.d.ts.map +1 -0
- package/core/ledger/Transaction-Transcode.js +47 -0
- package/core/ledger/index.d.ts +9 -0
- package/core/ledger/index.d.ts.map +1 -0
- package/core/ledger/index.js +24 -0
- package/core/ledger/interfaces/ApplicationNameResponse.d.ts +6 -0
- package/core/ledger/interfaces/ApplicationNameResponse.d.ts.map +1 -0
- package/core/ledger/interfaces/ApplicationNameResponse.js +2 -0
- package/core/ledger/interfaces/Device.d.ts +7 -0
- package/core/ledger/interfaces/Device.d.ts.map +1 -0
- package/core/ledger/interfaces/Device.js +2 -0
- package/core/ledger/interfaces/DeviceResponse.d.ts +7 -0
- package/core/ledger/interfaces/DeviceResponse.d.ts.map +1 -0
- package/core/ledger/interfaces/DeviceResponse.js +2 -0
- package/core/ledger/interfaces/Ledger.d.ts +2 -0
- package/core/ledger/interfaces/Ledger.d.ts.map +1 -0
- package/core/ledger/interfaces/Ledger.js +2 -0
- package/core/ledger/interfaces/LedgerBalanceFromLedgerResponse.d.ts +12 -0
- package/core/ledger/interfaces/LedgerBalanceFromLedgerResponse.d.ts.map +1 -0
- package/core/ledger/interfaces/LedgerBalanceFromLedgerResponse.js +2 -0
- package/core/ledger/interfaces/LedgerConfig.d.ts +17 -0
- package/core/ledger/interfaces/LedgerConfig.d.ts.map +1 -0
- package/core/ledger/interfaces/LedgerConfig.js +2 -0
- package/core/ledger/interfaces/LedgerDeviceInfoResponse.d.ts +7 -0
- package/core/ledger/interfaces/LedgerDeviceInfoResponse.d.ts.map +1 -0
- package/core/ledger/interfaces/LedgerDeviceInfoResponse.js +2 -0
- package/core/ledger/interfaces/LedgerSendTransactionResponse.d.ts +5 -0
- package/core/ledger/interfaces/LedgerSendTransactionResponse.d.ts.map +1 -0
- package/core/ledger/interfaces/LedgerSendTransactionResponse.js +2 -0
- package/core/ledger/interfaces/LedgerSigner.d.ts +6 -0
- package/core/ledger/interfaces/LedgerSigner.d.ts.map +1 -0
- package/core/ledger/interfaces/LedgerSigner.js +2 -0
- package/core/ledger/interfaces/LedgerSignerData.d.ts +8 -0
- package/core/ledger/interfaces/LedgerSignerData.d.ts.map +1 -0
- package/core/ledger/interfaces/LedgerSignerData.js +2 -0
- package/core/ledger/interfaces/PublicKeyResponse.d.ts +6 -0
- package/core/ledger/interfaces/PublicKeyResponse.d.ts.map +1 -0
- package/core/ledger/interfaces/PublicKeyResponse.js +2 -0
- package/core/ledger/interfaces/SignResponse.d.ts +6 -0
- package/core/ledger/interfaces/SignResponse.d.ts.map +1 -0
- package/core/ledger/interfaces/SignResponse.js +2 -0
- package/core/ledger/interfaces/VersionResponse.d.ts +6 -0
- package/core/ledger/interfaces/VersionResponse.d.ts.map +1 -0
- package/core/ledger/interfaces/VersionResponse.js +2 -0
- package/core/ledger/interfaces/index.d.ts +14 -0
- package/core/ledger/interfaces/index.d.ts.map +1 -0
- package/core/ledger/interfaces/index.js +29 -0
- package/core/ledger/ledger-comm.d.ts +85 -0
- package/core/ledger/ledger-comm.d.ts.map +1 -0
- package/core/ledger/ledger-comm.js +613 -0
- package/core/link/easyConnect.d.ts +23 -0
- package/core/link/easyConnect.d.ts.map +1 -0
- package/core/link/easyConnect.js +237 -0
- package/core/link/easyScript.d.ts +13 -0
- package/core/link/easyScript.d.ts.map +1 -0
- package/core/link/easyScript.js +52 -0
- package/core/link/index.d.ts +2 -0
- package/core/link/index.d.ts.map +1 -0
- package/core/link/index.js +17 -0
- package/core/link/interfaces/IAccount.d.ts +13 -0
- package/core/link/interfaces/IAccount.d.ts.map +1 -0
- package/core/link/interfaces/IAccount.js +2 -0
- package/core/link/interfaces/IFile.d.ts +7 -0
- package/core/link/interfaces/IFile.d.ts.map +1 -0
- package/core/link/interfaces/IFile.js +2 -0
- package/core/link/interfaces/ProofOfWork.d.ts +9 -0
- package/core/link/interfaces/ProofOfWork.d.ts.map +1 -0
- package/core/link/interfaces/ProofOfWork.js +12 -0
- package/core/link/interfaces/index.d.ts +4 -0
- package/core/link/interfaces/index.d.ts.map +1 -0
- package/core/link/interfaces/index.js +19 -0
- package/core/link/phantasmaLink.d.ts +41 -0
- package/core/link/phantasmaLink.d.ts.map +1 -0
- package/core/link/phantasmaLink.js +479 -0
- package/core/rpc/index.d.ts +3 -0
- package/core/rpc/index.d.ts.map +1 -0
- package/core/rpc/index.js +18 -0
- package/core/rpc/interfaces/ABIContract.d.ts +6 -0
- package/core/rpc/interfaces/ABIContract.d.ts.map +1 -0
- package/core/rpc/interfaces/ABIContract.js +2 -0
- package/core/rpc/interfaces/ABIEvent.d.ts +7 -0
- package/core/rpc/interfaces/ABIEvent.d.ts.map +1 -0
- package/core/rpc/interfaces/ABIEvent.js +2 -0
- package/core/rpc/interfaces/ABIMethod.d.ts +7 -0
- package/core/rpc/interfaces/ABIMethod.d.ts.map +1 -0
- package/core/rpc/interfaces/ABIMethod.js +2 -0
- package/core/rpc/interfaces/ABIParameter.d.ts +5 -0
- package/core/rpc/interfaces/ABIParameter.d.ts.map +1 -0
- package/core/rpc/interfaces/ABIParameter.js +2 -0
- package/core/rpc/interfaces/Account.d.ts +16 -0
- package/core/rpc/interfaces/Account.d.ts.map +1 -0
- package/core/rpc/interfaces/Account.js +2 -0
- package/core/rpc/interfaces/AccountTransactions.d.ts +6 -0
- package/core/rpc/interfaces/AccountTransactions.d.ts.map +1 -0
- package/core/rpc/interfaces/AccountTransactions.js +2 -0
- package/core/rpc/interfaces/Archive.d.ts +11 -0
- package/core/rpc/interfaces/Archive.d.ts.map +1 -0
- package/core/rpc/interfaces/Archive.js +2 -0
- package/core/rpc/interfaces/Auction.d.ts +13 -0
- package/core/rpc/interfaces/Auction.d.ts.map +1 -0
- package/core/rpc/interfaces/Auction.js +2 -0
- package/core/rpc/interfaces/Balance.d.ts +8 -0
- package/core/rpc/interfaces/Balance.d.ts.map +1 -0
- package/core/rpc/interfaces/Balance.js +2 -0
- package/core/rpc/interfaces/Block.d.ts +17 -0
- package/core/rpc/interfaces/Block.d.ts.map +1 -0
- package/core/rpc/interfaces/Block.js +2 -0
- package/core/rpc/interfaces/Chain.d.ts +10 -0
- package/core/rpc/interfaces/Chain.d.ts.map +1 -0
- package/core/rpc/interfaces/Chain.js +2 -0
- package/core/rpc/interfaces/Channel.d.ts +13 -0
- package/core/rpc/interfaces/Channel.d.ts.map +1 -0
- package/core/rpc/interfaces/Channel.js +2 -0
- package/core/rpc/interfaces/Contract.d.ts +11 -0
- package/core/rpc/interfaces/Contract.d.ts.map +1 -0
- package/core/rpc/interfaces/Contract.js +2 -0
- package/core/rpc/interfaces/Dapp.d.ts +6 -0
- package/core/rpc/interfaces/Dapp.d.ts.map +1 -0
- package/core/rpc/interfaces/Dapp.js +2 -0
- package/core/rpc/interfaces/Event.d.ts +7 -0
- package/core/rpc/interfaces/Event.d.ts.map +1 -0
- package/core/rpc/interfaces/Event.js +2 -0
- package/core/rpc/interfaces/Governance.d.ts +5 -0
- package/core/rpc/interfaces/Governance.d.ts.map +1 -0
- package/core/rpc/interfaces/Governance.js +2 -0
- package/core/rpc/interfaces/Interop.d.ts +5 -0
- package/core/rpc/interfaces/Interop.d.ts.map +1 -0
- package/core/rpc/interfaces/Interop.js +2 -0
- package/core/rpc/interfaces/KeyValue.d.ts +5 -0
- package/core/rpc/interfaces/KeyValue.d.ts.map +1 -0
- package/core/rpc/interfaces/KeyValue.js +2 -0
- package/core/rpc/interfaces/Leaderboard.d.ts +6 -0
- package/core/rpc/interfaces/Leaderboard.d.ts.map +1 -0
- package/core/rpc/interfaces/Leaderboard.js +2 -0
- package/core/rpc/interfaces/LeaderboardRow.d.ts +5 -0
- package/core/rpc/interfaces/LeaderboardRow.d.ts.map +1 -0
- package/core/rpc/interfaces/LeaderboardRow.js +2 -0
- package/core/rpc/interfaces/NFT.d.ts +14 -0
- package/core/rpc/interfaces/NFT.d.ts.map +1 -0
- package/core/rpc/interfaces/NFT.js +2 -0
- package/core/rpc/interfaces/Nexus.d.ts +14 -0
- package/core/rpc/interfaces/Nexus.d.ts.map +1 -0
- package/core/rpc/interfaces/Nexus.js +2 -0
- package/core/rpc/interfaces/Oracle.d.ts +5 -0
- package/core/rpc/interfaces/Oracle.d.ts.map +1 -0
- package/core/rpc/interfaces/Oracle.js +2 -0
- package/core/rpc/interfaces/Organization.d.ts +6 -0
- package/core/rpc/interfaces/Organization.d.ts.map +1 -0
- package/core/rpc/interfaces/Organization.js +2 -0
- package/core/rpc/interfaces/Paginated.d.ts +8 -0
- package/core/rpc/interfaces/Paginated.d.ts.map +1 -0
- package/core/rpc/interfaces/Paginated.js +2 -0
- package/core/rpc/interfaces/Peer.d.ts +8 -0
- package/core/rpc/interfaces/Peer.d.ts.map +1 -0
- package/core/rpc/interfaces/Peer.js +2 -0
- package/core/rpc/interfaces/Platform.d.ts +9 -0
- package/core/rpc/interfaces/Platform.d.ts.map +1 -0
- package/core/rpc/interfaces/Platform.js +2 -0
- package/core/rpc/interfaces/Receipt.d.ts +10 -0
- package/core/rpc/interfaces/Receipt.d.ts.map +1 -0
- package/core/rpc/interfaces/Receipt.js +2 -0
- package/core/rpc/interfaces/Script.d.ts +9 -0
- package/core/rpc/interfaces/Script.d.ts.map +1 -0
- package/core/rpc/interfaces/Script.js +2 -0
- package/core/rpc/interfaces/SendRawTx.d.ts +5 -0
- package/core/rpc/interfaces/SendRawTx.d.ts.map +1 -0
- package/core/rpc/interfaces/SendRawTx.js +2 -0
- package/core/rpc/interfaces/SignatureResult.d.ts +5 -0
- package/core/rpc/interfaces/SignatureResult.d.ts.map +1 -0
- package/core/rpc/interfaces/SignatureResult.js +2 -0
- package/core/rpc/interfaces/Stake.d.ts +6 -0
- package/core/rpc/interfaces/Stake.d.ts.map +1 -0
- package/core/rpc/interfaces/Stake.js +2 -0
- package/core/rpc/interfaces/Storage.d.ts +8 -0
- package/core/rpc/interfaces/Storage.d.ts.map +1 -0
- package/core/rpc/interfaces/Storage.js +2 -0
- package/core/rpc/interfaces/Swap.d.ts +13 -0
- package/core/rpc/interfaces/Swap.d.ts.map +1 -0
- package/core/rpc/interfaces/Swap.js +2 -0
- package/core/rpc/interfaces/Token.d.ts +19 -0
- package/core/rpc/interfaces/Token.d.ts.map +1 -0
- package/core/rpc/interfaces/Token.js +2 -0
- package/core/rpc/interfaces/TokenData.d.ts +13 -0
- package/core/rpc/interfaces/TokenData.d.ts.map +1 -0
- package/core/rpc/interfaces/TokenData.js +2 -0
- package/core/rpc/interfaces/TokenExternal.d.ts +5 -0
- package/core/rpc/interfaces/TokenExternal.d.ts.map +1 -0
- package/core/rpc/interfaces/TokenExternal.js +2 -0
- package/core/rpc/interfaces/TokenPrice.d.ts +8 -0
- package/core/rpc/interfaces/TokenPrice.d.ts.map +1 -0
- package/core/rpc/interfaces/TokenPrice.js +2 -0
- package/core/rpc/interfaces/TokenSeries.d.ts +12 -0
- package/core/rpc/interfaces/TokenSeries.d.ts.map +1 -0
- package/core/rpc/interfaces/TokenSeries.js +2 -0
- package/core/rpc/interfaces/TransactionData.d.ts +23 -0
- package/core/rpc/interfaces/TransactionData.d.ts.map +1 -0
- package/core/rpc/interfaces/TransactionData.js +2 -0
- package/core/rpc/interfaces/Validator.d.ts +5 -0
- package/core/rpc/interfaces/Validator.d.ts.map +1 -0
- package/core/rpc/interfaces/Validator.js +2 -0
- package/core/rpc/interfaces/index.d.ts +42 -0
- package/core/rpc/interfaces/index.d.ts.map +1 -0
- package/core/rpc/interfaces/index.js +57 -0
- package/core/rpc/phantasma.d.ts +89 -0
- package/core/rpc/phantasma.d.ts.map +1 -0
- package/core/rpc/phantasma.js +900 -0
- package/core/tx/SignatureKind.js +9 -0
- package/core/tx/Transaction.d.ts +28 -0
- package/core/tx/Transaction.d.ts.map +1 -0
- package/core/tx/Transaction.js +209 -0
- package/core/tx/index.d.ts +3 -0
- package/core/tx/index.d.ts.map +1 -0
- package/core/tx/index.js +18 -0
- package/core/tx/utils.d.ts +10 -0
- package/core/tx/utils.d.ts.map +1 -0
- package/core/tx/utils.js +147 -0
- package/core/types/Address.d.ts +41 -0
- package/core/types/Address.d.ts.map +1 -0
- package/core/types/Address.js +276 -0
- package/core/types/Consensus.d.ts +61 -0
- package/core/types/Consensus.d.ts.map +1 -0
- package/core/types/Consensus.js +151 -0
- package/core/types/Contract.d.ts +60 -0
- package/core/types/Contract.d.ts.map +1 -0
- package/core/types/Contract.js +342 -0
- package/core/types/DomainSettings.d.ts +87 -0
- package/core/types/DomainSettings.d.ts.map +1 -0
- package/core/types/DomainSettings.js +107 -0
- package/core/types/Ed25519Signature.d.ts +16 -0
- package/core/types/Ed25519Signature.d.ts.map +1 -0
- package/core/types/Ed25519Signature.js +78 -0
- package/core/types/Entropy.d.ts +5 -0
- package/core/types/Entropy.d.ts.map +1 -0
- package/core/types/Entropy.js +24 -0
- package/core/types/Extensions/Base16.d.ts +7 -0
- package/core/types/Extensions/Base16.d.ts.map +1 -0
- package/core/types/Extensions/Base16.js +36 -0
- package/core/types/Extensions/BinaryReader.d.ts +17 -0
- package/core/types/Extensions/BinaryReader.d.ts.map +1 -0
- package/core/types/Extensions/BinaryReader.js +192 -0
- package/core/types/Extensions/BinaryWriter.d.ts +25 -0
- package/core/types/Extensions/BinaryWriter.d.ts.map +1 -0
- package/core/types/Extensions/BinaryWriter.js +191 -0
- package/core/types/Extensions/Describer.d.ts +5 -0
- package/core/types/Extensions/Describer.d.ts.map +1 -0
- package/core/types/Extensions/Describer.js +25 -0
- package/core/types/Extensions/PBinaryReader.d.ts +42 -0
- package/core/types/Extensions/PBinaryReader.d.ts.map +1 -0
- package/core/types/Extensions/PBinaryReader.js +269 -0
- package/core/types/Extensions/PBinaryWriter.d.ts +49 -0
- package/core/types/Extensions/PBinaryWriter.d.ts.map +1 -0
- package/core/types/Extensions/PBinaryWriter.js +250 -0
- package/core/types/Extensions/TableColumns.d.ts +5 -0
- package/core/types/Extensions/TableColumns.d.ts.map +1 -0
- package/core/types/Extensions/TableColumns.js +22 -0
- package/core/types/Extensions/index.d.ts +5 -0
- package/core/types/Extensions/index.d.ts.map +1 -0
- package/core/types/Extensions/index.js +20 -0
- package/core/types/PhantasmaKeys.d.ts +19 -0
- package/core/types/PhantasmaKeys.d.ts.map +1 -0
- package/core/types/PhantasmaKeys.js +92 -0
- package/core/types/Serialization.d.ts +22 -0
- package/core/types/Serialization.d.ts.map +1 -0
- package/core/types/Serialization.js +195 -0
- package/core/types/Stack.d.ts +16 -0
- package/core/types/Stack.d.ts.map +1 -0
- package/core/types/Stack.js +42 -0
- package/core/types/Timestamp.d.ts +26 -0
- package/core/types/Timestamp.d.ts.map +1 -0
- package/core/types/Timestamp.js +74 -0
- package/core/types/index.d.ts +12 -0
- package/core/types/index.d.ts.map +1 -0
- package/core/types/index.js +27 -0
- package/core/utils/index.d.ts +25 -0
- package/core/utils/index.d.ts.map +1 -0
- package/core/utils/index.js +236 -0
- package/core/vm/Contracts.d.ts +17 -0
- package/core/vm/Contracts.d.ts.map +1 -0
- package/core/vm/Contracts.js +20 -0
- package/core/vm/Decoder.d.ts +19 -0
- package/core/vm/Decoder.d.ts.map +1 -0
- package/core/vm/Decoder.js +175 -0
- package/core/vm/EventData.d.ts +97 -0
- package/core/vm/EventData.d.ts.map +1 -0
- package/core/vm/EventData.js +134 -0
- package/core/vm/Opcode.d.ts +57 -0
- package/core/vm/Opcode.d.ts.map +1 -0
- package/core/vm/Opcode.js +69 -0
- package/core/vm/ScriptBuilder.d.ts +65 -0
- package/core/vm/ScriptBuilder.d.ts.map +1 -0
- package/core/vm/ScriptBuilder.js +592 -0
- package/core/vm/VMObject.d.ts +55 -0
- package/core/vm/VMObject.d.ts.map +1 -0
- package/core/vm/VMObject.js +1101 -0
- package/core/vm/VMType.d.ts +12 -0
- package/core/vm/VMType.d.ts.map +1 -0
- package/core/vm/VMType.js +15 -0
- package/core/vm/index.d.ts +8 -0
- package/core/vm/index.d.ts.map +1 -0
- package/core/vm/index.js +23 -0
- package/html/TestWebPage.html +187 -0
- package/html/phantasma.js +60504 -0
- package/index.d.ts +5 -0
- package/index.d.ts.map +1 -0
- package/index.js +36 -0
- package/jest.config.js +5 -0
- package/package.json +67 -0
- package/src/core/index.ts +9 -0
- package/src/core/interfaces/IContract.ts +28 -0
- package/src/core/interfaces/IKeyPair.ts +14 -0
- package/src/core/interfaces/ISerializable.ts +6 -0
- package/src/core/interfaces/IStack.ts +6 -0
- package/src/core/interfaces/IToken.ts +31 -0
- package/src/core/interfaces/Signature.ts +32 -0
- package/src/core/interfaces/index.ts +6 -0
- package/src/core/ledger/Address-Transcode.ts +44 -0
- package/src/core/ledger/Ledger-Commands.ts +463 -0
- package/src/core/ledger/Ledger-Utils.ts +549 -0
- package/src/core/ledger/Mnemonic.ts +79 -0
- package/src/core/ledger/Transaction-Sign.ts +126 -0
- package/src/core/ledger/Transaction-Transcode.ts +56 -0
- package/src/core/ledger/index.ts +8 -0
- package/src/core/ledger/interfaces/ApplicationNameResponse.ts +5 -0
- package/src/core/ledger/interfaces/Device.ts +6 -0
- package/src/core/ledger/interfaces/DeviceResponse.ts +6 -0
- package/src/core/ledger/interfaces/Ledger.ts +10 -0
- package/src/core/ledger/interfaces/LedgerBalanceFromLedgerResponse.ts +9 -0
- package/src/core/ledger/interfaces/LedgerConfig.ts +17 -0
- package/src/core/ledger/interfaces/LedgerDeviceInfoResponse.ts +7 -0
- package/src/core/ledger/interfaces/LedgerSendTransactionResponse.ts +4 -0
- package/src/core/ledger/interfaces/LedgerSigner.ts +6 -0
- package/src/core/ledger/interfaces/LedgerSignerData.ts +8 -0
- package/src/core/ledger/interfaces/PublicKeyResponse.ts +5 -0
- package/src/core/ledger/interfaces/SignResponse.ts +5 -0
- package/src/core/ledger/interfaces/VersionResponse.ts +5 -0
- package/src/core/ledger/interfaces/index.ts +13 -0
- package/src/core/link/easyConnect.ts +214 -0
- package/src/core/link/easyScript.ts +67 -0
- package/src/core/link/index.ts +1 -0
- package/src/core/link/interfaces/IAccount.ts +13 -0
- package/src/core/link/interfaces/IFile.ts +6 -0
- package/src/core/link/interfaces/ProofOfWork.ts +8 -0
- package/src/core/link/interfaces/index.ts +3 -0
- package/src/core/link/phantasmaLink.ts +561 -0
- package/src/core/rpc/index.ts +2 -0
- package/src/core/rpc/interfaces/ABIContract.ts +6 -0
- package/src/core/rpc/interfaces/ABIEvent.ts +6 -0
- package/src/core/rpc/interfaces/ABIMethod.ts +7 -0
- package/src/core/rpc/interfaces/ABIParameter.ts +4 -0
- package/src/core/rpc/interfaces/Account.ts +16 -0
- package/src/core/rpc/interfaces/AccountTransactions.ts +6 -0
- package/src/core/rpc/interfaces/Archive.ts +10 -0
- package/src/core/rpc/interfaces/Auction.ts +12 -0
- package/src/core/rpc/interfaces/Balance.ts +7 -0
- package/src/core/rpc/interfaces/Block.ts +17 -0
- package/src/core/rpc/interfaces/Chain.ts +9 -0
- package/src/core/rpc/interfaces/Channel.ts +12 -0
- package/src/core/rpc/interfaces/Contract.ts +11 -0
- package/src/core/rpc/interfaces/Dapp.ts +5 -0
- package/src/core/rpc/interfaces/Event.ts +6 -0
- package/src/core/rpc/interfaces/Governance.ts +4 -0
- package/src/core/rpc/interfaces/Interop.ts +4 -0
- package/src/core/rpc/interfaces/KeyValue.ts +4 -0
- package/src/core/rpc/interfaces/Leaderboard.ts +6 -0
- package/src/core/rpc/interfaces/LeaderboardRow.ts +4 -0
- package/src/core/rpc/interfaces/NFT.ts +14 -0
- package/src/core/rpc/interfaces/Nexus.ts +14 -0
- package/src/core/rpc/interfaces/Oracle.ts +4 -0
- package/src/core/rpc/interfaces/Organization.ts +5 -0
- package/src/core/rpc/interfaces/Paginated.ts +7 -0
- package/src/core/rpc/interfaces/Peer.ts +7 -0
- package/src/core/rpc/interfaces/Platform.ts +9 -0
- package/src/core/rpc/interfaces/Receipt.ts +9 -0
- package/src/core/rpc/interfaces/Script.ts +9 -0
- package/src/core/rpc/interfaces/SendRawTx.ts +4 -0
- package/src/core/rpc/interfaces/SignatureResult.ts +4 -0
- package/src/core/rpc/interfaces/Stake.ts +5 -0
- package/src/core/rpc/interfaces/Storage.ts +8 -0
- package/src/core/rpc/interfaces/Swap.ts +12 -0
- package/src/core/rpc/interfaces/Token.ts +19 -0
- package/src/core/rpc/interfaces/TokenData.ts +12 -0
- package/src/core/rpc/interfaces/TokenExternal.ts +4 -0
- package/src/core/rpc/interfaces/TokenPrice.ts +7 -0
- package/src/core/rpc/interfaces/TokenSeries.ts +12 -0
- package/src/core/rpc/interfaces/TransactionData.ts +23 -0
- package/src/core/rpc/interfaces/Validator.ts +4 -0
- package/src/core/rpc/interfaces/index.ts +41 -0
- package/src/core/rpc/phantasma.ts +466 -0
- package/src/core/tx/Transaction.ts +258 -0
- package/src/core/tx/index.ts +2 -0
- package/src/core/tx/utils.ts +106 -0
- package/src/core/types/Address.ts +290 -0
- package/src/core/types/Consensus.ts +181 -0
- package/src/core/types/Contract.ts +324 -0
- package/src/core/types/DomainSettings.ts +128 -0
- package/src/core/types/Ed25519Signature.ts +78 -0
- package/src/core/types/Entropy.ts +16 -0
- package/src/core/types/Extensions/Base16.ts +36 -0
- package/src/core/types/Extensions/Describer.ts +17 -0
- package/src/core/types/Extensions/PBinaryReader.ts +247 -0
- package/src/core/types/Extensions/PBinaryWriter.ts +278 -0
- package/src/core/types/Extensions/index.ts +4 -0
- package/src/core/types/PhantasmaKeys.ts +119 -0
- package/src/core/types/Serialization.ts +211 -0
- package/src/core/types/Stack.ts +46 -0
- package/src/core/types/Timestamp.ts +93 -0
- package/src/core/types/index.ts +11 -0
- package/src/core/utils/index.ts +206 -0
- package/src/core/vm/Contracts.ts +17 -0
- package/src/core/vm/Decoder.ts +162 -0
- package/src/core/vm/Disassembler.ts +1 -0
- package/src/core/vm/EventData.ts +135 -0
- package/src/core/vm/Opcode.ts +74 -0
- package/src/core/vm/ScriptBuilder.ts +588 -0
- package/src/core/vm/VMObject.ts +1162 -0
- package/src/core/vm/VMType.ts +11 -0
- package/src/core/vm/index.ts +7 -0
- package/src/core/vm/utils/DisasmMethodCall.ts +22 -0
- package/src/core/vm/utils/DisasmUtils.ts +89 -0
- package/src/core/vm/utils/index.ts +2 -0
- package/src/index.ts +7 -0
- package/tests/VMObject.test.ts +146 -0
- package/tests/ledger/Address-Transacode.test.ts +26 -0
- package/tests/tx/Transaction.test.ts +274 -0
- package/tests/types/Address.test.ts +26 -0
- package/tests/types/Consensus.test.ts +67 -0
- package/tsconfig.json +29 -0
|
@@ -0,0 +1,463 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GetPrivateKeyFromMnemonic,
|
|
3
|
+
LedgerSendTransactionResponse,
|
|
4
|
+
LedgerSignerData,
|
|
5
|
+
PublicKeyResponse,
|
|
6
|
+
Signature,
|
|
7
|
+
} from '..';
|
|
8
|
+
import { Transaction } from '../tx';
|
|
9
|
+
import { Address, Base16, Ed25519Signature, PBinaryReader } from '../types';
|
|
10
|
+
import { GetAddressFromPublicKey, GetAddressPublicKeyFromPublicKey } from './Address-Transcode';
|
|
11
|
+
import { LedgerConfig } from './interfaces/LedgerConfig';
|
|
12
|
+
import { GetPublicFromPrivate, Sign, Verify } from './Transaction-Sign';
|
|
13
|
+
import { GetExpirationDate } from './Transaction-Transcode';
|
|
14
|
+
import { GetVersion, GetApplicationName, GetPublicKey, SignLedger } from './Ledger-Utils';
|
|
15
|
+
import { LedgerDeviceInfoResponse } from './interfaces/LedgerDeviceInfoResponse';
|
|
16
|
+
import { LedgerBalanceFromLedgerResponse } from './interfaces/LedgerBalanceFromLedgerResponse';
|
|
17
|
+
import { LedgerSigner } from './interfaces/LedgerSigner';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @param number
|
|
22
|
+
* @param length
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
export const LeftPad = (number, length): string => {
|
|
26
|
+
let str = '' + number;
|
|
27
|
+
while (str.length < length) {
|
|
28
|
+
str = '0' + str;
|
|
29
|
+
}
|
|
30
|
+
return str;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* @param balance
|
|
36
|
+
* @param decimals
|
|
37
|
+
* @returns
|
|
38
|
+
*/
|
|
39
|
+
export const ToWholeNumber = (balance, decimals): string => {
|
|
40
|
+
if (balance === undefined) {
|
|
41
|
+
throw Error('balance is a required parameter.');
|
|
42
|
+
}
|
|
43
|
+
if (decimals === undefined) {
|
|
44
|
+
throw Error('decimals is a required parameter.');
|
|
45
|
+
}
|
|
46
|
+
// console.log('toWholeNumber', 'balance', balance);
|
|
47
|
+
const paddedBalance = LeftPad(balance, decimals + 1);
|
|
48
|
+
// console.log('toWholeNumber', 'paddedBalance', paddedBalance);
|
|
49
|
+
const prefixLength = paddedBalance.length - decimals;
|
|
50
|
+
// console.log('toWholeNumber', 'prefixLength', prefixLength);
|
|
51
|
+
const prefix = paddedBalance.slice(0, prefixLength);
|
|
52
|
+
// console.log('toWholeNumber', 'prefix', prefix);
|
|
53
|
+
const suffix = paddedBalance.slice(-decimals);
|
|
54
|
+
// console.log('toWholeNumber', 'suffix', suffix);
|
|
55
|
+
return `${prefix}.${suffix}`;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Get the device info from the ledger.
|
|
60
|
+
* @param config
|
|
61
|
+
* @returns
|
|
62
|
+
*/
|
|
63
|
+
export const GetLedgerDeviceInfo = async (
|
|
64
|
+
config: LedgerConfig
|
|
65
|
+
): Promise<LedgerDeviceInfoResponse> => {
|
|
66
|
+
if (config == undefined) {
|
|
67
|
+
throw Error('config is a required parameter.');
|
|
68
|
+
}
|
|
69
|
+
const version = await GetVersion(config.Transport);
|
|
70
|
+
const applicationName = await GetApplicationName(config.Transport);
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
version: version,
|
|
74
|
+
applicationName: applicationName,
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Get Ledger Account Signer
|
|
80
|
+
* @param config
|
|
81
|
+
* @param accountIx
|
|
82
|
+
* @returns
|
|
83
|
+
*/
|
|
84
|
+
export const GetLedgerAccountSigner = async (
|
|
85
|
+
config: LedgerConfig,
|
|
86
|
+
accountIx
|
|
87
|
+
): Promise<LedgerSigner> => {
|
|
88
|
+
/* istanbul ignore if */
|
|
89
|
+
if (config === undefined) {
|
|
90
|
+
throw Error('config is a required parameter.');
|
|
91
|
+
}
|
|
92
|
+
/* istanbul ignore if */
|
|
93
|
+
if (accountIx === undefined) {
|
|
94
|
+
throw Error('accountIx is a required parameter.');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const paths = await config.Transport.list();
|
|
98
|
+
console.log('paths', paths);
|
|
99
|
+
if (paths.length == 0) {
|
|
100
|
+
alert('NUmber of devices found:' + paths.length);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const accountData = await GetLedgerSignerData(config, {
|
|
104
|
+
verifyOnDevice: false,
|
|
105
|
+
debug: true,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
let signer: LedgerSigner = {
|
|
109
|
+
GetPublicKey: () => {
|
|
110
|
+
return accountData.publicKey;
|
|
111
|
+
},
|
|
112
|
+
GetAccount: () => {
|
|
113
|
+
return accountData.address;
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
return signer;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* GetLedgerSignerData
|
|
121
|
+
* @param config
|
|
122
|
+
* @param options
|
|
123
|
+
* @returns
|
|
124
|
+
*/
|
|
125
|
+
export async function GetLedgerSignerData(
|
|
126
|
+
config: LedgerConfig,
|
|
127
|
+
options
|
|
128
|
+
): Promise<LedgerSignerData> {
|
|
129
|
+
if (config == undefined) {
|
|
130
|
+
throw Error('config is a required parameter.');
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (options == undefined) {
|
|
134
|
+
throw Error('options is a required parameter.');
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const msg = await GetPublicKey(config.Transport, options);
|
|
138
|
+
let response: LedgerSignerData = {
|
|
139
|
+
address: Address.Null,
|
|
140
|
+
publicKey: '',
|
|
141
|
+
success: false,
|
|
142
|
+
message: '',
|
|
143
|
+
};
|
|
144
|
+
response.success = false;
|
|
145
|
+
response.message = msg.message;
|
|
146
|
+
|
|
147
|
+
if (!msg.success) {
|
|
148
|
+
return response;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const publicKey = msg.publicKey;
|
|
152
|
+
const address = GetAddressPublicKeyFromPublicKey(publicKey!);
|
|
153
|
+
response.success = true;
|
|
154
|
+
response.message = 'success';
|
|
155
|
+
response.address = address;
|
|
156
|
+
response.publicKey = publicKey;
|
|
157
|
+
return response;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* GetBalanceFromLedger
|
|
162
|
+
* @param config
|
|
163
|
+
* @param options
|
|
164
|
+
* @returns
|
|
165
|
+
*/
|
|
166
|
+
export const GetBalanceFromLedger = async (
|
|
167
|
+
config: LedgerConfig,
|
|
168
|
+
options
|
|
169
|
+
): Promise<LedgerBalanceFromLedgerResponse> => {
|
|
170
|
+
/* istanbul ignore if */
|
|
171
|
+
if (config == undefined) {
|
|
172
|
+
throw Error('config is a required parameter.');
|
|
173
|
+
}
|
|
174
|
+
/* istanbul ignore if */
|
|
175
|
+
if (options == undefined) {
|
|
176
|
+
throw Error('options is a required parameter.');
|
|
177
|
+
}
|
|
178
|
+
const msg = await GetPublicKey(config.Transport, options);
|
|
179
|
+
/* istanbul ignore if */
|
|
180
|
+
if (config.Debug) {
|
|
181
|
+
console.log('getBalanceFromLedger', 'msg', msg);
|
|
182
|
+
}
|
|
183
|
+
let response: LedgerBalanceFromLedgerResponse = {
|
|
184
|
+
address: Address.Null,
|
|
185
|
+
publicKey: '',
|
|
186
|
+
balances: new Map<string, { amount: number; decimals: number }>(),
|
|
187
|
+
success: false,
|
|
188
|
+
message: '',
|
|
189
|
+
};
|
|
190
|
+
response.message = msg.message;
|
|
191
|
+
|
|
192
|
+
if (!msg.success) {
|
|
193
|
+
return response;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const publicKey = msg.publicKey;
|
|
197
|
+
const address = GetAddressPublicKeyFromPublicKey(publicKey!);
|
|
198
|
+
/* istanbul ignore if */
|
|
199
|
+
if (config.Debug) {
|
|
200
|
+
console.log('address', address);
|
|
201
|
+
console.log('rpc', config.RPC);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
console.log('rpcAwait', await config.RPC.getAccount(address.Text));
|
|
205
|
+
const rpcResponse = await config.RPC.getAccount(address.Text);
|
|
206
|
+
if (config.Debug) {
|
|
207
|
+
console.log('rpcResponse', rpcResponse);
|
|
208
|
+
}
|
|
209
|
+
response.balances = new Map<string, { amount: number; decimals: number }>();
|
|
210
|
+
if (rpcResponse.balances !== undefined) {
|
|
211
|
+
rpcResponse.balances.forEach((balanceElt) => {
|
|
212
|
+
response.balances[balanceElt.symbol] = ToWholeNumber(balanceElt.amount, balanceElt.decimals);
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
response.address = address;
|
|
216
|
+
response.publicKey = publicKey;
|
|
217
|
+
response.success = true;
|
|
218
|
+
return response;
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Get Addres from Ledger
|
|
223
|
+
* @param config
|
|
224
|
+
* @param options
|
|
225
|
+
* @returns
|
|
226
|
+
*/
|
|
227
|
+
export const GetAddressFromLedeger = async (
|
|
228
|
+
config: LedgerConfig,
|
|
229
|
+
options
|
|
230
|
+
): Promise<string | PublicKeyResponse> => {
|
|
231
|
+
/* istanbul ignore if */
|
|
232
|
+
if (config == undefined) {
|
|
233
|
+
throw Error('config is a required parameter.');
|
|
234
|
+
}
|
|
235
|
+
/* istanbul ignore if */
|
|
236
|
+
if (options == undefined) {
|
|
237
|
+
throw Error('options is a required parameter.');
|
|
238
|
+
}
|
|
239
|
+
const msg = await GetPublicKey(config.Transport, options);
|
|
240
|
+
/* istanbul ignore if */
|
|
241
|
+
if (config.Debug) {
|
|
242
|
+
console.log('getBalanceFromLedger', 'msg', msg);
|
|
243
|
+
}
|
|
244
|
+
if (msg.success) {
|
|
245
|
+
const publicKey = msg.publicKey!;
|
|
246
|
+
const address = GetAddressFromPublicKey(publicKey);
|
|
247
|
+
return address;
|
|
248
|
+
} else {
|
|
249
|
+
return msg;
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
*
|
|
255
|
+
* @param encodedTx
|
|
256
|
+
* @param config
|
|
257
|
+
* @returns
|
|
258
|
+
*/
|
|
259
|
+
async function SignEncodedTx(encodedTx: string, config: LedgerConfig): Promise<string> {
|
|
260
|
+
const response = await SignLedger(config.Transport, encodedTx);
|
|
261
|
+
/* istanbul ignore if */
|
|
262
|
+
if (config.Debug) {
|
|
263
|
+
console.log('sendAmountUsingLedger', 'signCallback', 'response', response);
|
|
264
|
+
}
|
|
265
|
+
if (response.success) {
|
|
266
|
+
return response.signature;
|
|
267
|
+
} else {
|
|
268
|
+
throw Error(response.message);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* SendTransactionLedger
|
|
274
|
+
* @param config
|
|
275
|
+
* @param script
|
|
276
|
+
* @returns
|
|
277
|
+
*/
|
|
278
|
+
export async function SendTransactionLedger(
|
|
279
|
+
config: LedgerConfig,
|
|
280
|
+
script: string
|
|
281
|
+
): Promise<LedgerSendTransactionResponse> {
|
|
282
|
+
if (config == undefined) {
|
|
283
|
+
throw Error('config is a required parameter.');
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const options = { verifyOnDevice: false };
|
|
287
|
+
const msg_publicKey = await GetPublicKey(config.Transport, options);
|
|
288
|
+
if (!msg_publicKey.success) {
|
|
289
|
+
if (config.Debug) {
|
|
290
|
+
console.log('SendTransactionLedger', 'error ', msg_publicKey);
|
|
291
|
+
}
|
|
292
|
+
return msg_publicKey;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const addr = GetAddressPublicKeyFromPublicKey(msg_publicKey.publicKey!);
|
|
296
|
+
const publicKey = msg_publicKey.publicKey!;
|
|
297
|
+
|
|
298
|
+
const nexusName = config.NexusName;
|
|
299
|
+
const chainName = config.ChainName;
|
|
300
|
+
const gasPrice = config.GasPrice;
|
|
301
|
+
const gasLimit = config.GasLimit;
|
|
302
|
+
|
|
303
|
+
const expirationDate = GetExpirationDate();
|
|
304
|
+
|
|
305
|
+
// no payload, could be a message.
|
|
306
|
+
const payload = config.Payload;
|
|
307
|
+
|
|
308
|
+
const myTransaction = new Transaction(
|
|
309
|
+
nexusName, // Nexus Name
|
|
310
|
+
chainName, // Chain
|
|
311
|
+
script, // In string format
|
|
312
|
+
expirationDate, // Expiration Date
|
|
313
|
+
payload
|
|
314
|
+
); // Extra Info to attach to Transaction in Serialized Hex
|
|
315
|
+
|
|
316
|
+
const encodedTx = Base16.encodeUint8Array(myTransaction.ToByteAray(false));
|
|
317
|
+
|
|
318
|
+
try {
|
|
319
|
+
if (config.Debug) {
|
|
320
|
+
console.log('sendAmountUsingCallback', 'encodedTx', encodedTx);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const signature = await SignEncodedTx(encodedTx, config);
|
|
324
|
+
|
|
325
|
+
if (config.Debug) {
|
|
326
|
+
console.log('sendAmountUsingCallback', 'signature', signature);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
if (config.VerifyResponse) {
|
|
330
|
+
const verifyResponse = Verify(encodedTx, signature!, publicKey);
|
|
331
|
+
if (verifyResponse == false) {
|
|
332
|
+
throw Error(
|
|
333
|
+
`invalidSignature encodedTx:'${encodedTx}', publicKey:'${publicKey}' signature:'${signature}'`
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
if (config.Debug) {
|
|
338
|
+
console.log('verifyResponse', verifyResponse);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
let signatureBytes = Base16.decodeUint8Array(signature!);
|
|
343
|
+
let mySignature = new Ed25519Signature(signatureBytes);
|
|
344
|
+
let myNewSignaturesArray: Signature[] = [];
|
|
345
|
+
myNewSignaturesArray.push(mySignature);
|
|
346
|
+
myTransaction.signatures = myNewSignaturesArray;
|
|
347
|
+
|
|
348
|
+
if (config.Debug) {
|
|
349
|
+
console.log('signedTx', myTransaction);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
const encodedSignedTx = Base16.encodeUint8Array(myTransaction.ToByteAray(true));
|
|
353
|
+
console.log('encoded signed tx: ', encodedSignedTx);
|
|
354
|
+
|
|
355
|
+
const txHash = await config.RPC.sendRawTransaction(encodedSignedTx);
|
|
356
|
+
if (config.Debug) {
|
|
357
|
+
console.log('sendAmountUsingCallback', 'txHash', txHash);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
const response: LedgerSendTransactionResponse = {
|
|
361
|
+
success: true,
|
|
362
|
+
message: txHash,
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
/* istanbul ignore if */
|
|
366
|
+
if (config.Debug) {
|
|
367
|
+
console.log('response', response);
|
|
368
|
+
}
|
|
369
|
+
return response;
|
|
370
|
+
} catch (error) {
|
|
371
|
+
if (config.Debug) {
|
|
372
|
+
console.log('error', error);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
const errorResponse: LedgerSendTransactionResponse = {
|
|
376
|
+
success: false,
|
|
377
|
+
message: error.message,
|
|
378
|
+
};
|
|
379
|
+
return errorResponse;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
*
|
|
385
|
+
* @param config
|
|
386
|
+
* @param privateKey
|
|
387
|
+
* @returns
|
|
388
|
+
*/
|
|
389
|
+
export const GetBalanceFromPrivateKey = async (
|
|
390
|
+
config,
|
|
391
|
+
privateKey
|
|
392
|
+
): Promise<LedgerBalanceFromLedgerResponse> => {
|
|
393
|
+
/* istanbul ignore if */
|
|
394
|
+
if (config == undefined) {
|
|
395
|
+
throw Error('config is a required parameter.');
|
|
396
|
+
}
|
|
397
|
+
/* istanbul ignore if */
|
|
398
|
+
if (privateKey == undefined) {
|
|
399
|
+
throw Error('privateKey is a required parameter.');
|
|
400
|
+
}
|
|
401
|
+
/* istanbul ignore if */
|
|
402
|
+
if (config.Debug) {
|
|
403
|
+
console.log('privateKey', privateKey);
|
|
404
|
+
}
|
|
405
|
+
// https://github.com/phantasma-io/phantasma-ts/blob/7d04aaed839851ae5640f68ab223ca7d92c42016/core/tx/utils.js
|
|
406
|
+
const publicKey = GetPublicFromPrivate(privateKey);
|
|
407
|
+
/* istanbul ignore if */
|
|
408
|
+
if (config.Debug) {
|
|
409
|
+
console.log('publicKey', publicKey);
|
|
410
|
+
}
|
|
411
|
+
const address = GetAddressFromPublicKey(publicKey);
|
|
412
|
+
/* istanbul ignore if */
|
|
413
|
+
if (config.Debug) {
|
|
414
|
+
console.log('address', address);
|
|
415
|
+
}
|
|
416
|
+
// const path = `/address/${address}`;
|
|
417
|
+
// const response = await httpRequestUtil.get(config, path);
|
|
418
|
+
const rpcResponse = await config.RPC.getAccount(address);
|
|
419
|
+
if (config.Debug) {
|
|
420
|
+
console.log('rpcResponse', rpcResponse);
|
|
421
|
+
}
|
|
422
|
+
let response: LedgerBalanceFromLedgerResponse;
|
|
423
|
+
response.balances = new Map<string, { amount: number; decimals: number }>();
|
|
424
|
+
if (rpcResponse.balances !== undefined) {
|
|
425
|
+
rpcResponse.balances.forEach((balanceElt) => {
|
|
426
|
+
response.balances[balanceElt.symbol] = ToWholeNumber(balanceElt.amount, balanceElt.decimals);
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
response.address = Address.FromText(address);
|
|
430
|
+
response.success = true;
|
|
431
|
+
// const lastRefPath = `/transaction/last-ref/${address}`;
|
|
432
|
+
// const lastRefResponse = await httpRequestUtil.get(config, lastRefPath);
|
|
433
|
+
// response.lastRef = lastRefResponse;
|
|
434
|
+
return response;
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
*
|
|
439
|
+
* @param config
|
|
440
|
+
* @param mnemonic
|
|
441
|
+
* @param index
|
|
442
|
+
* @returns
|
|
443
|
+
*/
|
|
444
|
+
export const GetBalanceFromMnemonic = async (config: LedgerConfig, mnemonic: string, index) => {
|
|
445
|
+
/* istanbul ignore if */
|
|
446
|
+
if (config == undefined) {
|
|
447
|
+
throw Error('config is a required parameter.');
|
|
448
|
+
}
|
|
449
|
+
/* istanbul ignore if */
|
|
450
|
+
if (mnemonic == undefined) {
|
|
451
|
+
throw Error('mnemonic is a required parameter.');
|
|
452
|
+
}
|
|
453
|
+
/* istanbul ignore if */
|
|
454
|
+
if (index == undefined) {
|
|
455
|
+
throw Error('index is a required parameter.');
|
|
456
|
+
}
|
|
457
|
+
/* istanbul ignore if */
|
|
458
|
+
if (config.Debug) {
|
|
459
|
+
console.log('mnemonic', mnemonic);
|
|
460
|
+
}
|
|
461
|
+
const privateKey = GetPrivateKeyFromMnemonic(config, mnemonic, index);
|
|
462
|
+
return await GetBalanceFromPrivateKey(config, privateKey);
|
|
463
|
+
};
|