├── .gitignore ├── LICENSE ├── README.md ├── SECURITY.md ├── build.sh ├── docs ├── .nojekyll ├── README.md ├── _coverpage.md ├── _sidebar.md ├── coins │ ├── aptos.md │ ├── base.md │ ├── bitcoin.md │ ├── bitcoin │ │ ├── atomical.md │ │ ├── images │ │ │ ├── rune_batch_mint.png │ │ │ └── rune_serial_mint.png │ │ ├── pbst.md │ │ └── rune.md │ ├── cardano.md │ ├── cosmos.md │ ├── eos.md │ ├── ethereum.md │ ├── flow.md │ ├── kaspa.md │ ├── near.md │ ├── nostrassets.md │ ├── polkadot.md │ ├── solana.md │ ├── stacks.md │ ├── starknet.md │ ├── sui.md │ ├── ton.md │ ├── tron.md │ └── zkspace.md ├── index.html ├── media │ └── logo.png └── start.sh ├── document └── SignMessage.md ├── examples ├── .gitignore ├── README.md ├── config-overrides.js ├── package.json ├── public │ └── index.html ├── src │ ├── App.tsx │ ├── components │ │ ├── AddressOutput.tsx │ │ ├── Box100.tsx │ │ ├── BtcPrivateKey.tsx │ │ ├── BtcSignTx.tsx │ │ ├── DynamicForm.tsx │ │ ├── EvmPrivateKey.tsx │ │ ├── EvmSignEIP1559TokenTx.tsx │ │ ├── EvmSignEIP1559Tx.tsx │ │ ├── EvmSignLegacyTokenTx.tsx │ │ ├── EvmSignLegacyTx.tsx │ │ ├── EvmSignMessage.tsx │ │ ├── EvmSignTypedMessage.tsx │ │ ├── FormCheckbox.tsx │ │ ├── FormInput.tsx │ │ ├── FormTextarea.tsx │ │ ├── Header.tsx │ │ ├── SignedOutput.tsx │ │ ├── TonPrivateKey.tsx │ │ ├── TonSignJettonTx.tsx │ │ ├── TonSignTx.tsx │ │ ├── toast.tsx │ │ └── types.tsx │ ├── index.tsx │ └── pages │ │ ├── Btc.tsx │ │ ├── Evm.tsx │ │ ├── Home.tsx │ │ └── Ton.tsx └── tsconfig.json ├── package-lock.json ├── package.json ├── packages ├── coin-aptos │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── jest.config.js │ ├── package.json │ ├── src │ │ ├── AptosWallet.ts │ │ ├── aptos_account.ts │ │ ├── client.ts │ │ ├── generated │ │ │ ├── index.ts │ │ │ └── models │ │ │ │ └── HexEncodedBytes.ts │ │ ├── hex_string.ts │ │ ├── index.ts │ │ ├── transaction_builder │ │ │ ├── aptos_types │ │ │ │ ├── abi.ts │ │ │ │ ├── account_address.ts │ │ │ │ ├── authentication_key.ts │ │ │ │ ├── authenticator.ts │ │ │ │ ├── ed25519.ts │ │ │ │ ├── identifier.ts │ │ │ │ ├── index.ts │ │ │ │ ├── multi_ed25519.ts │ │ │ │ ├── transaction.ts │ │ │ │ └── type_tag.ts │ │ │ ├── bcs │ │ │ │ ├── consts.ts │ │ │ │ ├── deserializer.ts │ │ │ │ ├── helper.ts │ │ │ │ ├── index.ts │ │ │ │ ├── serializer.ts │ │ │ │ └── types.ts │ │ │ ├── builder.ts │ │ │ ├── builder_utils.ts │ │ │ ├── index.ts │ │ │ └── move_types.ts │ │ ├── utils │ │ │ ├── hd_key.ts │ │ │ ├── index.ts │ │ │ ├── memoize_decorator.ts │ │ │ └── misc.ts │ │ └── v2 │ │ │ ├── LICENSE │ │ │ ├── account │ │ │ ├── Account.ts │ │ │ ├── Ed25519Account.ts │ │ │ ├── MultiKeyAccount.ts │ │ │ ├── SingleKeyAccount.ts │ │ │ └── index.ts │ │ │ ├── api │ │ │ ├── aptosConfig.ts │ │ │ ├── fungibleAsset.ts │ │ │ ├── index.ts │ │ │ ├── transaction.ts │ │ │ └── transactionSubmission │ │ │ │ ├── build.ts │ │ │ │ ├── helpers.ts │ │ │ │ ├── sign.ts │ │ │ │ ├── simulate.ts │ │ │ │ └── submit.ts │ │ │ ├── bcs │ │ │ ├── consts.ts │ │ │ ├── deserializer.ts │ │ │ ├── index.ts │ │ │ ├── serializable │ │ │ │ ├── entryFunctionBytes.ts │ │ │ │ ├── fixedBytes.ts │ │ │ │ ├── movePrimitives.ts │ │ │ │ └── moveStructs.ts │ │ │ └── serializer.ts │ │ │ ├── core │ │ │ ├── account │ │ │ │ ├── index.ts │ │ │ │ └── utils │ │ │ │ │ ├── address.ts │ │ │ │ │ └── index.ts │ │ │ ├── accountAddress.ts │ │ │ ├── authenticationKey.ts │ │ │ ├── common.ts │ │ │ ├── crypto │ │ │ │ ├── ed25519.ts │ │ │ │ ├── hdKey.ts │ │ │ │ ├── index.ts │ │ │ │ ├── multiEd25519.ts │ │ │ │ ├── multiKey.ts │ │ │ │ ├── privateKey.ts │ │ │ │ ├── publicKey.ts │ │ │ │ ├── secp256k1.ts │ │ │ │ ├── signature.ts │ │ │ │ ├── singleKey.ts │ │ │ │ └── utils.ts │ │ │ ├── hex.ts │ │ │ └── index.ts │ │ │ ├── index.ts │ │ │ ├── internal │ │ │ ├── coin.ts │ │ │ ├── fungibleAsset.ts │ │ │ └── transactionSubmission.ts │ │ │ ├── transactions │ │ │ ├── authenticator │ │ │ │ ├── account.ts │ │ │ │ ├── index.ts │ │ │ │ └── transaction.ts │ │ │ ├── index.ts │ │ │ ├── instances │ │ │ │ ├── chainId.ts │ │ │ │ ├── identifier.ts │ │ │ │ ├── index.ts │ │ │ │ ├── moduleId.ts │ │ │ │ ├── multiAgentTransaction.ts │ │ │ │ ├── rawTransaction.ts │ │ │ │ ├── rotationProofChallenge.ts │ │ │ │ ├── signedTransaction.ts │ │ │ │ ├── simpleTransaction.ts │ │ │ │ ├── transactionArgument.ts │ │ │ │ └── transactionPayload.ts │ │ │ ├── transactionBuilder │ │ │ │ ├── helpers.ts │ │ │ │ ├── index.ts │ │ │ │ ├── remoteAbi.ts │ │ │ │ ├── signingMessage.ts │ │ │ │ └── transactionBuilder.ts │ │ │ ├── typeTag │ │ │ │ ├── index.ts │ │ │ │ └── parser.ts │ │ │ └── types.ts │ │ │ ├── types │ │ │ ├── codegen.yaml │ │ │ ├── generated │ │ │ │ ├── operations.ts │ │ │ │ ├── queries.ts │ │ │ │ └── types.ts │ │ │ ├── index.ts │ │ │ └── indexer.ts │ │ │ ├── utils │ │ │ ├── apiEndpoints.ts │ │ │ ├── const.ts │ │ │ ├── helpers.ts │ │ │ ├── index.ts │ │ │ ├── memoize.ts │ │ │ └── normalizeBundle.ts │ │ │ └── version.ts │ ├── tests │ │ └── aptos.test.ts │ └── tsconfig.json ├── coin-base │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── jest.config.js │ ├── package.json │ ├── src │ │ ├── basic │ │ │ ├── index.ts │ │ │ └── typeUtils.ts │ │ ├── common.ts │ │ ├── currency.ts │ │ ├── error.ts │ │ ├── index.ts │ │ └── wallet.ts │ ├── tests │ │ └── wallet.test.ts │ └── tsconfig.json ├── coin-bitcoin │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── doc │ │ ├── atomical.md │ │ ├── images │ │ │ ├── rune_batch_mint.png │ │ │ └── rune_serial_mint.png │ │ └── rune.md │ ├── jest.config.js │ ├── package.json │ ├── src │ │ ├── bitcoincash │ │ │ ├── base32.ts │ │ │ ├── cashaddr.ts │ │ │ ├── convertBits.ts │ │ │ ├── index.ts │ │ │ └── validation.ts │ │ ├── bitcoinjs-lib │ │ │ ├── address.ts │ │ │ ├── bip0322.ts │ │ │ ├── bip174 │ │ │ │ ├── combiner │ │ │ │ │ └── index.ts │ │ │ │ ├── converter │ │ │ │ │ ├── global │ │ │ │ │ │ ├── globalXpub.ts │ │ │ │ │ │ └── unsignedTx.ts │ │ │ │ │ ├── index.ts │ │ │ │ │ ├── input │ │ │ │ │ │ ├── finalScriptSig.ts │ │ │ │ │ │ ├── finalScriptWitness.ts │ │ │ │ │ │ ├── nonWitnessUtxo.ts │ │ │ │ │ │ ├── partialSig.ts │ │ │ │ │ │ ├── porCommitment.ts │ │ │ │ │ │ ├── sighashType.ts │ │ │ │ │ │ ├── tapKeySig.ts │ │ │ │ │ │ ├── tapLeafScript.ts │ │ │ │ │ │ ├── tapMerkleRoot.ts │ │ │ │ │ │ ├── tapScriptSig.ts │ │ │ │ │ │ └── witnessUtxo.ts │ │ │ │ │ ├── output │ │ │ │ │ │ └── tapTree.ts │ │ │ │ │ ├── shared │ │ │ │ │ │ ├── bip32Derivation.ts │ │ │ │ │ │ ├── checkPubkey.ts │ │ │ │ │ │ ├── redeemScript.ts │ │ │ │ │ │ ├── tapBip32Derivation.ts │ │ │ │ │ │ ├── tapInternalKey.ts │ │ │ │ │ │ └── witnessScript.ts │ │ │ │ │ ├── tools.ts │ │ │ │ │ └── varint.ts │ │ │ │ ├── interfaces.ts │ │ │ │ ├── parser │ │ │ │ │ ├── fromBuffer.ts │ │ │ │ │ ├── index.ts │ │ │ │ │ └── toBuffer.ts │ │ │ │ ├── psbt.ts │ │ │ │ ├── typeFields.ts │ │ │ │ └── utils.ts │ │ │ ├── bip66.ts │ │ │ ├── bufferutils.ts │ │ │ ├── crypto.ts │ │ │ ├── index.ts │ │ │ ├── networks.ts │ │ │ ├── ops.ts │ │ │ ├── payments │ │ │ │ ├── bip341.ts │ │ │ │ ├── embed.ts │ │ │ │ ├── index.ts │ │ │ │ ├── lazy.ts │ │ │ │ ├── p2ms.ts │ │ │ │ ├── p2pk.ts │ │ │ │ ├── p2pkh.ts │ │ │ │ ├── p2sh.ts │ │ │ │ ├── p2tr.ts │ │ │ │ ├── p2wpkh.ts │ │ │ │ └── p2wsh.ts │ │ │ ├── psbt.ts │ │ │ ├── psbt │ │ │ │ ├── bip371.ts │ │ │ │ └── psbtutils.ts │ │ │ ├── push_data.ts │ │ │ ├── script.ts │ │ │ ├── script_number.ts │ │ │ ├── script_signature.ts │ │ │ ├── transaction.ts │ │ │ ├── types.ts │ │ │ ├── varuint.d.ts │ │ │ └── varuint.js │ │ ├── cat20 │ │ │ ├── common │ │ │ │ ├── btc.ts │ │ │ │ ├── cat20Enum.ts │ │ │ │ ├── common.ts │ │ │ │ ├── contract.ts │ │ │ │ ├── index.ts │ │ │ │ ├── metadata.ts │ │ │ │ └── minterFinder.ts │ │ │ ├── index.ts │ │ │ ├── transaction │ │ │ │ ├── functions.ts │ │ │ │ ├── index.ts │ │ │ │ ├── merge.ts │ │ │ │ └── transfer.ts │ │ │ └── utils │ │ │ │ ├── eckey.ts │ │ │ │ ├── index.ts │ │ │ │ ├── paramsUtils.ts │ │ │ │ ├── prevTx.ts │ │ │ │ ├── utils.ts │ │ │ │ └── utxo.ts │ │ ├── common.ts │ │ ├── doginals.ts │ │ ├── index.ts │ │ ├── inscribe.ts │ │ ├── inscribe_refund_fee.ts │ │ ├── message.ts │ │ ├── onekey.ts │ │ ├── psbtSign.ts │ │ ├── rune.ts │ │ ├── runesMain.ts │ │ ├── runestones.ts │ │ ├── sigcost.ts │ │ ├── src20.ts │ │ ├── taproot.ts │ │ ├── txBuild.ts │ │ ├── type.ts │ │ ├── wallet │ │ │ ├── AtomicalWallet.ts │ │ │ ├── BchWallet.ts │ │ │ ├── BsvWallet.ts │ │ │ ├── BtcWallet.ts │ │ │ ├── CatWallet.ts │ │ │ ├── DogeWallet.ts │ │ │ ├── LtcWallet.ts │ │ │ ├── RuneMainWallet.ts │ │ │ ├── RuneWallet.ts │ │ │ ├── UsdtWallet.ts │ │ │ └── index.ts │ │ └── wif.ts │ ├── tests │ │ ├── atomical.test.ts │ │ ├── brc20.test.ts │ │ ├── btc.test.ts │ │ ├── cat20.test.ts │ │ ├── doginals.test.ts │ │ ├── psbt.test.ts │ │ ├── rune.test.ts │ │ ├── runeMain.test.ts │ │ └── src20.test.ts │ └── tsconfig.json ├── coin-cardano │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── jest.config.js │ ├── package.json │ ├── src │ │ ├── AdaWallet.ts │ │ ├── account.ts │ │ ├── cardano-sdk │ │ │ ├── core │ │ │ │ └── Cardano │ │ │ │ │ ├── Address │ │ │ │ │ ├── Address.ts │ │ │ │ │ ├── BaseAddress.ts │ │ │ │ │ └── index.ts │ │ │ │ │ ├── ChainId.ts │ │ │ │ │ └── index.ts │ │ │ └── crypto │ │ │ │ └── Bip32 │ │ │ │ ├── Bip32KeyDerivation.ts │ │ │ │ ├── Bip32PrivateKey.ts │ │ │ │ ├── arithmetic.ts │ │ │ │ └── index.ts │ │ ├── index.ts │ │ ├── libs │ │ │ ├── cardano_message_signing │ │ │ │ ├── LICENSE │ │ │ │ ├── cardano_message_signing.generated.js │ │ │ │ └── cardano_message_signing_bg.wasm │ │ │ ├── cardano_multiplatform_lib │ │ │ │ ├── LICENSE │ │ │ │ ├── LICENSE-EMURGO │ │ │ │ ├── LICENSE-IOHK │ │ │ │ ├── cardano_multiplatform_lib.generated.js │ │ │ │ └── cardano_multiplatform_lib_bg.wasm │ │ │ └── loader.js │ │ └── transaction.ts │ ├── test │ │ └── cardano.test.ts │ └── tsconfig.json ├── coin-cosmos │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── jest.config.js │ ├── package.json │ ├── src │ │ ├── CosmosWallet.ts │ │ ├── amino │ │ │ ├── aminoRegistry.ts │ │ │ ├── aminotypes.ts │ │ │ ├── coins.ts │ │ │ ├── encoding.ts │ │ │ ├── pubkeys.ts │ │ │ └── signDoc.ts │ │ ├── binary.ts │ │ ├── cosmwasm │ │ │ ├── index.ts │ │ │ ├── registry.ts │ │ │ └── wasm │ │ │ │ └── v1 │ │ │ │ ├── tx.amino.ts │ │ │ │ ├── tx.ts │ │ │ │ └── types.ts │ │ ├── encoding.ts │ │ ├── helpers.ts │ │ ├── index.ts │ │ ├── kava │ │ │ ├── aminotypes.ts │ │ │ ├── auction │ │ │ │ └── v1beta1 │ │ │ │ │ ├── tx.amino.ts │ │ │ │ │ └── tx.ts │ │ │ ├── hard │ │ │ │ └── v1beta1 │ │ │ │ │ ├── tx.amino.ts │ │ │ │ │ └── tx.ts │ │ │ ├── index.ts │ │ │ ├── registry.ts │ │ │ └── swap │ │ │ │ └── v1beta1 │ │ │ │ ├── tx.amino.ts │ │ │ │ └── tx.ts │ │ ├── osmosis │ │ │ ├── aminotypes.ts │ │ │ ├── gamm │ │ │ │ └── v1beta1 │ │ │ │ │ ├── aminotypes.ts │ │ │ │ │ └── tx.ts │ │ │ ├── index.ts │ │ │ ├── lockup │ │ │ │ ├── lock.ts │ │ │ │ ├── tx.amino.ts │ │ │ │ └── tx.ts │ │ │ ├── poolmanager │ │ │ │ └── v1beta1 │ │ │ │ │ ├── swap_route.ts │ │ │ │ │ ├── tx.amino.ts │ │ │ │ │ └── tx.ts │ │ │ ├── registry.ts │ │ │ ├── superfluid │ │ │ │ ├── tx.amino.ts │ │ │ │ └── tx.ts │ │ │ └── tokenfactory │ │ │ │ └── v1beta1 │ │ │ │ ├── tx.amino.ts │ │ │ │ └── tx.ts │ │ ├── registry.ts │ │ ├── tx.ts │ │ ├── types.ts │ │ ├── types │ │ │ ├── cosmos │ │ │ │ ├── bank │ │ │ │ │ └── v1beta1 │ │ │ │ │ │ └── tx.ts │ │ │ │ ├── base │ │ │ │ │ └── v1beta1 │ │ │ │ │ │ └── coin.ts │ │ │ │ ├── crypto │ │ │ │ │ ├── ed25519 │ │ │ │ │ │ └── keys.ts │ │ │ │ │ ├── multisig │ │ │ │ │ │ ├── keys.ts │ │ │ │ │ │ └── v1beta1 │ │ │ │ │ │ │ └── multisig.ts │ │ │ │ │ └── secp256k1 │ │ │ │ │ │ └── keys.ts │ │ │ │ ├── staking │ │ │ │ │ └── v1beta1 │ │ │ │ │ │ └── tx.ts │ │ │ │ └── tx │ │ │ │ │ ├── signing │ │ │ │ │ └── v1beta1 │ │ │ │ │ │ └── signing.ts │ │ │ │ │ └── v1beta1 │ │ │ │ │ └── tx.ts │ │ │ ├── gogoproto │ │ │ │ └── gogo.ts │ │ │ ├── google │ │ │ │ ├── api │ │ │ │ │ ├── annotations.ts │ │ │ │ │ └── http.ts │ │ │ │ └── protobuf │ │ │ │ │ ├── any.ts │ │ │ │ │ ├── descriptor.ts │ │ │ │ │ ├── duration.ts │ │ │ │ │ └── timestamp.ts │ │ │ └── ibc │ │ │ │ └── applications │ │ │ │ └── transfer │ │ │ │ ├── v1 │ │ │ │ ├── transfer.ts │ │ │ │ └── tx.ts │ │ │ │ └── v2 │ │ │ │ └── packet.ts │ │ ├── typesV2 │ │ │ ├── cosmos │ │ │ │ ├── bank │ │ │ │ │ └── v1beta1 │ │ │ │ │ │ └── bank.ts │ │ │ │ └── base │ │ │ │ │ └── v1beta1 │ │ │ │ │ └── coin.ts │ │ │ └── google │ │ │ │ └── protobuf │ │ │ │ ├── any.ts │ │ │ │ ├── duration.ts │ │ │ │ └── timestamp.ts │ │ ├── utf8.ts │ │ ├── utils │ │ │ └── array.ts │ │ └── varint.ts │ ├── tests │ │ ├── luna.test.ts │ │ └── signmessage.test.ts │ └── tsconfig.json ├── coin-eos │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── jest.config.js │ ├── package.json │ ├── src │ │ ├── EosWallet.ts │ │ ├── action.ts │ │ ├── api.ts │ │ ├── index.ts │ │ ├── numeric.ts │ │ ├── serialize.ts │ │ ├── txBuilder.ts │ │ └── types.ts │ ├── tests │ │ ├── eos.test.ts │ │ └── wax.test.ts │ └── tsconfig.json ├── coin-ethereum │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── jest.config.js │ ├── package.json │ ├── src │ │ ├── EthWallet.ts │ │ ├── api.ts │ │ ├── index.ts │ │ ├── message.ts │ │ └── sdk │ │ │ ├── eth-sig-util │ │ │ ├── attribution.md │ │ │ ├── encryption.ts │ │ │ ├── index.ts │ │ │ ├── nacl-fast.js │ │ │ ├── nacl-util.js │ │ │ └── sign-typed-data.ts │ │ │ ├── ethereumjs-tx │ │ │ ├── baseTransaction.ts │ │ │ ├── eip1559Transaction.ts │ │ │ ├── eip2930Transaction.ts │ │ │ ├── eip7702Transaction.ts │ │ │ ├── index.ts │ │ │ ├── legacyTransaction.ts │ │ │ ├── transactionFactory.ts │ │ │ ├── types.ts │ │ │ └── util.ts │ │ │ ├── ethereumjs-util │ │ │ ├── account.ts │ │ │ ├── address.ts │ │ │ ├── bytes.ts │ │ │ ├── constants.ts │ │ │ ├── externals.d.ts │ │ │ ├── hash.ts │ │ │ ├── helpers.ts │ │ │ ├── index.ts │ │ │ ├── rlp.ts │ │ │ ├── signature.ts │ │ │ ├── types.ts │ │ │ └── util.ts │ │ │ └── index.ts │ ├── tests │ │ └── eth.test.ts │ └── tsconfig.json ├── coin-flow │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── jest.config.js │ ├── package.json │ ├── src │ │ ├── account.ts │ │ ├── enode.ts │ │ ├── http.ts │ │ ├── index.ts │ │ ├── model.ts │ │ ├── signature.ts │ │ └── tx.ts │ ├── tests │ │ └── flow.test.ts │ └── tsconfig.json ├── coin-kaia │ ├── CHANGELOG.md │ ├── README.md │ ├── babel.config.js │ ├── jest.config.js │ ├── package.json │ ├── src │ │ ├── KaiaWallet.ts │ │ ├── api.ts │ │ ├── index.ts │ │ └── v6 │ │ │ ├── accountStore.ts │ │ │ ├── index.ts │ │ │ ├── keystore.ts │ │ │ ├── signer.ts │ │ │ ├── txutil.ts │ │ │ └── types.ts │ ├── tests │ │ └── kaia.test.ts │ └── tsconfig.json ├── coin-kaspa │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── jest.config.js │ ├── package.json │ ├── src │ │ ├── KaspaWallet.ts │ │ ├── address.ts │ │ ├── index.ts │ │ ├── lib │ │ │ ├── address.ts │ │ │ ├── base32.ts │ │ │ ├── convertBits.ts │ │ │ └── validation.ts │ │ └── transaction.ts │ ├── tests │ │ └── kaspa.test.ts │ └── tsconfig.json ├── coin-near │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── jest.config.js │ ├── package.json │ ├── src │ │ ├── NearWallet.ts │ │ ├── enums.ts │ │ ├── index.ts │ │ ├── keypair.ts │ │ ├── nearlib.ts │ │ ├── serialize.ts │ │ └── transaction.ts │ ├── tests │ │ └── near.test.ts │ └── tsconfig.json ├── coin-nostrassets │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── jest.config.js │ ├── package.json │ ├── src │ │ ├── NostrAssetsWallet.ts │ │ ├── event.test.ts │ │ ├── event.ts │ │ ├── index.ts │ │ ├── keys.test.ts │ │ ├── keys.ts │ │ └── nostrassets.ts │ ├── tests │ │ └── nostrassetswallet.test.ts │ └── tsconfig.json ├── coin-polkadot │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── jest.config.js │ ├── package.json │ ├── src │ │ ├── address.ts │ │ ├── bn.ts │ │ ├── const.ts │ │ ├── hex.ts │ │ ├── index.ts │ │ ├── is.ts │ │ ├── object.ts │ │ ├── string.ts │ │ ├── tx.ts │ │ ├── types.ts │ │ └── u8a.ts │ ├── tests │ │ └── dot.test.ts │ └── tsconfig.json ├── coin-solana │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── jest.config.js │ ├── package.json │ ├── src │ │ ├── SolWallet.ts │ │ ├── api.ts │ │ ├── index.ts │ │ └── sdk │ │ │ ├── buffer-layout │ │ │ ├── index.ts │ │ │ ├── layout.ts │ │ │ └── utils │ │ │ │ ├── base.ts │ │ │ │ ├── bigint.ts │ │ │ │ ├── decimal.ts │ │ │ │ ├── index.ts │ │ │ │ ├── native.ts │ │ │ │ └── web3.ts │ │ │ ├── index.ts │ │ │ ├── metaplex │ │ │ ├── beet-solana │ │ │ │ └── index.ts │ │ │ ├── index.ts │ │ │ ├── mpl-token-metadata │ │ │ │ ├── index.ts │ │ │ │ ├── instructions │ │ │ │ │ ├── Transfer.ts │ │ │ │ │ └── index.ts │ │ │ │ └── types │ │ │ │ │ ├── AuthorityType.ts │ │ │ │ │ ├── AuthorizationData.ts │ │ │ │ │ ├── DelegateArgs.ts │ │ │ │ │ ├── LeafInfo.ts │ │ │ │ │ ├── MetadataDelegateRole.ts │ │ │ │ │ ├── Payload.ts │ │ │ │ │ ├── PayloadType.ts │ │ │ │ │ ├── SeedsVec.ts │ │ │ │ │ ├── TokenDelegateRole.ts │ │ │ │ │ ├── TokenStandard.ts │ │ │ │ │ ├── TransferArgs.ts │ │ │ │ │ └── index.ts │ │ │ ├── plugins │ │ │ │ └── nftModule │ │ │ │ │ ├── Authorization.ts │ │ │ │ │ ├── DelegateInput.ts │ │ │ │ │ ├── DelegateType.ts │ │ │ │ │ ├── models │ │ │ │ │ ├── Metadata.ts │ │ │ │ │ └── index.ts │ │ │ │ │ ├── operations │ │ │ │ │ └── transferNft.ts │ │ │ │ │ └── pdas.ts │ │ │ ├── types │ │ │ │ ├── Amount.ts │ │ │ │ ├── BigNumber.ts │ │ │ │ ├── Pda.ts │ │ │ │ ├── Program.ts │ │ │ │ ├── PublicKey.ts │ │ │ │ ├── Signer.ts │ │ │ │ └── index.ts │ │ │ └── utils │ │ │ │ ├── TransactionBuilder.ts │ │ │ │ ├── index.ts │ │ │ │ └── types.ts │ │ │ ├── spl │ │ │ ├── constants.ts │ │ │ ├── errors.ts │ │ │ ├── index.ts │ │ │ └── instructions │ │ │ │ ├── associatedTokenAccount.ts │ │ │ │ ├── burn.ts │ │ │ │ ├── burnChecked.ts │ │ │ │ ├── index.ts │ │ │ │ ├── internal.ts │ │ │ │ ├── mintTo.ts │ │ │ │ ├── mintToChecked.ts │ │ │ │ ├── transfer.ts │ │ │ │ ├── transferChecked.ts │ │ │ │ └── types.ts │ │ │ └── web3 │ │ │ ├── account-data.ts │ │ │ ├── blockhash.ts │ │ │ ├── fee-calculator.ts │ │ │ ├── index.ts │ │ │ ├── instruction.ts │ │ │ ├── keypair.ts │ │ │ ├── layout.ts │ │ │ ├── message │ │ │ ├── account-keys.ts │ │ │ ├── compiled-keys.ts │ │ │ ├── index.ts │ │ │ ├── legacy.ts │ │ │ ├── v0.ts │ │ │ └── versioned.ts │ │ │ ├── nonce-account.ts │ │ │ ├── programs │ │ │ ├── address-lookup-table │ │ │ │ ├── index.ts │ │ │ │ └── state.ts │ │ │ ├── compute-budget.ts │ │ │ ├── index.ts │ │ │ └── system.ts │ │ │ ├── publickey.ts │ │ │ ├── sysvar.ts │ │ │ ├── transaction │ │ │ ├── constants.ts │ │ │ ├── expiry-custom-errors.ts │ │ │ ├── index.ts │ │ │ ├── legacy.ts │ │ │ ├── message.ts │ │ │ └── versioned.ts │ │ │ └── utils │ │ │ ├── assert.ts │ │ │ ├── bigint.ts │ │ │ ├── borsh-schema.ts │ │ │ ├── shortvec-encoding.ts │ │ │ └── to-buffer.ts │ ├── tests │ │ └── sol.test.ts │ └── tsconfig.json ├── coin-stacks │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── jest.config.js │ ├── package.json │ ├── src │ │ ├── Stxwallet.ts │ │ ├── base-x │ │ │ ├── index.d.ts │ │ │ └── index.js │ │ ├── c32check │ │ │ ├── address.ts │ │ │ ├── base58check.ts │ │ │ ├── checksum.ts │ │ │ ├── encoding.ts │ │ │ └── index.ts │ │ ├── common │ │ │ ├── buffer.ts │ │ │ ├── config.ts │ │ │ ├── constants.ts │ │ │ ├── errors.ts │ │ │ ├── index.ts │ │ │ ├── keys.ts │ │ │ ├── logger.ts │ │ │ ├── signatures.ts │ │ │ └── utils.ts │ │ ├── encryption │ │ │ ├── base64-js.js │ │ │ ├── cryptoRandom.ts │ │ │ ├── ec.ts │ │ │ ├── hashRipemd160.ts │ │ │ ├── index.ts │ │ │ ├── keys.ts │ │ │ ├── messageSignature.ts │ │ │ ├── sha2Hash.ts │ │ │ ├── utils.ts │ │ │ └── varuint.ts │ │ ├── index.ts │ │ ├── network │ │ │ ├── index.ts │ │ │ └── network.ts │ │ ├── stacking │ │ │ ├── constants.ts │ │ │ ├── generated.ts │ │ │ ├── index.ts │ │ │ └── utils.ts │ │ ├── transaction.ts │ │ └── transactions │ │ │ ├── authorization.ts │ │ │ ├── builders.ts │ │ │ ├── bytesReader.ts │ │ │ ├── cl.ts │ │ │ ├── clarity │ │ │ ├── clarityValue.ts │ │ │ ├── constants.ts │ │ │ ├── deepclone.js │ │ │ ├── deserialize.ts │ │ │ ├── index.ts │ │ │ ├── serialize.ts │ │ │ └── types │ │ │ │ ├── booleanCV.ts │ │ │ │ ├── bufferCV.ts │ │ │ │ ├── intCV.ts │ │ │ │ ├── listCV.ts │ │ │ │ ├── optionalCV.ts │ │ │ │ ├── principalCV.ts │ │ │ │ ├── responseCV.ts │ │ │ │ ├── stringCV.ts │ │ │ │ └── tupleCV.ts │ │ │ ├── common.ts │ │ │ ├── constants.ts │ │ │ ├── contract-abi.ts │ │ │ ├── errors.ts │ │ │ ├── index.ts │ │ │ ├── keys.ts │ │ │ ├── payload.ts │ │ │ ├── pc.ts │ │ │ ├── postcondition-types.ts │ │ │ ├── postcondition.ts │ │ │ ├── signature.ts │ │ │ ├── signer.ts │ │ │ ├── structuredDataSignature.ts │ │ │ ├── transaction.ts │ │ │ ├── types.ts │ │ │ └── utils.ts │ ├── tests │ │ ├── stacking.test.ts │ │ └── transaction.test.ts │ └── tsconfig.json ├── coin-starknet │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── jest.config.js │ ├── package.json │ ├── src │ │ ├── StarknetWallet.ts │ │ ├── account │ │ │ ├── default.ts │ │ │ ├── index.ts │ │ │ └── interface.ts │ │ ├── constants.ts │ │ ├── index.ts │ │ ├── provider │ │ │ └── utils.ts │ │ ├── signer │ │ │ ├── default.ts │ │ │ ├── index.ts │ │ │ └── interface.ts │ │ ├── types │ │ │ ├── account.ts │ │ │ ├── api │ │ │ │ ├── index.ts │ │ │ │ ├── openrpc.ts │ │ │ │ ├── rpc.ts │ │ │ │ └── sequencer.ts │ │ │ ├── contract.ts │ │ │ ├── index.ts │ │ │ ├── lib │ │ │ │ ├── contract │ │ │ │ │ ├── abi.ts │ │ │ │ │ ├── index.ts │ │ │ │ │ ├── legacy.ts │ │ │ │ │ └── sierra.ts │ │ │ │ └── index.ts │ │ │ ├── provider.ts │ │ │ └── signer.ts │ │ └── utils │ │ │ ├── address.ts │ │ │ ├── assert.ts │ │ │ ├── calldata │ │ │ ├── cairo.ts │ │ │ ├── formatter.ts │ │ │ ├── index.ts │ │ │ ├── requestParser.ts │ │ │ ├── responseParser.ts │ │ │ ├── tuple.ts │ │ │ └── validate.ts │ │ │ ├── contract.ts │ │ │ ├── ec.ts │ │ │ ├── encode.ts │ │ │ ├── events.ts │ │ │ ├── hash.ts │ │ │ ├── json.ts │ │ │ ├── json │ │ │ ├── LosslessNumber.ts │ │ │ ├── index.ts │ │ │ ├── numberParsers.ts │ │ │ ├── parse.ts │ │ │ ├── revive.ts │ │ │ ├── stringify.ts │ │ │ ├── types.ts │ │ │ └── utils.ts │ │ │ ├── merkle.ts │ │ │ ├── num.ts │ │ │ ├── provider.ts │ │ │ ├── shortString.ts │ │ │ ├── stark.ts │ │ │ ├── transaction.ts │ │ │ ├── typedData │ │ │ ├── index.ts │ │ │ ├── types.ts │ │ │ └── utils.ts │ │ │ └── uint256.ts │ ├── tests │ │ └── crypto.test.ts │ └── tsconfig.json ├── coin-stellar │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── babel.config.json │ ├── jest.config.js │ ├── package.json │ ├── src │ │ ├── PIWallet.ts │ │ ├── StellarWallet.ts │ │ ├── index.ts │ │ ├── stellar_base │ │ │ ├── account.js │ │ │ ├── address.js │ │ │ ├── asset.js │ │ │ ├── auth.js │ │ │ ├── claimant.js │ │ │ ├── contract.js │ │ │ ├── events.js │ │ │ ├── fee_bump_transaction.js │ │ │ ├── generated │ │ │ │ ├── curr_generated.js │ │ │ │ └── next_generated.js │ │ │ ├── get_liquidity_pool_id.js │ │ │ ├── hashing.js │ │ │ ├── index.js │ │ │ ├── invocation.js │ │ │ ├── jsxdr.js │ │ │ ├── keypair.js │ │ │ ├── liquidity_pool_asset.js │ │ │ ├── liquidity_pool_id.js │ │ │ ├── memo.js │ │ │ ├── muxed_account.js │ │ │ ├── network.js │ │ │ ├── numbers │ │ │ │ ├── index.js │ │ │ │ ├── int128.js │ │ │ │ ├── int256.js │ │ │ │ ├── sc_int.js │ │ │ │ ├── uint128.js │ │ │ │ ├── uint256.js │ │ │ │ └── xdr_large_int.js │ │ │ ├── operation.js │ │ │ ├── operations │ │ │ │ ├── account_merge.js │ │ │ │ ├── allow_trust.js │ │ │ │ ├── begin_sponsoring_future_reserves.js │ │ │ │ ├── bump_sequence.js │ │ │ │ ├── change_trust.js │ │ │ │ ├── claim_claimable_balance.js │ │ │ │ ├── clawback.js │ │ │ │ ├── clawback_claimable_balance.js │ │ │ │ ├── create_account.js │ │ │ │ ├── create_claimable_balance.js │ │ │ │ ├── create_passive_sell_offer.js │ │ │ │ ├── end_sponsoring_future_reserves.js │ │ │ │ ├── extend_footprint_ttl.js │ │ │ │ ├── index.js │ │ │ │ ├── inflation.js │ │ │ │ ├── invoke_host_function.js │ │ │ │ ├── liquidity_pool_deposit.js │ │ │ │ ├── liquidity_pool_withdraw.js │ │ │ │ ├── manage_buy_offer.js │ │ │ │ ├── manage_data.js │ │ │ │ ├── manage_sell_offer.js │ │ │ │ ├── path_payment_strict_receive.js │ │ │ │ ├── path_payment_strict_send.js │ │ │ │ ├── payment.js │ │ │ │ ├── restore_footprint.js │ │ │ │ ├── revoke_sponsorship.js │ │ │ │ ├── set_options.js │ │ │ │ └── set_trustline_flags.js │ │ │ ├── scval.js │ │ │ ├── signerkey.js │ │ │ ├── signing.js │ │ │ ├── soroban.js │ │ │ ├── sorobandata_builder.js │ │ │ ├── strkey.js │ │ │ ├── transaction.js │ │ │ ├── transaction_base.js │ │ │ ├── transaction_builder.js │ │ │ ├── util │ │ │ │ ├── bignumber.js │ │ │ │ ├── checksum.js │ │ │ │ ├── continued_fraction.js │ │ │ │ ├── decode_encode_muxed_account.js │ │ │ │ └── util.js │ │ │ └── xdr.js │ │ └── utils.ts │ ├── tests │ │ ├── wallet.test.ts │ │ └── walletPi.test.ts │ └── tsconfig.json ├── coin-sui │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── jest.config.js │ ├── package.json │ ├── src │ │ ├── SuiWallet.ts │ │ ├── bcs │ │ │ ├── b64.ts │ │ │ ├── hex.ts │ │ │ └── index.ts │ │ ├── builder │ │ │ ├── Inputs.ts │ │ │ ├── TransactionBlock.ts │ │ │ ├── TransactionBlockData.ts │ │ │ ├── Transactions.ts │ │ │ ├── bcs.ts │ │ │ ├── index.ts │ │ │ ├── serializer.ts │ │ │ └── utils.ts │ │ ├── cryptography │ │ │ ├── ed25519-keypair.ts │ │ │ ├── ed25519-publickey.ts │ │ │ ├── hash.ts │ │ │ ├── keypair.ts │ │ │ ├── publickey.ts │ │ │ └── signature.ts │ │ ├── framework │ │ │ ├── framework.ts │ │ │ └── index.ts │ │ ├── index.ts │ │ ├── pkg-version.ts │ │ ├── signers │ │ │ ├── raw-signer.ts │ │ │ ├── signer-with-provider.ts │ │ │ ├── signer.ts │ │ │ ├── txn-data-serializers │ │ │ │ └── type-tag-serializer.ts │ │ │ └── types.ts │ │ ├── types │ │ │ ├── checkpoints.ts │ │ │ ├── coin.ts │ │ │ ├── common.ts │ │ │ ├── dynamic_fields.ts │ │ │ ├── events.ts │ │ │ ├── faucet.ts │ │ │ ├── index.ts │ │ │ ├── normalized.ts │ │ │ ├── objects.ts │ │ │ ├── option.ts │ │ │ ├── sui-bcs.ts │ │ │ ├── transactions.ts │ │ │ └── validator.ts │ │ └── utils │ │ │ ├── format.ts │ │ │ ├── intent.ts │ │ │ └── properties.ts │ ├── tests │ │ └── crypto.test.ts │ └── tsconfig.json ├── coin-ton │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── jest.config.js │ ├── package.json │ ├── src │ │ ├── TonWallet.ts │ │ ├── api │ │ │ ├── address.ts │ │ │ ├── constant.ts │ │ │ ├── index.ts │ │ │ ├── nfts.ts │ │ │ ├── transaction.ts │ │ │ └── types.ts │ │ ├── index.ts │ │ ├── ton-core │ │ │ ├── address │ │ │ │ ├── ADNLAddress.ts │ │ │ │ ├── Address.ts │ │ │ │ ├── ExternalAddress.ts │ │ │ │ └── contractAddress.ts │ │ │ ├── boc │ │ │ │ ├── BitBuilder.ts │ │ │ │ ├── BitReader.ts │ │ │ │ ├── BitString.ts │ │ │ │ ├── Builder.ts │ │ │ │ ├── Cell.ts │ │ │ │ ├── CellType.ts │ │ │ │ ├── Slice.ts │ │ │ │ ├── Writable.ts │ │ │ │ ├── cell │ │ │ │ │ ├── LevelMask.ts │ │ │ │ │ ├── descriptor.ts │ │ │ │ │ ├── exoticLibrary.ts │ │ │ │ │ ├── exoticMerkleProof.ts │ │ │ │ │ ├── exoticMerkleUpdate.ts │ │ │ │ │ ├── exoticPruned.ts │ │ │ │ │ ├── resolveExotic.ts │ │ │ │ │ ├── serialization.ts │ │ │ │ │ ├── utils │ │ │ │ │ │ └── topologicalSort.ts │ │ │ │ │ └── wonderCalculator.ts │ │ │ │ └── utils │ │ │ │ │ ├── paddedBits.ts │ │ │ │ │ └── strings.ts │ │ │ ├── contract │ │ │ │ ├── ComputeError.ts │ │ │ │ ├── Contract.ts │ │ │ │ ├── ContractABI.ts │ │ │ │ ├── ContractProvider.ts │ │ │ │ ├── ContractState.ts │ │ │ │ ├── Sender.ts │ │ │ │ └── openContract.ts │ │ │ ├── crypto │ │ │ │ └── safeSign.ts │ │ │ ├── dict │ │ │ │ ├── Dictionary.ts │ │ │ │ ├── generateMerkleProof.ts │ │ │ │ ├── generateMerkleUpdate.ts │ │ │ │ ├── parseDict.ts │ │ │ │ ├── serializeDict.ts │ │ │ │ └── utils │ │ │ │ │ ├── findCommonPrefix.ts │ │ │ │ │ ├── internalKeySerializer.spec.ts │ │ │ │ │ ├── internalKeySerializer.ts │ │ │ │ │ └── readUnaryLength.ts │ │ │ ├── index.ts │ │ │ ├── tuple │ │ │ │ ├── builder.ts │ │ │ │ ├── reader.ts │ │ │ │ ├── tuple.ts │ │ │ │ └── ultra_deep_cons.json │ │ │ ├── types │ │ │ │ ├── Account.ts │ │ │ │ ├── AccountState.ts │ │ │ │ ├── AccountStatus.ts │ │ │ │ ├── AccountStatusChange.ts │ │ │ │ ├── AccountStorage.ts │ │ │ │ ├── CommonMessageInfo.ts │ │ │ │ ├── CommonMessageInfoRelaxed.ts │ │ │ │ ├── ComputeSkipReason.ts │ │ │ │ ├── CurrencyCollection.ts │ │ │ │ ├── DepthBalanceInfo.ts │ │ │ │ ├── HashUpdate.ts │ │ │ │ ├── MasterchainStateExtra.ts │ │ │ │ ├── Message.ts │ │ │ │ ├── MessageRelaxed.ts │ │ │ │ ├── OutList.ts │ │ │ │ ├── SendMode.ts │ │ │ │ ├── ShardAccount.ts │ │ │ │ ├── ShardAccounts.ts │ │ │ │ ├── ShardIdent.ts │ │ │ │ ├── ShardStateUnsplit.ts │ │ │ │ ├── SimpleLibrary.ts │ │ │ │ ├── SplitMergeInfo.ts │ │ │ │ ├── StateInit.ts │ │ │ │ ├── StorageInto.ts │ │ │ │ ├── StorageUsed.ts │ │ │ │ ├── StorageUsedShort.ts │ │ │ │ ├── TickTock.ts │ │ │ │ ├── Transaction.ts │ │ │ │ ├── TransactionActionPhase.ts │ │ │ │ ├── TransactionBouncePhase.ts │ │ │ │ ├── TransactionComputePhase.ts │ │ │ │ ├── TransactionCreditPhase.ts │ │ │ │ ├── TransactionDescription.ts │ │ │ │ ├── TransactionStoragePhase.ts │ │ │ │ ├── __testdata__ │ │ │ │ │ └── configProof.json │ │ │ │ ├── _export.ts │ │ │ │ └── _helpers.ts │ │ │ └── utils │ │ │ │ ├── base32.ts │ │ │ │ ├── bitsForNumber.ts │ │ │ │ ├── convert.ts │ │ │ │ ├── crc16.ts │ │ │ │ ├── crc32c.ts │ │ │ │ ├── getMethodId.ts │ │ │ │ ├── maybe.ts │ │ │ │ └── testAddress.ts │ │ ├── ton-crypto-primitives │ │ │ ├── node.ts │ │ │ └── node │ │ │ │ ├── getSecureRandom.ts │ │ │ │ ├── hmac_sha512.ts │ │ │ │ ├── pbkdf2_sha512.ts │ │ │ │ ├── sha256.ts │ │ │ │ └── sha512.ts │ │ ├── ton-crypto │ │ │ ├── index.ts │ │ │ └── primitives │ │ │ │ ├── getSecureRandom.ts │ │ │ │ ├── hmac_sha512.ts │ │ │ │ ├── nacl.ts │ │ │ │ ├── pbkdf2_sha512.ts │ │ │ │ ├── sha256.ts │ │ │ │ └── sha512.ts │ │ └── ton │ │ │ ├── index.ts │ │ │ ├── utils │ │ │ └── maybe.ts │ │ │ └── wallets │ │ │ ├── VenomWalletV3.ts │ │ │ ├── WalletContractV3R2.ts │ │ │ ├── WalletContractV4.ts │ │ │ └── signing │ │ │ └── createWalletTransfer.ts │ ├── tests │ │ └── ton.test.ts │ └── tsconfig.json ├── coin-tron │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── jest.config.js │ ├── package.json │ ├── src │ │ ├── TrxWallet.ts │ │ ├── index.ts │ │ └── protobuf │ │ │ ├── Contract.proto │ │ │ ├── Discover.proto │ │ │ ├── attribution.md │ │ │ ├── tron.d.ts │ │ │ ├── tron.js │ │ │ └── tron.proto │ ├── tests │ │ └── trx.test.ts │ └── tsconfig.json ├── coin-zkspace │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── jest.config.js │ ├── package.json │ ├── src │ │ ├── Units.ts │ │ ├── ZkspaceWallet.ts │ │ ├── ZksyncWallet.ts │ │ ├── index.ts │ │ ├── zkspace │ │ │ └── index.ts │ │ ├── zksync-crypto │ │ │ └── zksync-crypto-web.js │ │ └── zksync │ │ │ ├── index.ts │ │ │ └── utils.ts │ ├── tests │ │ ├── zkspace.test.ts │ │ └── zksync.test.ts │ └── tsconfig.json └── crypto-lib │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── jest.config.js │ ├── package.json │ ├── src │ ├── abi │ │ ├── LICENSE │ │ ├── abi.js │ │ ├── bytes.ts │ │ ├── helpers.ts │ │ ├── index.ts │ │ ├── internal.ts │ │ ├── rlp.ts │ │ ├── types.ts │ │ └── util.ts │ ├── base │ │ ├── LICENSE │ │ ├── ascii.ts │ │ ├── base58.ts │ │ ├── base58Check.ts │ │ ├── base64.ts │ │ ├── bech32.ts │ │ ├── bignumber-plus.ts │ │ ├── hash.ts │ │ ├── helper.ts │ │ ├── hex.ts │ │ ├── hmac.ts │ │ ├── index.ts │ │ ├── md5.ts │ │ ├── precondtion.ts │ │ └── utf8.ts │ ├── bip32 │ │ ├── LICENSE │ │ ├── api.ts │ │ ├── bip32.ts │ │ └── index.ts │ ├── bip39 │ │ ├── _wordlists.ts │ │ ├── index.ts │ │ └── wordlists │ │ │ └── english.json │ ├── elliptic │ │ ├── LICENSE │ │ ├── curve │ │ │ ├── base.js │ │ │ ├── edwards.js │ │ │ ├── index.js │ │ │ ├── mont.js │ │ │ └── short.js │ │ ├── curves.js │ │ ├── ec │ │ │ ├── index.js │ │ │ ├── key.js │ │ │ └── signature.js │ │ ├── eddsa │ │ │ ├── index.js │ │ │ ├── key.js │ │ │ └── signature.js │ │ ├── index.ts │ │ ├── precomputed │ │ │ └── secp256k1.js │ │ └── utils.js │ ├── index.ts │ ├── math │ │ ├── LICENSE │ │ ├── decimal.ts │ │ ├── index.ts │ │ └── integers.ts │ └── signutil │ │ ├── LICENSE │ │ ├── ed25519.ts │ │ ├── index.ts │ │ ├── p256.ts │ │ ├── schnorr │ │ ├── _shortw_utils.ts │ │ ├── abstract │ │ │ ├── curve.ts │ │ │ ├── hash-to-curve.ts │ │ │ ├── modular.ts │ │ │ ├── poseidon.ts │ │ │ ├── utils.ts │ │ │ └── weierstrass.ts │ │ ├── index.ts │ │ ├── secp256k1.ts │ │ └── stark.ts │ │ └── secp256k1.ts │ ├── tests │ ├── batch.test.ts │ ├── crypto.test.ts │ └── hex.test.ts │ └── tsconfig.json ├── refresh_doc.sh ├── scripts └── dep-version-check.js └── tsconfig.json /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/* 2 | .vscode 3 | build 4 | dist 5 | node_modules 6 | coverage 7 | *.log 8 | .env.local 9 | .DS_Store 10 | *.tsbuildinfo 11 | *.tgz 12 | .eslintcache 13 | yarn.lock 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 OKX.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | ## Security 2 | 3 | If you find security risks, it is recommended to feedback through the following channels and get your reward! 4 | submit on HackerOne platform https://hackerone.com/okg Or on our OKX feedback submission page > security bugs https://www.okx.com/feedback/submit -------------------------------------------------------------------------------- /docs/.nojekyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/okx/js-wallet-sdk/03cd3f0c7f06caeb648e0cdb34c1c83abef17c24/docs/.nojekyll -------------------------------------------------------------------------------- /docs/_coverpage.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ![logo](media/logo.png) 4 | 5 | # js-wallet-sdk 6 | 7 | 8 | - Generic Architecture, easy to extend and maintain 9 | - Fully Browser Compatible 10 | - Support for Bitcoin, Ethereum, Cosmos, Aptos, Sol ... 11 | 12 | [GitHub](https://github.com/okx/js-wallet-sdk) 13 | 14 | -------------------------------------------------------------------------------- /docs/coins/bitcoin/images/rune_batch_mint.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/okx/js-wallet-sdk/03cd3f0c7f06caeb648e0cdb34c1c83abef17c24/docs/coins/bitcoin/images/rune_batch_mint.png -------------------------------------------------------------------------------- /docs/coins/bitcoin/images/rune_serial_mint.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/okx/js-wallet-sdk/03cd3f0c7f06caeb648e0cdb34c1c83abef17c24/docs/coins/bitcoin/images/rune_serial_mint.png -------------------------------------------------------------------------------- /docs/media/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/okx/js-wallet-sdk/03cd3f0c7f06caeb648e0cdb34c1c83abef17c24/docs/media/logo.png -------------------------------------------------------------------------------- /docs/start.sh: -------------------------------------------------------------------------------- 1 | docsify serve -------------------------------------------------------------------------------- /examples/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /examples/src/App.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | import {Box, ChakraProvider, theme } from "@chakra-ui/react" 3 | import { BrowserRouter as Router, Routes, Route } from "react-router-dom"; 4 | import Header from "./components/Header"; 5 | import Home from "./pages/Home"; 6 | import Evm from "./pages/Evm"; 7 | import Btc from "./pages/Btc"; 8 | import Ton from "./pages/Ton"; 9 | 10 | export const App = () => ( 11 | 12 | 13 |
14 | 15 | 16 | }/> 17 | } /> 18 | } /> 19 | } /> 20 | 21 | 22 | 23 | 24 | ) 25 | -------------------------------------------------------------------------------- /examples/src/components/AddressOutput.tsx: -------------------------------------------------------------------------------- 1 | import {CheckIcon, CopyIcon, StarIcon} from "@chakra-ui/icons"; 2 | import {Alert, AlertIcon, Heading, IconButton, useClipboard} from "@chakra-ui/react"; 3 | 4 | interface AddressProps { 5 | address: string 6 | } 7 | const AddressOutput: React.FC = (props) =>{ 8 | const { hasCopied: hasCopiedAddress, onCopy: onCopyAddress } = useClipboard(props.address); 9 | return ( 10 | props.address ? 11 | 12 | 13 | {"Address: " + props.address } 14 | : } 18 | aria-label={hasCopiedAddress ? 'Copied' : 'Copy'} 19 | /> 20 | 21 | :
22 | ) 23 | } 24 | export default AddressOutput -------------------------------------------------------------------------------- /examples/src/components/SignedOutput.tsx: -------------------------------------------------------------------------------- 1 | import {Alert, AlertIcon, AlertTitle, Box} from "@chakra-ui/react"; 2 | import React from "react"; 3 | 4 | 5 | const SignedOutput: React.FC<{name: string, output: string}> = (props) => { 6 | return ( 7 | props.output ? 8 | 16 | 17 | 18 | {props.name}: 19 | {props.output} 20 | 21 | 22 | : 23 | ); 24 | }; 25 | export default SignedOutput -------------------------------------------------------------------------------- /examples/src/components/toast.tsx: -------------------------------------------------------------------------------- 1 | import {CreateToastFnReturn} from "@chakra-ui/react"; 2 | 3 | const capitalizeFirstLetter = (str: string): string => { 4 | if (str.length === 0) return str; // Handle empty string case 5 | return str.charAt(0).toUpperCase() + str.slice(1); 6 | }; 7 | export function successToast(toast: CreateToastFnReturn, title: string) { 8 | toast.closeAll() 9 | return toast({ 10 | title: capitalizeFirstLetter(title), 11 | status: 'success', 12 | duration: 5000, 13 | isClosable: true, 14 | position: "top-right" 15 | }) 16 | 17 | } 18 | export function errorToast(toast: CreateToastFnReturn, title: string) { 19 | toast.closeAll() 20 | return toast({ 21 | title: capitalizeFirstLetter(title), 22 | status: 'error', 23 | duration: 5000, 24 | isClosable: true, 25 | position: "top-right" 26 | }) 27 | } -------------------------------------------------------------------------------- /examples/src/index.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | import * as ReactDOM from "react-dom/client" 3 | import { App } from "./App" 4 | 5 | const root = ReactDOM.createRoot(document.getElementById('root')!); 6 | 7 | root.render( 8 | 9 | 10 | , 11 | ) 12 | -------------------------------------------------------------------------------- /examples/src/pages/Btc.tsx: -------------------------------------------------------------------------------- 1 | import { Box, VStack} from "@chakra-ui/react"; 2 | import {useState} from "react"; 3 | import BtcSignTx from "../components/BtcSignTx"; 4 | import {BtcWallet} from "@okxweb3/coin-bitcoin"; 5 | import {BitcoinWallets} from "../components/types"; 6 | import BtcPrivateKey from "../components/BtcPrivateKey"; 7 | 8 | 9 | export default function Btc() { 10 | const [privateKey, setPrivateKey] = useState("L2Nk86vWbm8eETtJa8N6DCeejRRJkjcHuYufkMq4A8sCLroS1rKU") 11 | const [wallet, setWallet] = useState(new BtcWallet()) 12 | 13 | 14 | return ( 15 | 16 | 17 | 18 | 19 | 20 | 21 | ); 22 | 23 | } -------------------------------------------------------------------------------- /examples/src/pages/Ton.tsx: -------------------------------------------------------------------------------- 1 | import {VStack} from "@chakra-ui/react"; 2 | import {useState} from "react"; 3 | import TonPrivateKey from "../components/TonPrivateKey"; 4 | import {TonWallet} from "@okxweb3/coin-ton"; 5 | import TonSignTx from "../components/TonSignTx"; 6 | import TonSignJettonTx from "../components/TonSignJettonTx"; 7 | 8 | 9 | export default function Ton() { 10 | const [privateKey, setPrivateKey] = useState("49c0722d56d6bac802bdf5c480a17c870d1d18bc4355d8344aa05390eb778280") 11 | const wallet = new TonWallet() 12 | 13 | return ( 14 | 15 | 16 | 17 | 18 | 19 | ); 20 | } -------------------------------------------------------------------------------- /examples/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": [ 5 | "dom", 6 | "dom.iterable", 7 | "esnext" 8 | ], 9 | "allowJs": true, 10 | "skipLibCheck": true, 11 | "esModuleInterop": true, 12 | "allowSyntheticDefaultImports": true, 13 | "strict": true, 14 | "forceConsistentCasingInFileNames": true, 15 | "noFallthroughCasesInSwitch": true, 16 | "module": "esnext", 17 | "moduleResolution": "node", 18 | "resolveJsonModule": true, 19 | "isolatedModules": true, 20 | "noEmit": true, 21 | "jsx": "react-jsx" 22 | }, 23 | "include": [ 24 | "src" 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "okxweb3", 3 | "version": "1.0.0", 4 | "description": "okx js sdk for web3", 5 | "main": "index.js", 6 | "scripts": {}, 7 | "author": "", 8 | "license": "MIT", 9 | "files": [ 10 | "dist" 11 | ], 12 | "devDependencies": { 13 | "@types/jest": "^29.2.5", 14 | "@types/node": "^12.20.52", 15 | "jest": "^29.7.0", 16 | "npm-run-all": "^4.1.5", 17 | "prettier": "2.6.2", 18 | "rimraf": "^3.0.2", 19 | "ts-jest": "^29.2.5", 20 | "ts-node": "^10.9.2", 21 | "typescript": "^4.6.2" 22 | }, 23 | "dependencies": { 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /packages/coin-aptos/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | # Change Log 3 | 4 | All notable changes to this project will be documented in this file. 5 | 6 | 7 | # [1.2.0](https://github.com/okx/js-wallet-sdk)(2024-01-15) 8 | 9 | ### New Features 10 | 11 | - **coin-aptos:** support signCommonMsg ([](https://github.com/okx/js-wallet-sdk)) 12 | 13 | # [1.1.0](https://github.com/okx/js-wallet-sdk)(2024-01-09) 14 | 15 | ### New Features 16 | 17 | - **coin-aptos:** support build simulate transaction ([](https://github.com/okx/js-wallet-sdk)) 18 | 19 | # [1.0.7](https://github.com/okx/js-wallet-sdk) (2024-08-20) 20 | 21 | ### New Features 22 | 23 | - **coin-aptos:** support Fungible Asset, compatible with different dapp protocols ([](https://github.com/okx/js-wallet-sdk)) 24 | 25 | ### Fix 26 | 27 | - **coin-aptos:** upgrade private key verification ([](https://github.com/okx/js-wallet-sdk)) 28 | 29 | 30 | # [1.0.1](https://github.com/okx/js-wallet-sdk) (2023-11-17) 31 | 32 | ### Bug Fixes 33 | 34 | - **coin-aptos:** support for module 0x1::object::Object and 0x1::option::Option ([30](https://github.com/okx/js-wallet-sdk/pull/30)) 35 | -------------------------------------------------------------------------------- /packages/coin-aptos/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 OKX.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /packages/coin-aptos/jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest').JestConfigWithTsJest} */ 2 | module.exports = { 3 | preset: 'ts-jest', 4 | testEnvironment: 'node', 5 | }; -------------------------------------------------------------------------------- /packages/coin-aptos/src/generated/index.ts: -------------------------------------------------------------------------------- 1 | export type { HexEncodedBytes } from './models/HexEncodedBytes'; -------------------------------------------------------------------------------- /packages/coin-aptos/src/generated/models/HexEncodedBytes.ts: -------------------------------------------------------------------------------- 1 | /* istanbul ignore file */ 2 | /* tslint:disable */ 3 | /* eslint-disable */ 4 | 5 | /** 6 | * All bytes (Vec) data is represented as hex-encoded string prefixed with `0x` and fulfilled with 7 | * two hex digits per byte. 8 | * 9 | * Unlike the `Address` type, HexEncodedBytes will not trim any zeros. 10 | * 11 | */ 12 | export type HexEncodedBytes = string; 13 | -------------------------------------------------------------------------------- /packages/coin-aptos/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./client" 2 | export * from "./hex_string" 3 | export * from "./aptos_account" 4 | export * from "./transaction_builder" 5 | export * from "./AptosWallet" 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /packages/coin-aptos/src/transaction_builder/aptos_types/identifier.ts: -------------------------------------------------------------------------------- 1 | /*** 2 | * Copyright © Aptos Foundation 3 | *SPDX-License-Identifier: Apache-2.0 4 | * 5 | * https://raw.githubusercontent.com/aptos-labs/aptos-core/097ea73b4a78c0166f22a269f27e514dc895afb4/ecosystem/typescript/sdk/LICENSE 6 | * 7 | * */ 8 | 9 | import { Deserializer, Serializer } from "../bcs"; 10 | 11 | export class Identifier { 12 | constructor(public value: string) {} 13 | 14 | public serialize(serializer: Serializer): void { 15 | serializer.serializeStr(this.value); 16 | } 17 | 18 | static deserialize(deserializer: Deserializer): Identifier { 19 | const value = deserializer.deserializeStr(); 20 | return new Identifier(value); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /packages/coin-aptos/src/transaction_builder/aptos_types/index.ts: -------------------------------------------------------------------------------- 1 | /*** 2 | * Copyright © Aptos Foundation 3 | *SPDX-License-Identifier: Apache-2.0 4 | * 5 | * https://raw.githubusercontent.com/aptos-labs/aptos-core/097ea73b4a78c0166f22a269f27e514dc895afb4/ecosystem/typescript/sdk/LICENSE 6 | * 7 | * */ 8 | 9 | export * from "./account_address"; 10 | export * from "./authenticator"; 11 | export * from "./transaction"; 12 | export * from "./type_tag"; 13 | export * from "./identifier"; 14 | export * from "./ed25519"; 15 | export * from "./multi_ed25519"; 16 | export * from "./authentication_key"; 17 | 18 | // export type SigningMessage = Buffer; 19 | export type SigningMessage = Uint8Array; 20 | -------------------------------------------------------------------------------- /packages/coin-aptos/src/transaction_builder/bcs/consts.ts: -------------------------------------------------------------------------------- 1 | /*** 2 | * Copyright © Aptos Foundation 3 | *SPDX-License-Identifier: Apache-2.0 4 | * 5 | * https://raw.githubusercontent.com/aptos-labs/aptos-core/097ea73b4a78c0166f22a269f27e514dc895afb4/ecosystem/typescript/sdk/LICENSE 6 | * 7 | * */ 8 | 9 | import {Uint128, Uint16, Uint256, Uint32, Uint64, Uint8} from "./types"; 10 | 11 | // Upper bound values for uint8, uint16, uint64 and uint128 12 | export const MAX_U8_NUMBER: Uint8 = 2 ** 8 - 1; 13 | export const MAX_U16_NUMBER: Uint16 = 2 ** 16 - 1; 14 | export const MAX_U32_NUMBER: Uint32 = 2 ** 32 - 1; 15 | export const MAX_U64_BIG_INT: Uint64 = BigInt(2 ** 64) - 1n; 16 | export const MAX_U128_BIG_INT: Uint128 = BigInt(2 ** 128) - 1n; 17 | export const MAX_U256_BIG_INT: Uint256 = BigInt(2 ** 256) - BigInt(1); -------------------------------------------------------------------------------- /packages/coin-aptos/src/transaction_builder/bcs/index.ts: -------------------------------------------------------------------------------- 1 | /*** 2 | * Copyright © Aptos Foundation 3 | *SPDX-License-Identifier: Apache-2.0 4 | * 5 | * https://raw.githubusercontent.com/aptos-labs/aptos-core/097ea73b4a78c0166f22a269f27e514dc895afb4/ecosystem/typescript/sdk/LICENSE 6 | * 7 | * */ 8 | 9 | export * from "./types"; 10 | export * from "./serializer"; 11 | export * from "./deserializer"; 12 | export * from "./helper"; 13 | -------------------------------------------------------------------------------- /packages/coin-aptos/src/transaction_builder/bcs/types.ts: -------------------------------------------------------------------------------- 1 | /*** 2 | * Copyright © Aptos Foundation 3 | *SPDX-License-Identifier: Apache-2.0 4 | * 5 | * https://raw.githubusercontent.com/aptos-labs/aptos-core/097ea73b4a78c0166f22a269f27e514dc895afb4/ecosystem/typescript/sdk/LICENSE 6 | * 7 | * */ 8 | 9 | export type Seq = T[]; 10 | 11 | export type Uint8 = number; 12 | export type Uint16 = number; 13 | export type Uint32 = number; 14 | export type Uint64 = bigint; 15 | export type Uint128 = bigint; 16 | export type Uint256 = bigint; 17 | export type AnyNumber = bigint | number; 18 | export type Bytes = Uint8Array; -------------------------------------------------------------------------------- /packages/coin-aptos/src/transaction_builder/index.ts: -------------------------------------------------------------------------------- 1 | /*** 2 | * Copyright © Aptos Foundation 3 | *SPDX-License-Identifier: Apache-2.0 4 | * 5 | * https://raw.githubusercontent.com/aptos-labs/aptos-core/097ea73b4a78c0166f22a269f27e514dc895afb4/ecosystem/typescript/sdk/LICENSE 6 | * 7 | * */ 8 | 9 | export * from "./builder"; 10 | export * as BCS from "./bcs"; 11 | export * as TxnBuilderTypes from "./aptos_types"; 12 | export * as MoveTypes from "./move_types"; 13 | 14 | -------------------------------------------------------------------------------- /packages/coin-aptos/src/utils/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./misc"; 2 | export * from "./memoize_decorator"; -------------------------------------------------------------------------------- /packages/coin-aptos/src/utils/misc.ts: -------------------------------------------------------------------------------- 1 | export const DEFAULT_MAX_GAS_AMOUNT = 200000; 2 | // Transaction expire timestamp 3 | export const DEFAULT_TXN_EXP_SEC_FROM_NOW = 20; 4 | // How long does SDK wait for txn to finish 5 | export const DEFAULT_TXN_TIMEOUT_SEC = 20; 6 | export const APTOS_COIN = "0x1::aptos_coin::AptosCoin"; -------------------------------------------------------------------------------- /packages/coin-aptos/src/v2/account/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./Ed25519Account"; 2 | export * from "./Account"; 3 | export * from "./SingleKeyAccount"; 4 | export * from "./MultiKeyAccount"; 5 | -------------------------------------------------------------------------------- /packages/coin-aptos/src/v2/api/aptosConfig.ts: -------------------------------------------------------------------------------- 1 | // Copyright © Aptos Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | import {Network} from "../utils/apiEndpoints"; 4 | import {AptosSettings} from "../types"; 5 | 6 | /** 7 | * This class holds the config information for the SDK client instance. 8 | */ 9 | export class AptosConfig { 10 | /** The Network that this SDK is associated with. Defaults to DEVNET */ 11 | readonly network: Network; 12 | 13 | readonly moveModule?: string; 14 | 15 | constructor(settings?: AptosSettings) { 16 | this.network = settings?.network ?? Network.DEVNET; 17 | this.moveModule = settings?.moveModule; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /packages/coin-aptos/src/v2/api/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright © Aptos Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | export * from "./aptosConfig"; 5 | export * from "./transaction"; 6 | export * from "./fungibleAsset"; 7 | -------------------------------------------------------------------------------- /packages/coin-aptos/src/v2/bcs/consts.ts: -------------------------------------------------------------------------------- 1 | // Copyright © Aptos Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { Uint8, Uint16, Uint32, Uint64, Uint128, Uint256 } from "../types"; 5 | 6 | // Upper bound values for uint8, uint16, uint64 etc. These are all derived as 7 | // 2^N - 1, where N is the number of bits in the type. 8 | export const MAX_U8_NUMBER: Uint8 = 255; 9 | export const MAX_U16_NUMBER: Uint16 = 65535; 10 | export const MAX_U32_NUMBER: Uint32 = 4294967295; 11 | export const MAX_U64_BIG_INT: Uint64 = 18446744073709551615n; 12 | export const MAX_U128_BIG_INT: Uint128 = 340282366920938463463374607431768211455n; 13 | export const MAX_U256_BIG_INT: Uint256 = 14 | 115792089237316195423570985008687907853269984665640564039457584007913129639935n; 15 | -------------------------------------------------------------------------------- /packages/coin-aptos/src/v2/bcs/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright © Aptos Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | export * from "./deserializer"; 5 | export * from "./serializer"; 6 | export * from "./serializable/entryFunctionBytes"; 7 | export * from "./serializable/fixedBytes"; 8 | export * from "./serializable/movePrimitives"; 9 | export * from "./serializable/moveStructs"; 10 | -------------------------------------------------------------------------------- /packages/coin-aptos/src/v2/core/account/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./utils"; 2 | -------------------------------------------------------------------------------- /packages/coin-aptos/src/v2/core/account/utils/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./address"; 2 | -------------------------------------------------------------------------------- /packages/coin-aptos/src/v2/core/crypto/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright © Aptos Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | export * from "./ed25519"; 5 | export * from "./hdKey"; 6 | export * from "./multiEd25519"; 7 | export * from "./multiKey"; 8 | export * from "./privateKey"; 9 | export * from "./publicKey"; 10 | export * from "./secp256k1"; 11 | export * from "./signature"; 12 | export * from "./singleKey"; 13 | -------------------------------------------------------------------------------- /packages/coin-aptos/src/v2/core/crypto/privateKey.ts: -------------------------------------------------------------------------------- 1 | import { HexInput } from "../../types"; 2 | import { PublicKey } from "./publicKey"; 3 | import { Signature } from "./signature"; 4 | 5 | /** 6 | * An abstract representation of a private key. 7 | * It is associated to a signature scheme and provides signing capabilities. 8 | */ 9 | export interface PrivateKey { 10 | /** 11 | * Sign the given message with the private key. 12 | * @param message in HexInput format 13 | */ 14 | sign(message: HexInput): Signature; 15 | 16 | /** 17 | * Derive the public key associated with the private key 18 | */ 19 | publicKey(): PublicKey; 20 | 21 | /** 22 | * Get the private key in bytes (Uint8Array). 23 | */ 24 | toUint8Array(): Uint8Array; 25 | } 26 | -------------------------------------------------------------------------------- /packages/coin-aptos/src/v2/core/crypto/utils.ts: -------------------------------------------------------------------------------- 1 | import { HexInput } from "../../types"; 2 | import { Hex } from "../hex"; 3 | 4 | /** 5 | * Helper function to convert a message to sign or to verify to a valid message input 6 | * 7 | * @param message a message as a string or Uint8Array 8 | * 9 | * @returns a valid HexInput - string or Uint8Array 10 | */ 11 | export const convertSigningMessage = (message: HexInput): HexInput => { 12 | // if message is of type string, verify it is a valid Hex string 13 | if (typeof message === "string") { 14 | const isValid = Hex.isValid(message); 15 | // If message is not a valid Hex string, convert it into a Buffer 16 | if (!isValid.valid) { 17 | return Buffer.from(message, "utf8"); 18 | } 19 | // If message is a valid Hex string, return it 20 | return message; 21 | } 22 | // message is a Uint8Array 23 | return message; 24 | }; 25 | -------------------------------------------------------------------------------- /packages/coin-aptos/src/v2/core/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright © Aptos Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | export * from "./accountAddress"; 5 | export * from "./authenticationKey"; 6 | export * from "./common"; 7 | export * from "./crypto"; 8 | export * from "./hex"; 9 | -------------------------------------------------------------------------------- /packages/coin-aptos/src/v2/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright © Aptos Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | export * from "./account"; 5 | export * from "./api"; 6 | export * from "./bcs"; 7 | export * from "./core"; 8 | export * from "./transactions"; 9 | export * from "./types"; 10 | export * from "./utils"; 11 | -------------------------------------------------------------------------------- /packages/coin-aptos/src/v2/transactions/authenticator/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright © Aptos Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | export * from "./account"; 5 | export * from "./transaction"; 6 | -------------------------------------------------------------------------------- /packages/coin-aptos/src/v2/transactions/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright © Aptos Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | export * from "./authenticator"; 5 | export * from "./instances"; 6 | export * from "./transactionBuilder"; 7 | export * from "./typeTag"; 8 | export * from "./typeTag/parser"; 9 | export * from "./types"; 10 | -------------------------------------------------------------------------------- /packages/coin-aptos/src/v2/transactions/instances/chainId.ts: -------------------------------------------------------------------------------- 1 | // Copyright © Aptos Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { Serializer, Serializable } from "../../bcs/serializer"; 5 | import { Deserializer } from "../../bcs/deserializer"; 6 | 7 | /** 8 | * Representation of a ChainId that can serialized and deserialized 9 | */ 10 | export class ChainId extends Serializable { 11 | public readonly chainId: number; 12 | 13 | constructor(chainId: number) { 14 | super(); 15 | this.chainId = chainId; 16 | } 17 | 18 | serialize(serializer: Serializer): void { 19 | serializer.serializeU8(this.chainId); 20 | } 21 | 22 | static deserialize(deserializer: Deserializer): ChainId { 23 | const chainId = deserializer.deserializeU8(); 24 | return new ChainId(chainId); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /packages/coin-aptos/src/v2/transactions/instances/identifier.ts: -------------------------------------------------------------------------------- 1 | // Copyright © Aptos Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { Deserializer } from "../../bcs/deserializer"; 5 | import { Serializable, Serializer } from "../../bcs/serializer"; 6 | 7 | /** 8 | * Representation of an Identifier that can serialized and deserialized. 9 | * We use Identifier to represent the module "name" in "ModuleId" and 10 | * the "function name" in "EntryFunction" 11 | */ 12 | export class Identifier extends Serializable { 13 | public identifier: string; 14 | 15 | constructor(identifier: string) { 16 | super(); 17 | this.identifier = identifier; 18 | } 19 | 20 | public serialize(serializer: Serializer): void { 21 | serializer.serializeStr(this.identifier); 22 | } 23 | 24 | static deserialize(deserializer: Deserializer): Identifier { 25 | const identifier = deserializer.deserializeStr(); 26 | return new Identifier(identifier); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /packages/coin-aptos/src/v2/transactions/instances/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright © Aptos Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | export * from "./chainId"; 5 | export * from "./identifier"; 6 | export * from "./moduleId"; 7 | export * from "./rawTransaction"; 8 | export * from "./rotationProofChallenge"; 9 | export * from "./signedTransaction"; 10 | export * from "./transactionArgument"; 11 | export * from "./transactionPayload"; 12 | export * from "./simpleTransaction"; 13 | export * from "./multiAgentTransaction"; 14 | -------------------------------------------------------------------------------- /packages/coin-aptos/src/v2/transactions/transactionBuilder/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright © Aptos Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | export * from "./helpers"; 5 | export * from "./transactionBuilder"; 6 | export * from "./remoteAbi"; 7 | export * from "./signingMessage"; -------------------------------------------------------------------------------- /packages/coin-aptos/src/v2/types/codegen.yaml: -------------------------------------------------------------------------------- 1 | overwrite: true 2 | documents: src/internal/queries/**/*.graphql 3 | schema: https://indexer.mainnet.aptoslabs.com/v1/graphql 4 | generates: 5 | src/types/generated/types.ts: 6 | plugins: 7 | - typescript 8 | config: 9 | skipTypename: true 10 | namingConvention: 11 | transformUnderscore: true 12 | src/types/generated/operations.ts: 13 | preset: import-types-preset 14 | presetConfig: 15 | typesPath: ./types 16 | plugins: 17 | - typescript-operations 18 | config: 19 | skipTypename: true 20 | namingConvention: 21 | transformUnderscore: true 22 | src/types/generated/queries.ts: 23 | preset: import-types-preset 24 | presetConfig: 25 | typesPath: ./operations 26 | plugins: 27 | - typescript-graphql-request 28 | config: 29 | documentMode: string 30 | documentVariableSuffix: "" 31 | skipTypename: true 32 | namingConvention: 33 | transformUnderscore: true 34 | -------------------------------------------------------------------------------- /packages/coin-aptos/src/v2/utils/apiEndpoints.ts: -------------------------------------------------------------------------------- 1 | // Copyright © Aptos Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | export enum Network { 4 | MAINNET = "mainnet", 5 | TESTNET = "testnet", 6 | DEVNET = "devnet", 7 | LOCAL = "local", 8 | CUSTOM = "custom", 9 | } 10 | 11 | export const NetworkToChainId: Record = { 12 | mainnet: 1, 13 | testnet: 2, 14 | }; 15 | 16 | export const NetworkToNetworkName: Record = { 17 | mainnet: Network.MAINNET, 18 | testnet: Network.TESTNET, 19 | devnet: Network.DEVNET, 20 | local: Network.LOCAL, 21 | custom: Network.CUSTOM, 22 | }; 23 | -------------------------------------------------------------------------------- /packages/coin-aptos/src/v2/utils/helpers.ts: -------------------------------------------------------------------------------- 1 | // Copyright © Aptos Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | /** 5 | * Sleep the current thread for the given amount of time 6 | * @param timeMs time in milliseconds to sleep 7 | */ 8 | export async function sleep(timeMs: number): Promise { 9 | return new Promise((resolve) => { 10 | setTimeout(resolve, timeMs); 11 | }); 12 | } 13 | -------------------------------------------------------------------------------- /packages/coin-aptos/src/v2/utils/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./apiEndpoints"; 2 | export * from "./const"; 3 | export * from "./normalizeBundle"; 4 | -------------------------------------------------------------------------------- /packages/coin-aptos/src/v2/utils/normalizeBundle.ts: -------------------------------------------------------------------------------- 1 | // Copyright © Aptos Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { Deserializer, Serializable } from "../bcs"; 5 | 6 | export type DeserializableClass = { 7 | deserialize(deserializer: Deserializer): T; 8 | }; 9 | 10 | /** 11 | * Utility function that serializes and deserialize an object back into the same bundle as the sdk. 12 | * This is a workaround to have the `instanceof` operator work when input objects come from a different 13 | * bundle. 14 | * @param cls The class of the object to normalize 15 | * @param value the instance to normalize 16 | */ 17 | export function normalizeBundle(cls: DeserializableClass, value: T) { 18 | const serializedBytes = value.bcsToBytes(); 19 | const deserializer = new Deserializer(serializedBytes); 20 | return cls.deserialize(deserializer); 21 | } 22 | -------------------------------------------------------------------------------- /packages/coin-aptos/src/v2/version.ts: -------------------------------------------------------------------------------- 1 | // Copyright © Aptos Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | /** 5 | * The current version of the SDK 6 | * 7 | * hardcoded for now, we would want to have it injected dynamically 8 | */ 9 | export const VERSION = "1.4.0"; 10 | -------------------------------------------------------------------------------- /packages/coin-aptos/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "allowJs": true, // Allows javascript files to be compiled 5 | "resolveJsonModule" : true, 6 | "outDir": "./dist", 7 | "rootDir": "./src", 8 | "experimentalDecorators": true 9 | }, 10 | "include": [ 11 | "src/**/*.ts", 12 | "src/**/*.js", 13 | "src/**/*.json" 14 | ], 15 | "exclude": [ 16 | "**/node_modules" 17 | ] 18 | } 19 | 20 | -------------------------------------------------------------------------------- /packages/coin-base/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 OKX.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /packages/coin-base/jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ 2 | module.exports = { 3 | preset: 'ts-jest', 4 | testEnvironment: 'node', 5 | }; -------------------------------------------------------------------------------- /packages/coin-base/src/basic/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./typeUtils" 2 | -------------------------------------------------------------------------------- /packages/coin-base/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./common"; 2 | export * from "./currency"; 3 | export * from "./error"; 4 | export * from "./wallet"; 5 | export * from "./basic" 6 | -------------------------------------------------------------------------------- /packages/coin-base/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./dist", 5 | "rootDir": "./src" 6 | }, 7 | "include": [ 8 | "src/**/*.ts" 9 | ], 10 | "exclude": [ 11 | "**/node_modules" 12 | ] 13 | } 14 | 15 | -------------------------------------------------------------------------------- /packages/coin-bitcoin/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 OKX.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /packages/coin-bitcoin/doc/images/rune_batch_mint.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/okx/js-wallet-sdk/03cd3f0c7f06caeb648e0cdb34c1c83abef17c24/packages/coin-bitcoin/doc/images/rune_batch_mint.png -------------------------------------------------------------------------------- /packages/coin-bitcoin/doc/images/rune_serial_mint.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/okx/js-wallet-sdk/03cd3f0c7f06caeb648e0cdb34c1c83abef17c24/packages/coin-bitcoin/doc/images/rune_serial_mint.png -------------------------------------------------------------------------------- /packages/coin-bitcoin/jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ 2 | module.exports = { 3 | preset: 'ts-jest', 4 | testEnvironment: 'node', 5 | }; -------------------------------------------------------------------------------- /packages/coin-bitcoin/src/bitcoincash/validation.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The following methods are based on `Emilio Almansi`, thanks for their work 3 | * @license 4 | * https://github.com/ealmansi/cashaddrjs 5 | * Copyright (c) 2017-2020 Emilio Almansi 6 | * Distributed under the MIT software license, see the accompanying 7 | * file LICENSE or http://www.opensource.org/licenses/mit-license.php. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | /** 13 | * Validation utility. 14 | * 15 | * @module validation 16 | */ 17 | 18 | /** 19 | * Validates a given condition, throwing a {@link ValidationError} if 20 | * the given condition does not hold. 21 | * 22 | * @static 23 | * @param {boolean} condition Condition to validate. 24 | * @param {string} message Error message in case the condition does not hold. 25 | */ 26 | export function validate(condition: any, message: string) { 27 | if (!condition) { 28 | throw new Error(message); 29 | } 30 | } -------------------------------------------------------------------------------- /packages/coin-bitcoin/src/bitcoinjs-lib/bip174/converter/global/unsignedTx.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The following methods are based on `bitcoinjs`, thanks for their work 3 | * https://github.com/bitcoinjs/bitcoinjs-lib 4 | */ 5 | import { KeyValue, Transaction } from '../../interfaces'; 6 | import { GlobalTypes } from '../../typeFields'; 7 | 8 | export function encode(data: Transaction): KeyValue { 9 | return { 10 | key: Buffer.from([GlobalTypes.UNSIGNED_TX]), 11 | value: data.toBuffer(), 12 | }; 13 | } 14 | -------------------------------------------------------------------------------- /packages/coin-bitcoin/src/bitcoinjs-lib/bip174/converter/input/nonWitnessUtxo.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The following methods are based on `bitcoinjs`, thanks for their work 3 | * https://github.com/bitcoinjs/bitcoinjs-lib 4 | */ 5 | import { KeyValue, NonWitnessUtxo } from '../../interfaces'; 6 | import { InputTypes } from '../../typeFields'; 7 | 8 | export function decode(keyVal: KeyValue): NonWitnessUtxo { 9 | if (keyVal.key[0] !== InputTypes.NON_WITNESS_UTXO) { 10 | throw new Error( 11 | 'Decode Error: could not decode nonWitnessUtxo with key 0x' + 12 | keyVal.key.toString('hex'), 13 | ); 14 | } 15 | return keyVal.value; 16 | } 17 | 18 | export function encode(data: NonWitnessUtxo): KeyValue { 19 | return { 20 | key: Buffer.from([InputTypes.NON_WITNESS_UTXO]), 21 | value: data, 22 | }; 23 | } 24 | 25 | export const expected = 'Buffer'; 26 | export function check(data: any): data is NonWitnessUtxo { 27 | return Buffer.isBuffer(data); 28 | } 29 | 30 | export function canAdd(currentData: any, newData: any): boolean { 31 | return !!currentData && !!newData && currentData.nonWitnessUtxo === undefined; 32 | } 33 | -------------------------------------------------------------------------------- /packages/coin-bitcoin/src/bitcoinjs-lib/bip174/converter/shared/checkPubkey.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The following methods are based on `bitcoinjs`, thanks for their work 3 | * https://github.com/bitcoinjs/bitcoinjs-lib 4 | */ 5 | import { KeyValue } from '../../interfaces'; 6 | 7 | export function makeChecker( 8 | pubkeyTypes: number[], 9 | ): (keyVal: KeyValue) => Buffer | undefined { 10 | return checkPubkey; 11 | function checkPubkey(keyVal: KeyValue): Buffer | undefined { 12 | let pubkey: Buffer | undefined; 13 | if (pubkeyTypes.includes(keyVal.key[0])) { 14 | pubkey = keyVal.key.slice(1); 15 | if ( 16 | !(pubkey.length === 33 || pubkey.length === 65) || 17 | ![2, 3, 4].includes(pubkey[0]) 18 | ) { 19 | throw new Error( 20 | 'Format Error: invalid pubkey in key 0x' + keyVal.key.toString('hex'), 21 | ); 22 | } 23 | } 24 | return pubkey; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /packages/coin-bitcoin/src/bitcoinjs-lib/bip174/parser/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The following methods are based on `bitcoinjs`, thanks for their work 3 | * https://github.com/bitcoinjs/bitcoinjs-lib 4 | */ 5 | import { PsbtGlobal, PsbtInput, PsbtOutput } from '../interfaces'; 6 | 7 | export * from './fromBuffer'; 8 | export * from './toBuffer'; 9 | 10 | export interface PsbtAttributes { 11 | globalMap: PsbtGlobal; 12 | inputs: PsbtInput[]; 13 | outputs: PsbtOutput[]; 14 | } 15 | -------------------------------------------------------------------------------- /packages/coin-bitcoin/src/bitcoinjs-lib/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The following methods are based on `bitcoinjs`, thanks for their work 3 | * https://github.com/bitcoinjs/bitcoinjs-lib 4 | */ 5 | import * as address from './address'; 6 | import * as crypto from './crypto'; 7 | import * as networks from './networks'; 8 | import * as payments from './payments'; 9 | import * as script from './script'; 10 | import * as bip0322 from './bip0322'; 11 | import * as psbt from './psbt'; 12 | 13 | export { address, crypto, networks, payments, script, bip0322, psbt }; 14 | export { Transaction } from './transaction'; 15 | export { Network } from './networks'; 16 | export { BufferWriter } from './bufferutils'; 17 | -------------------------------------------------------------------------------- /packages/coin-bitcoin/src/bitcoinjs-lib/payments/lazy.ts: -------------------------------------------------------------------------------- 1 | export function prop(object: {}, name: string, f: () => any): void { 2 | Object.defineProperty(object, name, { 3 | configurable: true, 4 | enumerable: true, 5 | get(): any { 6 | const _value = f.call(this); 7 | this[name] = _value; 8 | return _value; 9 | }, 10 | set(_value: any): void { 11 | Object.defineProperty(this, name, { 12 | configurable: true, 13 | enumerable: true, 14 | value: _value, 15 | writable: true, 16 | }); 17 | }, 18 | }); 19 | } 20 | 21 | export function value(f: () => T): () => T { 22 | let _value: T; 23 | return (): T => { 24 | if (_value !== undefined) return _value; 25 | _value = f(); 26 | return _value; 27 | }; 28 | } 29 | -------------------------------------------------------------------------------- /packages/coin-bitcoin/src/bitcoinjs-lib/varuint.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The following methods are based on `bitcoinjs`, thanks for their work 3 | * https://github.com/bitcoinjs/bitcoinjs-lib 4 | */ 5 | /// 6 | interface Encode { 7 | (num: number, buffer?: Buffer, offset?: number): Buffer; 8 | bytes: number; 9 | } 10 | declare const encode: Encode; 11 | interface Decode { 12 | (buffer: Buffer, offset?: number): number; 13 | bytes: number; 14 | } 15 | declare const decode: Decode; 16 | declare function encodingLength(num: number): number; 17 | export { encode, decode, encodingLength }; -------------------------------------------------------------------------------- /packages/coin-bitcoin/src/cat20/common/btc.ts: -------------------------------------------------------------------------------- 1 | // eslint-disable-next-line @typescript-eslint/ban-ts-comment 2 | // @ts-ignore 3 | // import btc = require('bitcore-lib-inquisition'); 4 | import {btc} from '@cat-protocol/cat-smartcontracts' 5 | export {btc}; 6 | -------------------------------------------------------------------------------- /packages/coin-bitcoin/src/cat20/common/cat20Enum.ts: -------------------------------------------------------------------------------- 1 | export enum CatAddressType { 2 | P2WPKH = 'p2wpkh', 3 | P2TR = 'p2tr', 4 | } 5 | 6 | export enum SupportedNetwork { 7 | btcSignet = 'btc-signet', 8 | fractalMainnet = 'fractal-mainnet', 9 | fractalTestnet = 'fractal-testnet' 10 | } 11 | 12 | 13 | export enum Postage { 14 | METADATA_POSTAGE = 546, 15 | GUARD_POSTAGE = 332, 16 | MINTER_POSTAGE = 331, 17 | TOKEN_POSTAGE = 330, 18 | } 19 | 20 | export const CHANGE_MIN_POSTAGE = 546; 21 | 22 | export enum MinterType { 23 | OPEN_MINTER_V1 = '21cbd2e538f2b6cc40ee180e174f1e25', 24 | OPEN_MINTER_V2 = 'a6c2e92d74a23c07bb6220b676c6cb9b', 25 | UNKOWN_MINTER = 'unkown_minter', 26 | } 27 | -------------------------------------------------------------------------------- /packages/coin-bitcoin/src/cat20/common/common.ts: -------------------------------------------------------------------------------- 1 | import {TokenContract} from "./contract"; 2 | 3 | 4 | export type TokenPrevTx = { 5 | prevTx: string, 6 | prevPrevTx: string, 7 | } 8 | 9 | // transfer 10 | export interface CatTransferParams 11 | { 12 | tokenMetadata: string 13 | feeInputs: UtxoInput[] 14 | feeRate: number 15 | tokens: string 16 | changeAddress: string 17 | toAddress: string 18 | tokenAmount: string 19 | tokenPrevTxs: TokenPrevTx[] 20 | verifyScript?: boolean 21 | guard? : string 22 | publicKey?: string 23 | signData?: SignData 24 | estimateFee?: boolean 25 | } 26 | 27 | export type UtxoInput = { 28 | txId: string 29 | vOut: number 30 | amount: number // min unit: satoshi 31 | address?: string 32 | } 33 | 34 | // sighashes to be signed or signatures after signing 35 | export type SignData = { 36 | merge: string[], 37 | commit: string[], 38 | reveal: string[], 39 | } -------------------------------------------------------------------------------- /packages/coin-bitcoin/src/cat20/common/contract.ts: -------------------------------------------------------------------------------- 1 | import { 2 | CAT20State, 3 | GuardConstState, 4 | OpenMinterState, 5 | OpenMinterV2State, 6 | ProtocolState 7 | } from '@cat-protocol/cat-smartcontracts'; 8 | import {UTXO} from 'scrypt-ts'; 9 | 10 | export interface ContractState { 11 | protocolState: ProtocolState; 12 | 13 | data: T; 14 | } 15 | 16 | export interface Contract { 17 | utxo: UTXO; 18 | state: ContractState; 19 | } 20 | 21 | export type OpenMinterContract = Contract; 22 | 23 | export type TokenContract = Contract; 24 | 25 | export type GuardContract = Contract; 26 | -------------------------------------------------------------------------------- /packages/coin-bitcoin/src/cat20/common/index.ts: -------------------------------------------------------------------------------- 1 | export * from './metadata'; 2 | export * from './cat20Enum'; 3 | export * from './contract'; 4 | export * from './minterFinder'; 5 | export * from './btc'; 6 | export * from './common' 7 | -------------------------------------------------------------------------------- /packages/coin-bitcoin/src/cat20/common/metadata.ts: -------------------------------------------------------------------------------- 1 | export interface TokenInfo { 2 | name: string; 3 | symbol: string; 4 | decimals: number; 5 | minterMd5: string; 6 | } 7 | 8 | const INT32_MAX = 2147483647n; 9 | 10 | export const MAX_TOTAL_SUPPLY = INT32_MAX; 11 | 12 | export interface ClosedMinterTokenInfo extends TokenInfo { 13 | } 14 | 15 | export interface OpenMinterTokenInfo extends TokenInfo { 16 | max: bigint; 17 | limit: bigint; 18 | premine: bigint; 19 | } 20 | 21 | export interface TokenMetadata { 22 | info: TokenInfo; 23 | tokenId: string; 24 | /** token p2tr address */ 25 | tokenAddr: string; 26 | /** minter p2tr address */ 27 | minterAddr: string; 28 | genesisTxid: string; 29 | revealTxid: string; 30 | timestamp: number; 31 | } 32 | -------------------------------------------------------------------------------- /packages/coin-bitcoin/src/cat20/common/minterFinder.ts: -------------------------------------------------------------------------------- 1 | import {MinterType} from "./cat20Enum"; 2 | 3 | export function isOpenMinter(md5: string) { 4 | return MinterType.OPEN_MINTER_V1 === md5 || MinterType.OPEN_MINTER_V2 === md5; 5 | } 6 | -------------------------------------------------------------------------------- /packages/coin-bitcoin/src/cat20/index.ts: -------------------------------------------------------------------------------- 1 | export * from './common' 2 | export * from './transaction' 3 | export * from './utils' 4 | -------------------------------------------------------------------------------- /packages/coin-bitcoin/src/cat20/transaction/index.ts: -------------------------------------------------------------------------------- 1 | export * from './functions' 2 | export * from './merge' 3 | export * from './transfer' 4 | -------------------------------------------------------------------------------- /packages/coin-bitcoin/src/cat20/transaction/merge.ts: -------------------------------------------------------------------------------- 1 | import {UTXO} from "scrypt-ts"; 2 | import {EcKeyService} from "../utils"; 3 | import {btc} from "../common"; 4 | 5 | export function mergeFee( 6 | ecKey: EcKeyService, 7 | feeUtxos: UTXO[], 8 | feeRate: number, 9 | ){ 10 | 11 | const address = ecKey.getAddress(); 12 | const mergeTx = new btc.Transaction() 13 | .from(feeUtxos) 14 | .feePerByte(feeRate) 15 | .change(address); 16 | 17 | if (mergeTx.getChangeOutput() === null) { 18 | throw new Error('Insufficient satoshis balance!'); 19 | } 20 | const output = mergeTx.outputs[0] 21 | output.satoshis -= 1; 22 | 23 | if (ecKey.hasPrivateKey()) { 24 | ecKey.signTx(mergeTx); 25 | } 26 | 27 | const mergedFeeUtxo: UTXO = { 28 | address, 29 | txId: mergeTx.id, 30 | outputIndex: 0, 31 | script: output.script, 32 | satoshis: output.satoshis, 33 | } 34 | 35 | return { 36 | mergeTx, 37 | feeUtxo: mergedFeeUtxo, 38 | } 39 | } -------------------------------------------------------------------------------- /packages/coin-bitcoin/src/cat20/utils/index.ts: -------------------------------------------------------------------------------- 1 | export * from './eckey'; 2 | export * from './paramsUtils'; 3 | export * from './prevTx'; 4 | export * from './utils'; 5 | export * from './utxo'; 6 | 7 | -------------------------------------------------------------------------------- /packages/coin-bitcoin/src/cat20/utils/utxo.ts: -------------------------------------------------------------------------------- 1 | import {UTXO} from 'scrypt-ts'; 2 | 3 | 4 | export function pickLargeFeeUtxo(feeUtxos: Array): UTXO { 5 | let max = feeUtxos[0]; 6 | 7 | for (const utxo of feeUtxos) { 8 | if (utxo.satoshis > max.satoshis) { 9 | max = utxo; 10 | } 11 | } 12 | return max; 13 | } 14 | -------------------------------------------------------------------------------- /packages/coin-bitcoin/src/common.ts: -------------------------------------------------------------------------------- 1 | export enum BtcXrcTypes { 2 | INSCRIBE = 1, 3 | PSBT = 2, 4 | PSBT_MPC_UNSIGNED_LIST = 21, 5 | PSBT_MPC_SIGNED_LIST = 22, 6 | PSBT_MPC_UNSIGNED_BUY = 23, 7 | PSBT_MPC_SIGNED_BUY = 24, 8 | PSBT_MPC_UNSIGNED = 25, 9 | PSBT_MPC_SIGNED = 26, 10 | PSBT_RUNEMAIN = 27, 11 | PSBT_KEY_SCRIPT_PATH = 3, 12 | PSBT_KEY_SCRIPT_PATH_BATCH = 4, 13 | SRC20 = 101, 14 | RUNE = 102, 15 | RUNEMAIN = 103, 16 | PSBT_DEODE = 104, 17 | ARC20 = 114, 18 | CAT20 = 115, 19 | } -------------------------------------------------------------------------------- /packages/coin-bitcoin/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./bitcoinjs-lib" 2 | export * from "./bitcoincash" 3 | export * from "./txBuild" 4 | export * from "./type" 5 | export * as wif from "./wif" 6 | export * from "./src20" 7 | export * from "./inscribe" 8 | // @ts-ignore 9 | export * from "./inscribe_refund_fee" 10 | export * from "./doginals" 11 | export * from "./psbtSign" 12 | export * as message from "./message" 13 | export * from "./wallet/index" 14 | export * from "./onekey" 15 | export * from "./common" 16 | export * from "./cat20" 17 | export * from "./taproot" -------------------------------------------------------------------------------- /packages/coin-bitcoin/src/wallet/CatWallet.ts: -------------------------------------------------------------------------------- 1 | import { SignTxParams} from "@okxweb3/coin-base"; 2 | import { BtcWallet } from "./BtcWallet"; 3 | import { transfer } from "../cat20" 4 | 5 | export class CatWallet extends BtcWallet { 6 | 7 | async signTransaction(param: SignTxParams): Promise { 8 | try { 9 | const tx = await transfer(param) 10 | return Promise.resolve(tx); 11 | } catch (e) { 12 | return Promise.reject(e); 13 | } 14 | } 15 | 16 | async estimateFee(param: SignTxParams): Promise { 17 | try { 18 | param.data.estimateFee = true 19 | const fees = await transfer(param) 20 | return Promise.resolve(fees); 21 | } catch (e) { 22 | return Promise.reject(e); 23 | } 24 | } 25 | } 26 | // fractal testnet uses same network info as bitcoin & fractal mainnet 27 | // export class CatTestWallet extends CatWallet { 28 | // network() { 29 | // return bitcoin.networks.testnet; 30 | // } 31 | // } 32 | -------------------------------------------------------------------------------- /packages/coin-bitcoin/src/wallet/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./BtcWallet" 2 | export * from "./BchWallet" 3 | export * from "./BsvWallet" 4 | export * from "./DogeWallet" 5 | export * from "./LtcWallet" 6 | export * from "./UsdtWallet" 7 | export * from "./RuneWallet" 8 | export * from "./RuneMainWallet" 9 | export * from "./AtomicalWallet" 10 | export * from "./CatWallet" 11 | -------------------------------------------------------------------------------- /packages/coin-bitcoin/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "allowJs": true, 5 | // Allows javascript files to be compiled 6 | "resolveJsonModule": true, 7 | "outDir": "./dist", 8 | "types": [ 9 | "@types/jest" 10 | ], 11 | "rootDir": "./src" 12 | }, 13 | "include": [ 14 | "src/**/*.ts", 15 | "src/**/*.js", 16 | "src/**/*.json" 17 | ], 18 | "exclude": [ 19 | "**/node_modules" 20 | ] 21 | } 22 | 23 | -------------------------------------------------------------------------------- /packages/coin-cardano/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | # Change Log 3 | 4 | All notable changes to this project will be documented in this file. 5 | 6 | # [1.1.0](https://github.com/okx/js-wallet-sdk)(2024-01-15) 7 | 8 | ### New Features 9 | 10 | - **coin-cardano:** support signCommonMsg ([](https://github.com/okx/js-wallet-sdk)) 11 | 12 | # [1.0.6](https://github.com/okx/js-wallet-sdk) (2024-08-20) 13 | 14 | ### Fix 15 | 16 | - **coin-cardano:** upgrade private key verification ([](https://github.com/okx/js-wallet-sdk)) 17 | 18 | 19 | # [1.0.3](https://github.com/okx/js-wallet-sdk) (2024-07-01) 20 | 21 | ### Fix 22 | 23 | - **coin-cardano:** update library for private key path derivation 24 | 25 | # [1.0.2](https://github.com/okx/js-wallet-sdk) (2024-06-13) 26 | 27 | ### Fix 28 | 29 | - **coin-cardano:** support derive private key for multi accounts 30 | 31 | 32 | # [1.0.1](https://github.com/okx/js-wallet-sdk) (2023-11-15) 33 | 34 | ### Feature 35 | 36 | - **coin-cardano:** support signMessage and signRawTx ([25](https://github.com/okx/js-wallet-sdk/pull/25)) 37 | -------------------------------------------------------------------------------- /packages/coin-cardano/jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ 2 | module.exports = { 3 | preset: 'ts-jest', 4 | testEnvironment: 'node', 5 | }; -------------------------------------------------------------------------------- /packages/coin-cardano/src/cardano-sdk/core/Cardano/Address/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Address'; 2 | export * from './BaseAddress'; -------------------------------------------------------------------------------- /packages/coin-cardano/src/cardano-sdk/core/Cardano/index.ts: -------------------------------------------------------------------------------- 1 | export * from './ChainId'; 2 | export * from './Address'; -------------------------------------------------------------------------------- /packages/coin-cardano/src/cardano-sdk/crypto/Bip32/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Bip32PrivateKey'; 2 | export * from './arithmetic'; 3 | -------------------------------------------------------------------------------- /packages/coin-cardano/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./account"; 2 | export * from "./AdaWallet"; 3 | export * from "./transaction"; 4 | export { default as Loader } from "./libs/loader"; 5 | -------------------------------------------------------------------------------- /packages/coin-cardano/src/libs/cardano_message_signing/cardano_message_signing_bg.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/okx/js-wallet-sdk/03cd3f0c7f06caeb648e0cdb34c1c83abef17c24/packages/coin-cardano/src/libs/cardano_message_signing/cardano_message_signing_bg.wasm -------------------------------------------------------------------------------- /packages/coin-cardano/src/libs/cardano_multiplatform_lib/cardano_multiplatform_lib_bg.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/okx/js-wallet-sdk/03cd3f0c7f06caeb648e0cdb34c1c83abef17c24/packages/coin-cardano/src/libs/cardano_multiplatform_lib/cardano_multiplatform_lib_bg.wasm -------------------------------------------------------------------------------- /packages/coin-cardano/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "allowJs": true, // Allows javascript files to be compiled 5 | "resolveJsonModule" : true, 6 | "outDir": "./dist", 7 | "rootDir": "./src", 8 | "experimentalDecorators": true 9 | }, 10 | "include": [ 11 | "src/**/*.ts", 12 | "src/**/*.js", 13 | "src/**/*.json" 14 | ], 15 | "exclude": [ 16 | "**/node_modules" 17 | ] 18 | } 19 | 20 | -------------------------------------------------------------------------------- /packages/coin-cosmos/jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ 2 | module.exports = { 3 | preset: 'ts-jest', 4 | testEnvironment: 'node', 5 | }; -------------------------------------------------------------------------------- /packages/coin-cosmos/src/cosmwasm/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./wasm/v1/tx.amino" 2 | export * from "./registry" -------------------------------------------------------------------------------- /packages/coin-cosmos/src/kava/aminotypes.ts: -------------------------------------------------------------------------------- 1 | import {AuctionAminoConverter} from "./auction/v1beta1/tx.amino"; 2 | import {HardAminoConverter} from "./hard/v1beta1/tx.amino"; 3 | import {SwapAminoConverter} from "./swap/v1beta1/tx.amino"; 4 | 5 | export const KavaAminoConverters = { 6 | ...AuctionAminoConverter, 7 | ...HardAminoConverter, 8 | ...SwapAminoConverter 9 | } -------------------------------------------------------------------------------- /packages/coin-cosmos/src/kava/auction/v1beta1/tx.amino.ts: -------------------------------------------------------------------------------- 1 | import { MsgPlaceBid } from "./tx"; 2 | export const AuctionAminoConverter = { 3 | "/kava.auction.v1beta1.MsgPlaceBid": { 4 | aminoType: "auction/MsgPlaceBid", 5 | toAmino: MsgPlaceBid.toAmino, 6 | fromAmino: MsgPlaceBid.fromAmino 7 | } 8 | }; -------------------------------------------------------------------------------- /packages/coin-cosmos/src/kava/hard/v1beta1/tx.amino.ts: -------------------------------------------------------------------------------- 1 | import { MsgDeposit, MsgWithdraw, MsgBorrow, MsgRepay, MsgLiquidate } from "./tx"; 2 | export const HardAminoConverter = { 3 | "/kava.hard.v1beta1.MsgDeposit": { 4 | aminoType: "hard/MsgDeposit", 5 | toAmino: MsgDeposit.toAmino, 6 | fromAmino: MsgDeposit.fromAmino 7 | }, 8 | "/kava.hard.v1beta1.MsgWithdraw": { 9 | aminoType: "hard/MsgWithdraw", 10 | toAmino: MsgWithdraw.toAmino, 11 | fromAmino: MsgWithdraw.fromAmino 12 | }, 13 | "/kava.hard.v1beta1.MsgBorrow": { 14 | aminoType: "hard/MsgBorrow", 15 | toAmino: MsgBorrow.toAmino, 16 | fromAmino: MsgBorrow.fromAmino 17 | }, 18 | "/kava.hard.v1beta1.MsgRepay": { 19 | aminoType: "hard/MsgRepay", 20 | toAmino: MsgRepay.toAmino, 21 | fromAmino: MsgRepay.fromAmino 22 | }, 23 | "/kava.hard.v1beta1.MsgLiquidate": { 24 | aminoType: "hard/MsgLiquidate", 25 | toAmino: MsgLiquidate.toAmino, 26 | fromAmino: MsgLiquidate.fromAmino 27 | } 28 | }; -------------------------------------------------------------------------------- /packages/coin-cosmos/src/kava/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./registry" 2 | export * from "./aminotypes" -------------------------------------------------------------------------------- /packages/coin-cosmos/src/kava/swap/v1beta1/tx.amino.ts: -------------------------------------------------------------------------------- 1 | import { MsgDeposit, MsgWithdraw, MsgSwapExactForTokens, MsgSwapForExactTokens } from "./tx"; 2 | export const SwapAminoConverter = { 3 | "/kava.swap.v1beta1.MsgDeposit": { 4 | aminoType: "swap/MsgDeposit", 5 | toAmino: MsgDeposit.toAmino, 6 | fromAmino: MsgDeposit.fromAmino 7 | }, 8 | "/kava.swap.v1beta1.MsgWithdraw": { 9 | aminoType: "swap/MsgWithdraw", 10 | toAmino: MsgWithdraw.toAmino, 11 | fromAmino: MsgWithdraw.fromAmino 12 | }, 13 | "/kava.swap.v1beta1.MsgSwapExactForTokens": { 14 | aminoType: "swap/MsgSwapExactForTokens", 15 | toAmino: MsgSwapExactForTokens.toAmino, 16 | fromAmino: MsgSwapExactForTokens.fromAmino 17 | }, 18 | "/kava.swap.v1beta1.MsgSwapForExactTokens": { 19 | aminoType: "swap/MsgSwapForExactTokens", 20 | toAmino: MsgSwapForExactTokens.toAmino, 21 | fromAmino: MsgSwapForExactTokens.fromAmino 22 | } 23 | }; -------------------------------------------------------------------------------- /packages/coin-cosmos/src/osmosis/aminotypes.ts: -------------------------------------------------------------------------------- 1 | import {GammAminoConverters} from "./gamm/v1beta1/aminotypes"; 2 | import {PoolManagerAminoConverter} from "./poolmanager/v1beta1/tx.amino"; 3 | import {LockupAminoConverter} from "./lockup/tx.amino"; 4 | import {SuperfluidAminoConverter} from "./superfluid/tx.amino"; 5 | import {TokenFactoryAminoConverter} from "./tokenfactory/v1beta1/tx.amino"; 6 | 7 | export const OsmosisAminoConverters = { 8 | ...GammAminoConverters, 9 | ...LockupAminoConverter, 10 | ...PoolManagerAminoConverter, 11 | ...SuperfluidAminoConverter, 12 | ...TokenFactoryAminoConverter 13 | } 14 | -------------------------------------------------------------------------------- /packages/coin-cosmos/src/osmosis/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./registry" 2 | export * from "./aminotypes" -------------------------------------------------------------------------------- /packages/coin-cosmos/src/types/gogoproto/gogo.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | import {Long} from "@okxweb3/crypto-lib"; 3 | import { _m0 } from "@okxweb3/crypto-lib"; 4 | 5 | export const protobufPackage = "gogoproto"; 6 | 7 | if (_m0.util.Long !== Long) { 8 | _m0.util.Long = Long as any; 9 | _m0.configure(); 10 | } 11 | -------------------------------------------------------------------------------- /packages/coin-cosmos/src/types/google/api/annotations.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | import {Long} from "@okxweb3/crypto-lib"; 3 | import { _m0 } from "@okxweb3/crypto-lib"; 4 | 5 | export const protobufPackage = "google.api"; 6 | 7 | if (_m0.util.Long !== Long) { 8 | _m0.util.Long = Long as any; 9 | _m0.configure(); 10 | } 11 | -------------------------------------------------------------------------------- /packages/coin-cosmos/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "allowJs": true, // allow build javascript files 5 | "resolveJsonModule" : true, 6 | "outDir": "./dist", 7 | "rootDir": "./src" 8 | }, 9 | "include": [ 10 | "src/**/*.ts", 11 | "src/**/*.js", 12 | "src/**/*.json" 13 | ], 14 | "exclude": [ 15 | "**/node_modules" 16 | ] 17 | } 18 | 19 | -------------------------------------------------------------------------------- /packages/coin-eos/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | # Change Log 3 | 4 | All notable changes to this project will be documented in this file. 5 | 6 | # [1.1.0](https://github.com/okx/js-wallet-sdk)(2024-01-15) 7 | 8 | ### New Features 9 | 10 | - **coin-eos:** support signCommonMsg ([](https://github.com/okx/js-wallet-sdk)) 11 | 12 | # [1.0.1](https://github.com/okx/js-wallet-sdk) (2023-12-21) 13 | 14 | ### Feature 15 | 16 | - **coin-eos:** update for wax or eos token ([49](https://github.com/okx/js-wallet-sdk/pull/49)) 17 | -------------------------------------------------------------------------------- /packages/coin-eos/jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ 2 | module.exports = { 3 | preset: 'ts-jest', 4 | testEnvironment: 'node', 5 | }; -------------------------------------------------------------------------------- /packages/coin-eos/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./api" 2 | export * from "./txBuilder" 3 | export * from "./types" 4 | export * from "./action" 5 | export * from "./numeric" 6 | export * from "./EosWallet" 7 | -------------------------------------------------------------------------------- /packages/coin-eos/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "resolveJsonModule" : true, 5 | "outDir": "./dist", 6 | "rootDir": "./src" 7 | }, 8 | "include": [ 9 | "src/**/*.ts", 10 | "src/**/*.json" 11 | ], 12 | "exclude": [ 13 | "**/node_modules" 14 | ] 15 | } 16 | 17 | -------------------------------------------------------------------------------- /packages/coin-ethereum/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | # Change Log 3 | 4 | All notable changes to this project will be documented in this file. 5 | 6 | # [1.1.1](https://github.com/okx/js-wallet-sdk)(2025-03-24) 7 | 8 | ### New Features 9 | 10 | - **coin-ethereum:** support EIP-7702 11 | 12 | # [1.1.0](https://github.com/okx/js-wallet-sdk)(2024-01-15) 13 | 14 | ### New Features 15 | 16 | - **coin-ethereum:** support signCommonMsg ([](https://github.com/okx/js-wallet-sdk)) 17 | - 18 | # [1.0.5](https://github.com/okx/js-wallet-sdk) (2024-08-20) 19 | 20 | ### Fix 21 | 22 | - **coin-ethereum:** upgrade private key verification ([](https://github.com/okx/js-wallet-sdk)) 23 | 24 | 25 | # [1.0.1](https://github.com/okx/js-wallet-sdk) (2023-10-31) 26 | 27 | ### Bug Fixes 28 | 29 | - **coin-ethereum:** signMessage supports more data types ([ef53b09](https://github.com/okx/js-wallet-sdk/commit/ef53b095efd880b2b863e8780933754a39f78f10)) 30 | -------------------------------------------------------------------------------- /packages/coin-ethereum/jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ 2 | module.exports = { 3 | preset: 'ts-jest', 4 | testEnvironment: 'node', 5 | }; -------------------------------------------------------------------------------- /packages/coin-ethereum/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./api" 2 | export * from "./message" 3 | export * from "./sdk" 4 | export * from "./EthWallet" 5 | -------------------------------------------------------------------------------- /packages/coin-ethereum/src/sdk/ethereumjs-tx/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The following methods are based on `ethereumjs/tx`, thanks for their work 3 | * https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/tx 4 | * Distributed under the Mozilla Public License Version 2.0 software license, see the accompanying 5 | * file LICENSE or https://opensource.org/license/mpl-2-0/. 6 | */ 7 | 8 | export { default as Transaction } from './legacyTransaction' 9 | export { default as AccessListEIP2930Transaction } from './eip2930Transaction' 10 | export { default as TransactionFactory } from './transactionFactory' 11 | export { default as FeeMarketEIP1559Transaction } from './eip1559Transaction' 12 | export { default as EOACodeEIP7702Transaction } from './eip7702Transaction' 13 | 14 | export * from './types' 15 | -------------------------------------------------------------------------------- /packages/coin-ethereum/src/sdk/ethereumjs-util/externals.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The following methods are based on `ethereumjs/util`, thanks for their work 3 | * https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/util 4 | * Distributed under the Mozilla Public License Version 2.0 software license, see the accompanying 5 | * file LICENSE or https://opensource.org/license/mpl-2-0/. 6 | */ 7 | 8 | import { BN } from '@okxweb3/crypto-lib'; 9 | import * as rlp from './rlp'; 10 | export { BN }; 11 | export { rlp }; 12 | -------------------------------------------------------------------------------- /packages/coin-ethereum/src/sdk/ethereumjs-util/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The following methods are based on `ethereumjs/util`, thanks for their work 3 | * https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/util 4 | * Distributed under the Mozilla Public License Version 2.0 software license, see the accompanying 5 | * file LICENSE or https://opensource.org/license/mpl-2-0/. 6 | */ 7 | 8 | /** 9 | * Constants 10 | */ 11 | export * from './constants' 12 | 13 | /** 14 | * Account class and helper functions 15 | */ 16 | export * from './account' 17 | 18 | /** 19 | * Address type 20 | */ 21 | export * from './address' 22 | 23 | /** 24 | * Hash functions 25 | */ 26 | export * from './hash' 27 | 28 | /** 29 | * ECDSA signature 30 | */ 31 | export * from './signature' 32 | 33 | /** 34 | * Utilities for manipulating Buffers, byte arrays, etc. 35 | */ 36 | export * from './bytes' 37 | 38 | /** 39 | * Helpful TypeScript types 40 | */ 41 | export * from './types' 42 | 43 | 44 | export * as rlp from './rlp' 45 | 46 | export * from './util' 47 | 48 | 49 | -------------------------------------------------------------------------------- /packages/coin-ethereum/src/sdk/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./ethereumjs-util" 2 | export * from "./ethereumjs-tx" 3 | export * as sigUtil from "./eth-sig-util" -------------------------------------------------------------------------------- /packages/coin-ethereum/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "allowJs": true, 5 | "resolveJsonModule" : true, 6 | "outDir": "./dist", 7 | "rootDir": "./src" 8 | }, 9 | "include": [ 10 | "src/**/*.ts", 11 | "src/**/*.js", 12 | "src/**/*.json" 13 | ], 14 | "exclude": [ 15 | "**/node_modules" 16 | ] 17 | } 18 | 19 | -------------------------------------------------------------------------------- /packages/coin-flow/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | # Change Log 3 | 4 | All notable changes to this project will be documented in this file. 5 | 6 | # [1.1.0](https://github.com/okx/js-wallet-sdk)(2024-01-15) 7 | 8 | ### New Features 9 | 10 | - **coin-flow:** support signCommonMsg ([](https://github.com/okx/js-wallet-sdk)) 11 | 12 | # [1.0.2](https://github.com/okx/js-wallet-sdk) (2024-08-20) 13 | 14 | ### Fix 15 | 16 | - **coin-flow:** upgrade private key verification ([](https://github.com/okx/js-wallet-sdk)) 17 | 18 | -------------------------------------------------------------------------------- /packages/coin-flow/jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ 2 | module.exports = { 3 | preset: 'ts-jest', 4 | testEnvironment: 'node', 5 | }; -------------------------------------------------------------------------------- /packages/coin-flow/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./account" 2 | export * from "./enode" 3 | export * from "./http" 4 | export * from "./model" 5 | export * from "./signature" 6 | export * from "./tx" 7 | 8 | import { base, signUtil } from "@okxweb3/crypto-lib" 9 | export function validateAddress(address: string) { 10 | return base.isHexString(address, 8) 11 | } 12 | 13 | export function private2Public(privateHex: string): string { 14 | if (!base.validateHexString(privateHex)) { 15 | throw new Error('invalid key'); 16 | } 17 | const pk = signUtil.p256.publicKeyCreate(base.fromHex(privateHex.toLowerCase()), false) 18 | return base.toHex(pk.slice(1)) 19 | } 20 | -------------------------------------------------------------------------------- /packages/coin-flow/src/signature.ts: -------------------------------------------------------------------------------- 1 | import { base, signUtil } from '@okxweb3/crypto-lib'; 2 | import { rightPaddedHexBuffer } from './enode'; 3 | 4 | export const TX_DOMAIN_TAG_HEX = rightPaddedHexBuffer(Buffer.from('FLOW-V0.0-transaction', 'utf-8').toString('hex'), 32).toString('hex'); 5 | 6 | export const transactionSignature = (msg: string, privateKey: Buffer): string => { 7 | const messageForHash = base.fromHex(TX_DOMAIN_TAG_HEX + msg); 8 | const digest = base.sha3_256(messageForHash); 9 | const sig = signUtil.p256.sign(Buffer.from(digest), privateKey); 10 | return base.toHex(sig.signature); 11 | }; -------------------------------------------------------------------------------- /packages/coin-flow/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "resolveJsonModule" : true, 5 | "outDir": "./dist", 6 | "rootDir": "./src" 7 | }, 8 | "include": [ 9 | "src/**/*.ts", 10 | "src/**/*.json" 11 | ], 12 | "exclude": [ 13 | "**/node_modules" 14 | ] 15 | } 16 | 17 | -------------------------------------------------------------------------------- /packages/coin-kaia/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | # Change Log 3 | 4 | All notable changes to this project will be documented in this file. 5 | 6 | 7 | 8 | # [1.0.1](https://github.com/okx/js-wallet-sdk)(2024-02-19) 9 | 10 | ### New Features 11 | 12 | - **coin-kaia:** overrides elliptic 13 | 14 | # [1.0.0](https://github.com/okx/js-wallet-sdk)(2024-02-18) 15 | 16 | ### New Features 17 | 18 | - **coin-kaia:** support kaia -------------------------------------------------------------------------------- /packages/coin-kaia/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | ['@babel/preset-env', {targets: {node: 'current'}}], 4 | '@babel/preset-typescript', 5 | ], 6 | }; -------------------------------------------------------------------------------- /packages/coin-kaia/jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ 2 | module.exports = { 3 | preset: 'ts-jest/presets/default-esm', // 支持 ESM 4 | testEnvironment: 'node', 5 | transform: { 6 | '^.+\\.(ts|tsx)$': 'ts-jest', 7 | '^.+\\.js$': 'babel-jest', // 转译 JS 文件 8 | }, 9 | transformIgnorePatterns: [ 10 | '/node_modules/(?!lodash-es|@kaiachain/ethers-ext)', // 强制转译这些依赖 11 | ], 12 | extensionsToTreatAsEsm: ['.ts', '.tsx'], // 指定这些扩展名需要被当作 ESM 处理 13 | moduleNameMapper: { 14 | '^@kaiachain/ethers-ext/src/v6$': '/node_modules/@kaiachain/ethers-ext/src/v6', 15 | '^@kaiachain/js-ext-core/util$': '/node_modules/@kaiachain/js-ext-core/util', 16 | '^@kaiachain/js-ext-core/ethers-v6$': '/node_modules/@kaiachain/js-ext-core/ethers-v6', 17 | }, 18 | }; -------------------------------------------------------------------------------- /packages/coin-kaia/src/api.ts: -------------------------------------------------------------------------------- 1 | import {base} from "@okxweb3/crypto-lib" 2 | 3 | export function validPrivateKey(privateKeyHex: string): boolean { 4 | if (!base.validateHexString(privateKeyHex)) { 5 | return false; 6 | } 7 | const privateKey = base.fromHex(privateKeyHex.toLowerCase()) 8 | if (privateKey.length != 32 || privateKey.every(byte => byte === 0)) { 9 | return false; 10 | } 11 | return true; 12 | } -------------------------------------------------------------------------------- /packages/coin-kaia/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./api" 2 | export * from "./KaiaWallet" -------------------------------------------------------------------------------- /packages/coin-kaia/src/v6/index.ts: -------------------------------------------------------------------------------- 1 | // Pass-through js-ext-core exports 2 | // export * from "@kaiachain/js-ext-core/util"; 3 | export { 4 | AccountKey, 5 | AccountKeyFactory, 6 | KlaytnTx, 7 | KlaytnTxFactory, 8 | parseTransaction, 9 | } from "@kaiachain/js-ext-core"; 10 | 11 | // ethers-ext classes and functions 12 | export * from "./accountStore"; 13 | export * from "./keystore"; 14 | export * from "./signer"; 15 | export * from "./txutil"; 16 | -------------------------------------------------------------------------------- /packages/coin-kaia/src/v6/types.ts: -------------------------------------------------------------------------------- 1 | import { TransactionRequest as EthersTransactionRequest } from "ethers6"; 2 | 3 | export interface TransactionRequest extends EthersTransactionRequest { 4 | txSignatures?: any[]; 5 | feePayer?: string; 6 | feePayerSignatures?: any[]; 7 | } -------------------------------------------------------------------------------- /packages/coin-kaia/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "allowJs": true, 5 | "resolveJsonModule" : true, 6 | "outDir": "./dist", 7 | "rootDir": "./src" 8 | }, 9 | "include": [ 10 | "src/**/*.ts", 11 | "src/**/*.js", 12 | "src/**/*.json" 13 | ], 14 | "exclude": [ 15 | "**/node_modules" 16 | ] 17 | } -------------------------------------------------------------------------------- /packages/coin-kaspa/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | # Change Log 3 | 4 | All notable changes to this project will be documented in this file. 5 | 6 | # [1.1.0](https://github.com/okx/js-wallet-sdk)(2024-01-15) 7 | 8 | ### New Features 9 | 10 | - **coin-kaspa:** support signCommonMsg ([](https://github.com/okx/js-wallet-sdk)) 11 | 12 | # [1.0.5](https://github.com/okx/js-wallet-sdk) (2024-08-20) 13 | 14 | ### Fix 15 | 16 | - **coin-kaspa:** upgrade private key verification ([](https://github.com/okx/js-wallet-sdk)) 17 | 18 | # [1.0.3](https://github.com/okx/js-wallet-sdk) (2023-12-05) 19 | 20 | ### Feature 21 | 22 | - **coin-kaspa:** add transfer, sign message ([40](https://github.com/okx/js-wallet-sdk/pull/40)) 23 | 24 | # [1.0.2](https://github.com/okx/js-wallet-sdk) (2023-11-17) 25 | 26 | ### Bug Fixes 27 | 28 | - **coin-kaspa:** fix address validate ([26](https://github.com/okx/js-wallet-sdk/pull/26)) 29 | 30 | # [1.0.1](https://github.com/okx/js-wallet-sdk) (2023-11-13) 31 | 32 | ### Bug Fixes 33 | 34 | - **coin-kaspa:** add index.ts ([23](https://github.com/okx/js-wallet-sdk/pull/23)) 35 | -------------------------------------------------------------------------------- /packages/coin-kaspa/jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ 2 | module.exports = { 3 | preset: 'ts-jest', 4 | testEnvironment: 'node', 5 | }; -------------------------------------------------------------------------------- /packages/coin-kaspa/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./KaspaWallet"; 2 | export * from "./address"; 3 | export * from "./transaction"; 4 | -------------------------------------------------------------------------------- /packages/coin-kaspa/src/lib/validation.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The following methods are based on `Emilio Almansi`, thanks for their work 3 | * @license 4 | * https://github.com/ealmansi/cashaddrjs 5 | * Copyright (c) 2017-2020 Emilio Almansi 6 | * Distributed under the MIT software license, see the accompanying 7 | * file LICENSE or http://www.opensource.org/licenses/mit-license.php. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | /** 13 | * Validation utility. 14 | * 15 | * @module validation 16 | */ 17 | 18 | /** 19 | * Validates a given condition, throwing a {@link Error} if 20 | * the given condition does not hold. 21 | * 22 | * @static 23 | * @param {boolean} condition Condition to validate. 24 | * @param {string} message Error message in case the condition does not hold. 25 | */ 26 | export function validate(condition: any, message: string) { 27 | if (!condition) { 28 | throw new Error(message); 29 | } 30 | } -------------------------------------------------------------------------------- /packages/coin-kaspa/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "allowJs": true, // Allows javascript files to be compiled 5 | "resolveJsonModule" : true, 6 | "outDir": "./dist", 7 | "rootDir": "./src", 8 | "experimentalDecorators": true 9 | }, 10 | "include": [ 11 | "src/**/*.ts", 12 | "src/**/*.js", 13 | "src/**/*.json" 14 | ], 15 | "exclude": [ 16 | "**/node_modules" 17 | ] 18 | } 19 | 20 | -------------------------------------------------------------------------------- /packages/coin-near/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | # Change Log 3 | 4 | All notable changes to this project will be documented in this file. 5 | 6 | 7 | # [1.1.0](https://github.com/okx/js-wallet-sdk)(2024-01-15) 8 | 9 | ### New Features 10 | 11 | - **coin-near:** support signCommonMsg ([](https://github.com/okx/js-wallet-sdk)) 12 | 13 | 14 | # [1.0.4](https://github.com/okx/js-wallet-sdk) (2024-08-20) 15 | 16 | ### Fix 17 | 18 | - **coin-near:** upgrade private key verification ([](https://github.com/okx/js-wallet-sdk)) 19 | 20 | # [1.0.1](https://github.com/okx/js-wallet-sdk) (2024-4-9) 21 | 22 | ### New Feature 23 | 24 | - **coin-near:** support near dapp txs ([1.0.1](https://github.com/okx/js-wallet-sdk)) 25 | -------------------------------------------------------------------------------- /packages/coin-near/jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ 2 | module.exports = { 3 | preset: 'ts-jest', 4 | testEnvironment: 'node', 5 | }; -------------------------------------------------------------------------------- /packages/coin-near/src/enums.ts: -------------------------------------------------------------------------------- 1 | /** @hidden @module */ 2 | export abstract class Enum { 3 | enum: string; 4 | 5 | constructor(properties: any) { 6 | if (Object.keys(properties).length !== 1) { 7 | throw new Error('Enum can only take single value'); 8 | } 9 | Object.keys(properties).map((key: string) => { 10 | (this as any)[key] = properties[key]; 11 | this.enum = key; 12 | }); 13 | } 14 | } 15 | 16 | export abstract class Assignable { 17 | constructor(properties: any) { 18 | Object.keys(properties).map((key: any) => { 19 | (this as any)[key] = properties[key]; 20 | }); 21 | } 22 | } -------------------------------------------------------------------------------- /packages/coin-near/src/nearlib.ts: -------------------------------------------------------------------------------- 1 | import { Schema, serialize } from 'borsh'; 2 | 3 | export interface SignMessageParamsNEP { 4 | message: string 5 | recipient: string 6 | nonce: Buffer 7 | callbackUrl?: string 8 | state?: string 9 | } 10 | 11 | 12 | export interface SignMessageParams { 13 | chainId: string 14 | messageParams: SignMessageParamsNEP & { 15 | accountId?: string 16 | } 17 | } 18 | 19 | export class MessagePayload { 20 | tag: number 21 | message: string 22 | nonce: Buffer 23 | recipient: string 24 | callbackUrl?: string 25 | 26 | constructor(data: SignMessageParamsNEP) { 27 | // The tag's value is a hardcoded value as per 28 | // defined in the NEP [NEP413](https://github.com/near/NEPs/blob/master/neps/nep-0413.md) 29 | this.tag = 2147484061 30 | this.message = data.message 31 | this.nonce = data.nonce 32 | this.recipient = data.recipient 33 | if (data.callbackUrl) { 34 | this.callbackUrl = data.callbackUrl 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /packages/coin-near/src/serialize.ts: -------------------------------------------------------------------------------- 1 | export { 2 | baseEncode as base_encode, 3 | baseDecode as base_decode, 4 | serialize, 5 | deserialize, 6 | Schema, 7 | BorshError, 8 | BinaryWriter, 9 | BinaryReader, 10 | } from 'borsh'; -------------------------------------------------------------------------------- /packages/coin-near/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "resolveJsonModule" : true, 5 | "strictPropertyInitialization": false, 6 | "outDir": "./dist", 7 | "rootDir": "./src" 8 | }, 9 | "include": [ 10 | "src/**/*.ts", 11 | "src/**/*.json" 12 | ], 13 | "exclude": [ 14 | "**/node_modules" 15 | ] 16 | } 17 | 18 | -------------------------------------------------------------------------------- /packages/coin-nostrassets/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | # Change Log 3 | 4 | All notable changes to this project will be documented in this file. 5 | 6 | # [1.1.0](https://github.com/okx/js-wallet-sdk)(2024-01-15) 7 | 8 | ### New Features 9 | 10 | - **coin-nostrassets:** support signCommonMsg ([](https://github.com/okx/js-wallet-sdk)) 11 | 12 | # [1.0.2](https://github.com/okx/js-wallet-sdk) (2023-11-28) 13 | 14 | ### New Features 15 | 16 | - **coin-nostrassets:** support private key with 'nsec' prefix ([35](https://github.com/okx/js-wallet-sdk/pull/35)) -------------------------------------------------------------------------------- /packages/coin-nostrassets/jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ 2 | module.exports = { 3 | preset: 'ts-jest', 4 | testEnvironment: 'node', 5 | }; -------------------------------------------------------------------------------- /packages/coin-nostrassets/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./NostrAssetsWallet"; 2 | export * from "./nostrassets"; 3 | export * from "./keys"; 4 | export * from "./event"; 5 | -------------------------------------------------------------------------------- /packages/coin-nostrassets/src/keys.test.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Author:https://github.com/nbd-wtf/nostr-tools 3 | * */ 4 | import { generatePrivateKey, getPublicKey } from './keys' 5 | 6 | test('private key generation', () => { 7 | expect(generatePrivateKey()).toMatch(/[a-f0-9]{64}/) 8 | }) 9 | 10 | test('public key generation', () => { 11 | expect(getPublicKey(generatePrivateKey())).toMatch(/[a-f0-9]{64}/) 12 | }) 13 | 14 | test('public key from private key deterministic', () => { 15 | let sk = generatePrivateKey() 16 | let pk = getPublicKey(sk) 17 | 18 | for (let i = 0; i < 5; i++) { 19 | expect(getPublicKey(sk)).toEqual(pk) 20 | } 21 | }) 22 | -------------------------------------------------------------------------------- /packages/coin-nostrassets/src/keys.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Author:https://github.com/nbd-wtf/nostr-tools 3 | * */ 4 | import { 5 | base, secp256k1 6 | } from "@okxweb3/crypto-lib"; 7 | 8 | export function generatePrivateKey(): string { 9 | return base.toHex(secp256k1.utils.randomPrivateKey(),false) 10 | } 11 | 12 | export function getPublicKey(privateKey: string): string { 13 | return base.toHex(secp256k1.schnorr.getPublicKey(base.stripHexPrefix(privateKey)),false) 14 | } 15 | -------------------------------------------------------------------------------- /packages/coin-nostrassets/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "allowJs": true, // Allows javascript files to be compiled 5 | "resolveJsonModule" : true, 6 | "outDir": "./dist", 7 | "rootDir": "./src" 8 | }, 9 | "include": [ 10 | "src/**/*.ts", 11 | "src/**/*.js", 12 | "src/**/*.json" 13 | ], 14 | "exclude": [ 15 | "**/node_modules" 16 | ] 17 | } 18 | 19 | -------------------------------------------------------------------------------- /packages/coin-polkadot/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | # Change Log 3 | 4 | All notable changes to this project will be documented in this file. 5 | 6 | # [1.0.4](https://github.com/okx/js-wallet-sdk) (2024-08-20) 7 | 8 | ### Fix 9 | 10 | - **coin-polkadot:** update base and lib 11 | 12 | 13 | 14 | # [1.0.2](https://github.com/okx/js-wallet-sdk) (2024-08-20) 15 | 16 | ### Fix 17 | 18 | - **coin-polkadot:** upgrade private key verification ([](https://github.com/okx/js-wallet-sdk)) 19 | 20 | -------------------------------------------------------------------------------- /packages/coin-polkadot/jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ 2 | module.exports = { 3 | preset: 'ts-jest', 4 | testEnvironment: 'node', 5 | }; -------------------------------------------------------------------------------- /packages/coin-polkadot/src/index.ts: -------------------------------------------------------------------------------- 1 | import {base} from "@okxweb3/crypto-lib"; 2 | import {NetWork} from "./const"; 3 | import {decodeAddress, encodeAddress, private2Public} from "./address"; 4 | 5 | 6 | export function getNewAddress(seed: string, ss58Format: NetWork) { 7 | if (!validatePrivate(seed)) { 8 | throw new Error("invalid key"); 9 | } 10 | const publicKey = private2Public(base.fromHex(seed)) 11 | return encodeAddress(publicKey, ss58Format) 12 | } 13 | 14 | function validatePrivate(seed: string): boolean { 15 | if (!base.validateHexString(seed)){ 16 | return false 17 | } 18 | const buffer = base.fromHex(seed.toLowerCase()); 19 | if (buffer.length != 32 && buffer.length != 64) { 20 | return false 21 | } 22 | return true; 23 | } 24 | 25 | export function validateAddress(encoded: string, ss58Format: NetWork): boolean { 26 | try { 27 | decodeAddress(encoded, ss58Format) 28 | return true 29 | } catch (e) { 30 | return false 31 | } 32 | } 33 | 34 | export * from "./const" 35 | export * from "./tx" 36 | export * from "./types" -------------------------------------------------------------------------------- /packages/coin-polkadot/src/object.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The following methods are based on `polkadot-js`, thanks for their work 3 | * https://github.com/polkadot-js/common/tree/master/packages/util 4 | */ 5 | export function objectKeys> (value: T): K[] { 6 | return Object.keys(value) as K[]; 7 | } 8 | 9 | export function objectSpread (dest: object, ...sources: (object | undefined | null)[]): T { 10 | for (let i = 0; i < sources.length; i++) { 11 | const src = sources[i]; 12 | 13 | if (src) { 14 | const keys = objectKeys(src); 15 | 16 | for (let j = 0; j < keys.length; j++) { 17 | const key = keys[j]; 18 | 19 | dest[key] = src[key]; 20 | } 21 | } 22 | } 23 | 24 | return dest as T; 25 | } -------------------------------------------------------------------------------- /packages/coin-polkadot/src/string.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The following methods are based on `polkadot-js`, thanks for their work 3 | * https://github.com/polkadot-js/common/tree/master/packages/util 4 | */ 5 | import {TextEncoder} from "@polkadot/x-textencoder"; 6 | import {AnyString} from "./types"; 7 | 8 | const encoder = new TextEncoder(); 9 | 10 | /** 11 | * @name stringToU8a 12 | * @summary Creates a Uint8Array object from a utf-8 string. 13 | * @description 14 | * String input values return the actual encoded `UInt8Array`. `null` or `undefined` values returns an empty encoded array. 15 | * @example 16 | *
17 | * 18 | * ```javascript 19 | * import { stringToU8a } from '@polkadot/util'; 20 | * 21 | * stringToU8a('hello'); // [0x68, 0x65, 0x6c, 0x6c, 0x6f] 22 | * ``` 23 | */ 24 | export function stringToU8a (value?: AnyString | null): Uint8Array { 25 | return value 26 | ? encoder.encode(value.toString()) 27 | : new Uint8Array(); 28 | } -------------------------------------------------------------------------------- /packages/coin-polkadot/src/types.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The following methods are based on `polkadot-js`, thanks for their work 3 | * https://github.com/polkadot-js/common/tree/master/packages/util 4 | */ 5 | import {BN} from "@okxweb3/crypto-lib"; 6 | 7 | export type HexString = `0x${string}`; 8 | export type AnyString = string | String; 9 | export type U8aLike = HexString | number[] | Buffer | Uint8Array | AnyString; 10 | 11 | export interface ToBn { 12 | toBn: () => BN; 13 | } 14 | 15 | export interface ToBigInt { 16 | toBigInt: () => bigint; 17 | } 18 | 19 | export interface NumberOptions extends ToBnOptions { 20 | /** 21 | * @description Limit to the specified bitLength, despite input length 22 | */ 23 | bitLength?: number; 24 | } 25 | 26 | export type MessageFn = () => string; 27 | 28 | export interface ToBnOptions { 29 | /** 30 | * @description Convert in LE format 31 | */ 32 | isLe?: boolean; 33 | /** 34 | * @description Number is negative, apply two's complement 35 | */ 36 | isNegative?: boolean; 37 | } 38 | 39 | export const hasBuffer = typeof Buffer !== 'undefined'; 40 | 41 | -------------------------------------------------------------------------------- /packages/coin-polkadot/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "resolveJsonModule" : true, 5 | "outDir": "./dist", 6 | "rootDir": "./src" 7 | }, 8 | "include": [ 9 | "src/**/*.ts", 10 | "src/**/*.json" 11 | ], 12 | "exclude": [ 13 | "**/node_modules" 14 | ] 15 | } 16 | 17 | -------------------------------------------------------------------------------- /packages/coin-solana/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | # [1.1.0](https://github.com/okx/js-wallet-sdk)(2024-01-15) 6 | 7 | ### New Features 8 | 9 | - **coin-solana:** support signCommonMsg ([](https://github.com/okx/js-wallet-sdk)) 10 | 11 | 12 | # [1.0.4](https://github.com/okx/js-wallet-sdk) (2024-08-20) 13 | 14 | ### Fix 15 | 16 | - **coin-solana:** upgrading dependencies ([](https://github.com/okx/js-wallet-sdk)) 17 | 18 | # [1.0.3] (2024-06-19) 19 | 20 | ### fix 21 | 22 | - **coin-solana:** support mpl transfer and dynamic fee 23 | 24 | # [1.0.1] (2024-03-21) 25 | 26 | ### Feature 27 | 28 | - **coin-solana:** support token2022 and priority fee 29 | -------------------------------------------------------------------------------- /packages/coin-solana/jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ 2 | module.exports = { 3 | preset: 'ts-jest', 4 | testEnvironment: 'node', 5 | }; -------------------------------------------------------------------------------- /packages/coin-solana/src/index.ts: -------------------------------------------------------------------------------- 1 | export * as api from "./api" 2 | export * from "./sdk" 3 | export * from "./SolWallet" 4 | -------------------------------------------------------------------------------- /packages/coin-solana/src/sdk/buffer-layout/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./layout" 2 | export * from "./utils" 3 | -------------------------------------------------------------------------------- /packages/coin-solana/src/sdk/buffer-layout/utils/base.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The following methods are based on `buffer-layout-utils`, thanks for their work 3 | * https://github.com/solana-labs/buffer-layout-utils/tree/master/src 4 | */ 5 | import { Layout } from '../layout'; 6 | 7 | export interface EncodeDecode { 8 | decode(buffer: Buffer, offset?: number): T; 9 | encode(src: T, buffer: Buffer, offset?: number): number; 10 | } 11 | 12 | export const encodeDecode = (layout: Layout): EncodeDecode => { 13 | const decode = layout.decode.bind(layout); 14 | const encode = layout.encode.bind(layout); 15 | return { decode, encode }; 16 | }; 17 | -------------------------------------------------------------------------------- /packages/coin-solana/src/sdk/buffer-layout/utils/index.ts: -------------------------------------------------------------------------------- 1 | export * from './base'; 2 | export * from './bigint'; 3 | export * from './decimal'; 4 | export * from './native'; 5 | export * from './web3'; 6 | export * from '../layout'; 7 | -------------------------------------------------------------------------------- /packages/coin-solana/src/sdk/buffer-layout/utils/native.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The following methods are based on `buffer-layout-utils`, thanks for their work 3 | * https://github.com/solana-labs/buffer-layout-utils/tree/master/src 4 | */ 5 | import { Layout, u8 } from '../layout'; 6 | import { encodeDecode } from './base'; 7 | 8 | export const bool = (property?: string): Layout => { 9 | const layout = u8(property); 10 | const { encode, decode } = encodeDecode(layout); 11 | 12 | const boolLayout = layout as Layout as Layout; 13 | 14 | boolLayout.decode = (buffer: Buffer, offset: number) => { 15 | const src = decode(buffer, offset); 16 | return !!src; 17 | }; 18 | 19 | boolLayout.encode = (bool: boolean, buffer: Buffer, offset: number) => { 20 | const src = Number(bool); 21 | return encode(src, buffer, offset); 22 | }; 23 | 24 | return boolLayout; 25 | }; 26 | -------------------------------------------------------------------------------- /packages/coin-solana/src/sdk/buffer-layout/utils/web3.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The following methods are based on `buffer-layout-utils`, thanks for their work 3 | * https://github.com/solana-labs/buffer-layout-utils/tree/master/src 4 | */ 5 | import { blob, Layout } from '../layout'; 6 | import { PublicKey } from '../../web3'; 7 | import { encodeDecode } from './base'; 8 | 9 | export const publicKey = (property?: string): Layout => { 10 | const layout = blob(32, property); 11 | const { encode, decode } = encodeDecode(layout); 12 | 13 | const publicKeyLayout = layout as Layout as Layout; 14 | 15 | publicKeyLayout.decode = (buffer: Buffer, offset: number) => { 16 | const src = decode(buffer, offset); 17 | return new PublicKey(src); 18 | }; 19 | 20 | publicKeyLayout.encode = (publicKey: PublicKey, buffer: Buffer, offset: number) => { 21 | const src = publicKey.toBuffer(); 22 | return encode(src, buffer, offset); 23 | }; 24 | 25 | return publicKeyLayout; 26 | }; 27 | -------------------------------------------------------------------------------- /packages/coin-solana/src/sdk/index.ts: -------------------------------------------------------------------------------- 1 | export * as spl from "./spl" 2 | export * as web3 from "./web3" 3 | export * as metaplex from "./metaplex" 4 | -------------------------------------------------------------------------------- /packages/coin-solana/src/sdk/metaplex/index.ts: -------------------------------------------------------------------------------- 1 | export * from './beet-solana'; 2 | export * from './mpl-token-metadata'; 3 | export * from './plugins/nftModule/operations/transferNft'; 4 | export * from './utils'; 5 | export * from './types'; 6 | -------------------------------------------------------------------------------- /packages/coin-solana/src/sdk/metaplex/mpl-token-metadata/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The following methods are based on `mpl-token-metadata`, thanks for their work 3 | * https://github.com/metaplex-foundation/mpl-token-metadata/tree/main/programs/token-metadata/js/src/generated 4 | */ 5 | 6 | import { PublicKey } from '../../web3'; 7 | export * from './instructions'; 8 | export * from './types'; 9 | 10 | /** 11 | * Program address 12 | * 13 | * @category constants 14 | * @category generated 15 | */ 16 | export const PROGRAM_ADDRESS = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'; 17 | 18 | /** 19 | * Program public key 20 | * 21 | * @category constants 22 | * @category generated 23 | */ 24 | export const PROGRAM_ID = new PublicKey(PROGRAM_ADDRESS); 25 | -------------------------------------------------------------------------------- /packages/coin-solana/src/sdk/metaplex/mpl-token-metadata/instructions/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Transfer'; 2 | -------------------------------------------------------------------------------- /packages/coin-solana/src/sdk/metaplex/mpl-token-metadata/types/AuthorityType.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The following methods are based on `mpl-token-metadata`, thanks for their work 3 | * https://github.com/metaplex-foundation/mpl-token-metadata/tree/main/programs/token-metadata/js/src/generated/types 4 | */ 5 | 6 | /** 7 | * This code was GENERATED using the solita package. 8 | * Please DO NOT EDIT THIS FILE, instead rerun solita to update it or write a wrapper to add functionality. 9 | * 10 | * See: https://github.com/metaplex-foundation/solita 11 | */ 12 | 13 | import * as beet from '@metaplex-foundation/beet'; 14 | /** 15 | * @category enums 16 | * @category generated 17 | */ 18 | export enum AuthorityType { 19 | None, 20 | Metadata, 21 | Holder, 22 | MetadataDelegate, 23 | TokenDelegate, 24 | } 25 | 26 | /** 27 | * @category userTypes 28 | * @category generated 29 | */ 30 | export const authorityTypeBeet = beet.fixedScalarEnum(AuthorityType) as beet.FixedSizeBeet< 31 | AuthorityType, 32 | AuthorityType 33 | >; 34 | -------------------------------------------------------------------------------- /packages/coin-solana/src/sdk/metaplex/mpl-token-metadata/types/AuthorizationData.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The following methods are based on `mpl-token-metadata`, thanks for their work 3 | * https://github.com/metaplex-foundation/mpl-token-metadata/tree/main/programs/token-metadata/js/src/generated/types 4 | */ 5 | 6 | /** 7 | * This code was GENERATED using the solita package. 8 | * Please DO NOT EDIT THIS FILE, instead rerun solita to update it or write a wrapper to add functionality. 9 | * 10 | * See: https://github.com/metaplex-foundation/solita 11 | */ 12 | 13 | import * as beet from '@metaplex-foundation/beet'; 14 | import { Payload, payloadBeet } from './Payload'; 15 | export type AuthorizationData = { 16 | payload: Payload; 17 | }; 18 | 19 | /** 20 | * @category userTypes 21 | * @category generated 22 | */ 23 | export const authorizationDataBeet = new beet.FixableBeetArgsStruct( 24 | [['payload', payloadBeet]], 25 | 'AuthorizationData', 26 | ); 27 | -------------------------------------------------------------------------------- /packages/coin-solana/src/sdk/metaplex/mpl-token-metadata/types/LeafInfo.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This code was GENERATED using the solita package. 3 | * Please DO NOT EDIT THIS FILE, instead rerun solita to update it or write a wrapper to add functionality. 4 | * 5 | * See: https://github.com/metaplex-foundation/solita 6 | */ 7 | 8 | import * as beet from '@metaplex-foundation/beet'; 9 | export type LeafInfo = { 10 | leaf: number[] /* size: 32 */; 11 | proof: number[] /* size: 32 */[]; 12 | }; 13 | 14 | /** 15 | * @category userTypes 16 | * @category generated 17 | */ 18 | export const leafInfoBeet = new beet.FixableBeetArgsStruct( 19 | [ 20 | ['leaf', beet.uniformFixedSizeArray(beet.u8, 32)], 21 | ['proof', beet.array(beet.uniformFixedSizeArray(beet.u8, 32))], 22 | ], 23 | 'LeafInfo', 24 | ); 25 | -------------------------------------------------------------------------------- /packages/coin-solana/src/sdk/metaplex/mpl-token-metadata/types/MetadataDelegateRole.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The following methods are based on `mpl-token-metadata`, thanks for their work 3 | * https://github.com/metaplex-foundation/mpl-token-metadata/tree/main/programs/token-metadata/js/src/generated/types 4 | */ 5 | 6 | /** 7 | * This code was GENERATED using the solita package. 8 | * Please DO NOT EDIT THIS FILE, instead rerun solita to update it or write a wrapper to add functionality. 9 | * 10 | * See: https://github.com/metaplex-foundation/solita 11 | */ 12 | 13 | import * as beet from '@metaplex-foundation/beet'; 14 | /** 15 | * @category enums 16 | * @category generated 17 | */ 18 | export enum MetadataDelegateRole { 19 | AuthorityItem, 20 | Collection, 21 | Use, 22 | Data, 23 | ProgrammableConfig, 24 | DataItem, 25 | CollectionItem, 26 | ProgrammableConfigItem, 27 | } 28 | 29 | /** 30 | * @category userTypes 31 | * @category generated 32 | */ 33 | export const metadataDelegateRoleBeet = beet.fixedScalarEnum( 34 | MetadataDelegateRole, 35 | ) as beet.FixedSizeBeet; 36 | -------------------------------------------------------------------------------- /packages/coin-solana/src/sdk/metaplex/mpl-token-metadata/types/Payload.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The following methods are based on `mpl-token-metadata`, thanks for their work 3 | * https://github.com/metaplex-foundation/mpl-token-metadata/tree/main/programs/token-metadata/js/src/generated/types 4 | */ 5 | 6 | /** 7 | * This code was GENERATED using the solita package. 8 | * Please DO NOT EDIT THIS FILE, instead rerun solita to update it or write a wrapper to add functionality. 9 | * 10 | * See: https://github.com/metaplex-foundation/solita 11 | */ 12 | 13 | import * as beet from '@metaplex-foundation/beet'; 14 | import { PayloadType, payloadTypeBeet } from './PayloadType'; 15 | export type Payload = { 16 | map: Map; 17 | }; 18 | 19 | /** 20 | * @category userTypes 21 | * @category generated 22 | */ 23 | export const payloadBeet = new beet.FixableBeetArgsStruct( 24 | [['map', beet.map(beet.utf8String, payloadTypeBeet)]], 25 | 'Payload', 26 | ); 27 | -------------------------------------------------------------------------------- /packages/coin-solana/src/sdk/metaplex/mpl-token-metadata/types/SeedsVec.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The following methods are based on `mpl-token-metadata`, thanks for their work 3 | * https://github.com/metaplex-foundation/mpl-token-metadata/tree/main/programs/token-metadata/js/src/generated/types 4 | */ 5 | 6 | /** 7 | * This code was GENERATED using the solita package. 8 | * Please DO NOT EDIT THIS FILE, instead rerun solita to update it or write a wrapper to add functionality. 9 | * 10 | * See: https://github.com/metaplex-foundation/solita 11 | */ 12 | 13 | import * as beet from '@metaplex-foundation/beet'; 14 | export type SeedsVec = { 15 | seeds: Uint8Array[]; 16 | }; 17 | 18 | /** 19 | * @category userTypes 20 | * @category generated 21 | */ 22 | export const seedsVecBeet = new beet.FixableBeetArgsStruct( 23 | [['seeds', beet.array(beet.bytes)]], 24 | 'SeedsVec', 25 | ); 26 | -------------------------------------------------------------------------------- /packages/coin-solana/src/sdk/metaplex/mpl-token-metadata/types/TokenDelegateRole.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The following methods are based on `mpl-token-metadata`, thanks for their work 3 | * https://github.com/metaplex-foundation/mpl-token-metadata/tree/main/programs/token-metadata/js/src/generated/types 4 | */ 5 | 6 | /** 7 | * This code was GENERATED using the solita package. 8 | * Please DO NOT EDIT THIS FILE, instead rerun solita to update it or write a wrapper to add functionality. 9 | * 10 | * See: https://github.com/metaplex-foundation/solita 11 | */ 12 | 13 | import * as beet from '@metaplex-foundation/beet'; 14 | /** 15 | * @category enums 16 | * @category generated 17 | */ 18 | export enum TokenDelegateRole { 19 | Sale, 20 | Transfer, 21 | Utility, 22 | Staking, 23 | Standard, 24 | LockedTransfer, 25 | Migration, 26 | } 27 | 28 | /** 29 | * @category userTypes 30 | * @category generated 31 | */ 32 | export const tokenDelegateRoleBeet = beet.fixedScalarEnum(TokenDelegateRole) as beet.FixedSizeBeet< 33 | TokenDelegateRole, 34 | TokenDelegateRole 35 | >; 36 | -------------------------------------------------------------------------------- /packages/coin-solana/src/sdk/metaplex/mpl-token-metadata/types/TokenStandard.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The following methods are based on `mpl-token-metadata`, thanks for their work 3 | * https://github.com/metaplex-foundation/mpl-token-metadata/tree/main/programs/token-metadata/js/src/generated/types 4 | */ 5 | 6 | /** 7 | * This code was GENERATED using the solita package. 8 | * Please DO NOT EDIT THIS FILE, instead rerun solita to update it or write a wrapper to add functionality. 9 | * 10 | * See: https://github.com/metaplex-foundation/solita 11 | */ 12 | 13 | import * as beet from '@metaplex-foundation/beet'; 14 | /** 15 | * @category enums 16 | * @category generated 17 | */ 18 | export enum TokenStandard { 19 | NonFungible, 20 | FungibleAsset, 21 | Fungible, 22 | NonFungibleEdition, 23 | ProgrammableNonFungible, 24 | } 25 | 26 | /** 27 | * @category userTypes 28 | * @category generated 29 | */ 30 | export const tokenStandardBeet = beet.fixedScalarEnum(TokenStandard) as beet.FixedSizeBeet< 31 | TokenStandard, 32 | TokenStandard 33 | >; 34 | -------------------------------------------------------------------------------- /packages/coin-solana/src/sdk/metaplex/mpl-token-metadata/types/index.ts: -------------------------------------------------------------------------------- 1 | export * from './AuthorityType'; 2 | export * from './AuthorizationData'; 3 | export * from './DelegateArgs'; 4 | export * from './LeafInfo'; 5 | export * from './MetadataDelegateRole'; 6 | export * from './Payload'; 7 | export * from './PayloadType'; 8 | export * from './SeedsVec'; 9 | export * from './TokenDelegateRole'; 10 | export * from './TokenStandard'; 11 | export * from './TransferArgs'; 12 | -------------------------------------------------------------------------------- /packages/coin-solana/src/sdk/metaplex/plugins/nftModule/models/Metadata.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The following methods are based on `nftModule`, thanks for their work 3 | * https://github.com/metaplex-foundation/js/tree/main/packages/js/src/plugins/nftModule 4 | */ 5 | 6 | import { 7 | TokenStandard, 8 | } from '../../../mpl-token-metadata'; 9 | import { Option } from '../../../utils'; 10 | 11 | export const isNonFungible = (nftOrSft: { 12 | tokenStandard: Option; 13 | }): boolean => 14 | nftOrSft.tokenStandard === null || 15 | nftOrSft.tokenStandard === TokenStandard.NonFungible || 16 | nftOrSft.tokenStandard === TokenStandard.NonFungibleEdition || 17 | nftOrSft.tokenStandard === TokenStandard.ProgrammableNonFungible; 18 | 19 | export const isProgrammable = (nftOrSft: { 20 | tokenStandard: Option; 21 | }): boolean => nftOrSft.tokenStandard === TokenStandard.ProgrammableNonFungible; 22 | -------------------------------------------------------------------------------- /packages/coin-solana/src/sdk/metaplex/plugins/nftModule/models/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Metadata'; 2 | -------------------------------------------------------------------------------- /packages/coin-solana/src/sdk/metaplex/types/BigNumber.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The following methods are based on `types`, thanks for their work 3 | * https://github.com/metaplex-foundation/js/tree/main/packages/js/src/types 4 | */ 5 | import type { Buffer } from 'buffer'; 6 | import { BN } from '@okxweb3/crypto-lib'; 7 | import type { Opaque, Option } from '../utils'; 8 | 9 | export type BigNumber = Opaque; 10 | export type BigNumberValues = 11 | | number 12 | | string 13 | | number[] 14 | | Uint8Array 15 | | Buffer 16 | | BN; 17 | 18 | export const toBigNumber = ( 19 | value: BigNumberValues, 20 | endian?: BN.Endianness 21 | ): BigNumber => { 22 | return new BN(value, endian) as BigNumber; 23 | }; 24 | 25 | export const toOptionBigNumber = ( 26 | value: Option 27 | ): Option => { 28 | return value === null ? null : toBigNumber(value); 29 | }; 30 | 31 | export const isBigNumber = (value: any): value is BigNumber => { 32 | return value?.__opaque__ === 'BigNumber'; 33 | }; 34 | -------------------------------------------------------------------------------- /packages/coin-solana/src/sdk/metaplex/types/Pda.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The following methods are based on `types`, thanks for their work 3 | * https://github.com/metaplex-foundation/js/tree/main/packages/js/src/types 4 | */ 5 | import { Buffer } from 'buffer'; 6 | import { PublicKey, PublicKeyInitData } from '../../web3'; 7 | 8 | export class Pda extends PublicKey { 9 | /** The bump used to generate the PDA. */ 10 | public readonly bump: number; 11 | 12 | constructor(value: PublicKeyInitData, bump: number) { 13 | super(value); 14 | this.bump = bump; 15 | } 16 | 17 | static find(programId: PublicKey, seeds: Array): Pda { 18 | const [publicKey, bump] = PublicKey.findProgramAddressSync( 19 | seeds, 20 | programId 21 | ); 22 | 23 | return new Pda(publicKey, bump); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /packages/coin-solana/src/sdk/metaplex/types/Program.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The following methods are based on `types`, thanks for their work 3 | * https://github.com/metaplex-foundation/js/tree/main/packages/js/src/types 4 | */ 5 | import {PublicKey, SystemProgram} from '../../web3'; 6 | import { PROGRAM_ID as TOKEN_METADATA_PROGRAM_ID } from "../mpl-token-metadata"; 7 | import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from "../../spl"; 8 | 9 | export type Program = { 10 | name: string; 11 | address: PublicKey; 12 | }; 13 | 14 | export const tokenMetadataProgram: Program = { 15 | name: 'TokenMetadataProgram', 16 | address: TOKEN_METADATA_PROGRAM_ID, 17 | }; 18 | 19 | export const tokenProgram: Program = { 20 | name: 'TokenProgram', 21 | address: TOKEN_PROGRAM_ID, 22 | }; 23 | 24 | export const associatedTokenProgram: Program = { 25 | name: 'AssociatedTokenProgram', 26 | address: ASSOCIATED_TOKEN_PROGRAM_ID, 27 | }; 28 | 29 | export const systemProgram: Program = { 30 | name: 'SystemProgram', 31 | address: SystemProgram.programId, 32 | }; 33 | -------------------------------------------------------------------------------- /packages/coin-solana/src/sdk/metaplex/types/PublicKey.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The following methods are based on `types`, thanks for their work 3 | * https://github.com/metaplex-foundation/js/tree/main/packages/js/src/types 4 | */ 5 | import { PublicKey, PublicKeyInitData } from '../../web3'; 6 | 7 | export { PublicKey } from '../../web3'; 8 | export type PublicKeyString = string; 9 | export type PublicKeyValues = 10 | | PublicKeyInitData 11 | | { publicKey: PublicKey } 12 | | { address: PublicKey }; 13 | 14 | export const toPublicKey = (value: PublicKeyValues): PublicKey => { 15 | if (typeof value === 'object' && 'publicKey' in value) { 16 | return value.publicKey; 17 | } 18 | 19 | if (typeof value === 'object' && 'address' in value) { 20 | return (value as { address: PublicKey }).address; 21 | } 22 | 23 | return new PublicKey(value); 24 | }; 25 | -------------------------------------------------------------------------------- /packages/coin-solana/src/sdk/metaplex/types/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Amount'; 2 | export * from './BigNumber'; 3 | export * from './Pda'; 4 | export * from './Program'; 5 | export * from './PublicKey'; 6 | export * from './Signer'; 7 | -------------------------------------------------------------------------------- /packages/coin-solana/src/sdk/metaplex/utils/index.ts: -------------------------------------------------------------------------------- 1 | export * from './TransactionBuilder'; 2 | export * from './types'; 3 | -------------------------------------------------------------------------------- /packages/coin-solana/src/sdk/metaplex/utils/types.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The following methods are based on `utils`, thanks for their work 3 | * https://github.com/metaplex-foundation/js/tree/main/packages/js/src/utils 4 | */ 5 | export type PartialKeys = Omit< 6 | T, 7 | K 8 | > & 9 | Partial>; 10 | 11 | export type RequiredKeys = Omit< 12 | T, 13 | K 14 | > & 15 | Required>; 16 | 17 | export type Option = T | null; 18 | 19 | export type Opaque = T & { __opaque__: K }; 20 | -------------------------------------------------------------------------------- /packages/coin-solana/src/sdk/spl/instructions/index.ts: -------------------------------------------------------------------------------- 1 | export * from './types'; 2 | export * from './transfer'; 3 | export * from './transferChecked'; 4 | export * from './associatedTokenAccount'; 5 | export * from './burn'; 6 | export * from './burnChecked'; 7 | export * from './mintTo'; 8 | export * from './mintToChecked'; 9 | -------------------------------------------------------------------------------- /packages/coin-solana/src/sdk/spl/instructions/types.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The following methods are based on `solana-program-library`, thanks for their work 3 | * https://github.com/solana-labs/solana-program-library/tree/master/token/js/src/instructions 4 | */ 5 | 6 | /** Instructions defined by the program */ 7 | export enum TokenInstruction { 8 | InitializeMint = 0, 9 | InitializeAccount = 1, 10 | InitializeMultisig = 2, 11 | Transfer = 3, 12 | Approve = 4, 13 | Revoke = 5, 14 | SetAuthority = 6, 15 | MintTo = 7, 16 | Burn = 8, 17 | CloseAccount = 9, 18 | FreezeAccount = 10, 19 | ThawAccount = 11, 20 | TransferChecked = 12, 21 | ApproveChecked = 13, 22 | MintToChecked = 14, 23 | BurnChecked = 15, 24 | InitializeAccount2 = 16, 25 | SyncNative = 17, 26 | InitializeAccount3 = 18, 27 | InitializeMultisig2 = 19, 28 | InitializeMint2 = 20, 29 | } 30 | -------------------------------------------------------------------------------- /packages/coin-solana/src/sdk/web3/blockhash.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The following methods are based on `solana-web3.js`, thanks for their work 3 | * https://github.com/solana-labs/solana-web3.js/tree/master/packages/library-legacy/src 4 | */ 5 | 6 | /** 7 | * Blockhash as Base58 string. 8 | */ 9 | export type Blockhash = string; 10 | -------------------------------------------------------------------------------- /packages/coin-solana/src/sdk/web3/fee-calculator.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The following methods are based on `solana-web3.js`, thanks for their work 3 | * https://github.com/solana-labs/solana-web3.js/tree/master/packages/library-legacy/src 4 | */ 5 | 6 | import * as BufferLayout from '../buffer-layout'; 7 | 8 | /** 9 | * https://github.com/solana-labs/solana/blob/90bedd7e067b5b8f3ddbb45da00a4e9cabb22c62/sdk/src/fee_calculator.rs#L7-L11 10 | * 11 | * @internal 12 | */ 13 | export const FeeCalculatorLayout = BufferLayout.nu64('lamportsPerSignature'); 14 | 15 | /** 16 | * Calculator for transaction fees. 17 | * 18 | * @deprecated Deprecated since Solana v1.8.0. 19 | */ 20 | export interface FeeCalculator { 21 | /** Cost in lamports to validate a signature. */ 22 | lamportsPerSignature: number; 23 | } 24 | -------------------------------------------------------------------------------- /packages/coin-solana/src/sdk/web3/index.ts: -------------------------------------------------------------------------------- 1 | export * from './blockhash'; 2 | export * from './fee-calculator'; 3 | export * from './keypair'; 4 | export * from './message'; 5 | export * from './nonce-account'; 6 | export * from './programs'; 7 | export * from './publickey'; 8 | export * from './transaction'; 9 | export * from './sysvar'; 10 | 11 | /** 12 | * There are 1-billion lamports in one SOL 13 | */ 14 | export const LAMPORTS_PER_SOL = 1000000000; 15 | -------------------------------------------------------------------------------- /packages/coin-solana/src/sdk/web3/programs/index.ts: -------------------------------------------------------------------------------- 1 | export * from './address-lookup-table'; 2 | export * from './system'; 3 | export * from './compute-budget'; 4 | -------------------------------------------------------------------------------- /packages/coin-solana/src/sdk/web3/transaction/constants.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The following methods are based on `solana-web3.js`, thanks for their work 3 | * https://github.com/solana-labs/solana-web3.js/tree/master/packages/library-legacy/src/transaction 4 | */ 5 | 6 | /** 7 | * Maximum over-the-wire size of a Transaction 8 | * 9 | * 1280 is IPv6 minimum MTU 10 | * 40 bytes is the size of the IPv6 header 11 | * 8 bytes is the size of the fragment header 12 | */ 13 | export const PACKET_DATA_SIZE = 1280 - 40 - 8; 14 | 15 | export const VERSION_PREFIX_MASK = 0x7f; 16 | 17 | export const SIGNATURE_LENGTH_IN_BYTES = 64; 18 | -------------------------------------------------------------------------------- /packages/coin-solana/src/sdk/web3/transaction/index.ts: -------------------------------------------------------------------------------- 1 | export * from './constants'; 2 | export * from './expiry-custom-errors'; 3 | export * from './legacy'; 4 | export * from './message'; 5 | export * from './versioned'; 6 | -------------------------------------------------------------------------------- /packages/coin-solana/src/sdk/web3/utils/assert.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The following methods are based on `solana-web3.js`, thanks for their work 3 | * https://github.com/solana-labs/solana-web3.js/tree/master/packages/library-legacy/src/utils 4 | */ 5 | 6 | export default function ( 7 | condition: unknown, 8 | message?: string, 9 | ): asserts condition { 10 | if (!condition) { 11 | throw new Error(message || 'Assertion failed'); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/coin-solana/src/sdk/web3/utils/shortvec-encoding.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The following methods are based on `solana-web3.js`, thanks for their work 3 | * https://github.com/solana-labs/solana-web3.js/tree/master/packages/library-legacy/src/utils 4 | */ 5 | 6 | export function decodeLength(bytes: Array): number { 7 | let len = 0; 8 | let size = 0; 9 | for (;;) { 10 | let elem = bytes.shift() as number; 11 | len |= (elem & 0x7f) << (size * 7); 12 | size += 1; 13 | if ((elem & 0x80) === 0) { 14 | break; 15 | } 16 | } 17 | return len; 18 | } 19 | 20 | export function encodeLength(bytes: Array, len: number) { 21 | let rem_len = len; 22 | for (;;) { 23 | let elem = rem_len & 0x7f; 24 | rem_len >>= 7; 25 | if (rem_len == 0) { 26 | bytes.push(elem); 27 | break; 28 | } else { 29 | elem |= 0x80; 30 | bytes.push(elem); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /packages/coin-solana/src/sdk/web3/utils/to-buffer.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The following methods are based on `solana-web3.js`, thanks for their work 3 | * https://github.com/solana-labs/solana-web3.js/tree/master/packages/library-legacy/src/utils 4 | */ 5 | 6 | import {Buffer} from 'buffer'; 7 | 8 | export const toBuffer = (arr: Buffer | Uint8Array | Array): Buffer => { 9 | if (Buffer.isBuffer(arr)) { 10 | return arr; 11 | } else if (arr instanceof Uint8Array) { 12 | return Buffer.from(arr.buffer, arr.byteOffset, arr.byteLength); 13 | } else { 14 | return Buffer.from(arr); 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /packages/coin-solana/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./dist", 5 | "rootDir": "./src" 6 | }, 7 | "include": [ 8 | "src/**/*.ts" 9 | ], 10 | "exclude": [ 11 | "**/node_modules" 12 | ] 13 | } 14 | 15 | -------------------------------------------------------------------------------- /packages/coin-stacks/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | # Change Log 3 | 4 | All notable changes to this project will be documented in this file. 5 | 6 | # [1.1.0](https://github.com/okx/js-wallet-sdk)(2024-01-15) 7 | 8 | ### New Features 9 | 10 | - **coin-stacks:** support signCommonMsg ([](https://github.com/okx/js-wallet-sdk)) 11 | 12 | # [1.0.3](https://github.com/okx/js-wallet-sdk) (2024-08-20) 13 | 14 | ### Fix 15 | 16 | - **coin-stacks:** upgrading dependencies ([](https://github.com/okx/js-wallet-sdk)) 17 | 18 | # [1.0.1](https://github.com/okx/js-wallet-sdk) (2024-1-2) 19 | 20 | ### Bug Fix 21 | 22 | - **coin-stacks:** compatible with private key signatures starting with 0x ([73](https://github.com/okx/js-wallet-sdk/pull/73)) 23 | -------------------------------------------------------------------------------- /packages/coin-stacks/jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ 2 | module.exports = { 3 | preset: 'ts-jest', 4 | testEnvironment: 'node', 5 | }; -------------------------------------------------------------------------------- /packages/coin-stacks/src/base-x/index.d.ts: -------------------------------------------------------------------------------- 1 | declare function base(ALPHABET: string): base.BaseConverter; 2 | export = base; 3 | declare namespace base { 4 | interface BaseConverter { 5 | encode(buffer: Uint8Array | number[]): string; 6 | decodeUnsafe(string: string): Uint8Array | undefined; 7 | decode(string: string): Uint8Array; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/coin-stacks/src/c32check/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Jude Nelson 5 | * 6 | * https://github.com/stacks-network/c32check/blob/master/LICENSE 7 | * */ 8 | import { c32encode, c32decode, c32normalize } from './encoding'; 9 | 10 | import { c32checkEncode, c32checkDecode } from './checksum'; 11 | 12 | import { c32address, c32addressDecode, c32ToB58, b58ToC32, versions } from './address'; 13 | 14 | export { 15 | c32encode, 16 | c32decode, 17 | c32checkEncode, 18 | c32checkDecode, 19 | c32address, 20 | c32addressDecode, 21 | c32normalize, 22 | versions, 23 | c32ToB58, 24 | b58ToC32, 25 | }; 26 | -------------------------------------------------------------------------------- /packages/coin-stacks/src/common/config.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2017 Blockstack Inc. 5 | * https://github.com/hirosystems/stacks.js/blob/main/LICENSE 6 | * */ 7 | 8 | 9 | // import { network } from './network' 10 | 11 | /** 12 | * @ignore 13 | */ 14 | const config = { 15 | // network: network.defaults.MAINNET_DEFAULT, 16 | network: { 17 | layer1: 'placeholder', 18 | }, 19 | logLevel: 'debug', 20 | }; 21 | 22 | export { config }; -------------------------------------------------------------------------------- /packages/coin-stacks/src/common/constants.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2017 Blockstack Inc. 5 | * https://github.com/hirosystems/stacks.js/blob/main/LICENSE 6 | * */ 7 | 8 | export enum ChainID { 9 | Testnet = 0x80000000, 10 | Mainnet = 0x00000001, 11 | } 12 | 13 | export enum TransactionVersion { 14 | Mainnet = 0x00, 15 | Testnet = 0x80, 16 | } 17 | 18 | /** 19 | * @ignore 20 | */ 21 | export const PRIVATE_KEY_COMPRESSED_LENGTH = 33; 22 | 23 | /** 24 | * @ignore 25 | */ 26 | export const PRIVATE_KEY_UNCOMPRESSED_LENGTH = 32; 27 | 28 | /** 29 | * @ignore 30 | */ 31 | export const BLOCKSTACK_DEFAULT_GAIA_HUB_URL = 'https://hub.blockstack.org'; -------------------------------------------------------------------------------- /packages/coin-stacks/src/common/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2017 Blockstack Inc. 5 | * https://github.com/hirosystems/stacks.js/blob/main/LICENSE 6 | * */ 7 | 8 | export * from './config'; 9 | export * from './errors'; 10 | export * from './logger'; 11 | export * from './utils'; 12 | export * from './constants'; 13 | export * from './signatures'; 14 | export * from './keys'; 15 | export * from './buffer'; -------------------------------------------------------------------------------- /packages/coin-stacks/src/common/keys.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2017 Blockstack Inc. 5 | * https://github.com/hirosystems/stacks.js/blob/main/LICENSE 6 | * */ 7 | 8 | import { hexToBytes } from './utils'; 9 | 10 | /** 11 | * @private 12 | * @ignore 13 | */ 14 | export function privateKeyToBytes(privateKey: string | Uint8Array): Uint8Array { 15 | const privateKeyBuffer = typeof privateKey === 'string' ? hexToBytes(privateKey) : privateKey; 16 | 17 | if (privateKeyBuffer.length != 32 && privateKeyBuffer.length != 33) { 18 | throw new Error( 19 | `Improperly formatted private-key. Private-key byte length should be 32 or 33. Length provided: ${privateKeyBuffer.length}` 20 | ); 21 | } 22 | 23 | if (privateKeyBuffer.length == 33 && privateKeyBuffer[32] !== 1) { 24 | throw new Error( 25 | 'Improperly formatted private-key. 33 bytes indicate compressed key, but the last byte must be == 01' 26 | ); 27 | } 28 | 29 | return privateKeyBuffer; 30 | } -------------------------------------------------------------------------------- /packages/coin-stacks/src/common/signatures.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2017 Blockstack Inc. 5 | * https://github.com/hirosystems/stacks.js/blob/main/LICENSE 6 | * */ 7 | 8 | import { hexToInt } from './utils'; 9 | 10 | const COORDINATE_BYTES = 32; 11 | 12 | /** @ignore */ 13 | export function parseRecoverableSignatureVrs(signature: string) { 14 | // todo: prefer RSV format or add format options of message signing functions 15 | if (signature.length < COORDINATE_BYTES * 2 * 2 + 1) { 16 | throw new Error('Invalid signature'); 17 | } 18 | const recoveryIdHex = signature.slice(0, 2); 19 | const r = signature.slice(2, 2 + COORDINATE_BYTES * 2); 20 | const s = signature.slice(2 + COORDINATE_BYTES * 2); 21 | return { 22 | recoveryId: hexToInt(recoveryIdHex), 23 | r, 24 | s, 25 | }; 26 | } 27 | 28 | /** @ignore */ 29 | export function signatureVrsToRsv(signature: string) { 30 | return signature.slice(2) + signature.slice(0, 2); 31 | } 32 | 33 | /** @ignore */ 34 | export function signatureRsvToVrs(signature: string) { 35 | return signature.slice(-2) + signature.slice(0, -2); 36 | } -------------------------------------------------------------------------------- /packages/coin-stacks/src/encryption/cryptoRandom.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2017 Blockstack Inc. 5 | * https://github.com/hirosystems/stacks.js/blob/main/LICENSE 6 | * */ 7 | 8 | import { base } from '@okxweb3/crypto-lib'; 9 | 10 | /** 11 | * Reexports @noble/secp256k1's randombytes 12 | * Generates bytes with random bytes of given length 13 | * @param bytesLength an optional bytes length, default `32` bytes 14 | * @return {Uint8Array} random bytes 15 | */ 16 | export const randomBytes = (bytesLength: number = 32): Uint8Array => base.randomBytes(bytesLength); 17 | 18 | /** Optional function to generate cryptographically secure random bytes */ 19 | export type GetRandomBytes = (count: number) => Uint8Array; 20 | -------------------------------------------------------------------------------- /packages/coin-stacks/src/encryption/hashRipemd160.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2017 Blockstack Inc. 5 | * https://github.com/hirosystems/stacks.js/blob/main/LICENSE 6 | * */ 7 | 8 | import { base } from '@okxweb3/crypto-lib'; 9 | 10 | export function hashRipemd160(data: Uint8Array) { 11 | return base.ripemd160(data); 12 | } 13 | -------------------------------------------------------------------------------- /packages/coin-stacks/src/encryption/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2017 Blockstack Inc. 5 | * https://github.com/hirosystems/stacks.js/blob/main/LICENSE 6 | * */ 7 | 8 | export * from './keys'; 9 | export * from './cryptoRandom'; 10 | export * from './sha2Hash'; 11 | export * from './utils'; 12 | export * from './messageSignature'; 13 | export * from './ec'; 14 | -------------------------------------------------------------------------------- /packages/coin-stacks/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './transactions'; 2 | export * from './stacking'; 3 | export * from './network'; 4 | export * from './c32check'; 5 | export * from './transaction'; 6 | export {bytesToHex} from './common'; 7 | export {hashMessage,verifyMessageSignatureRsv} from './encryption'; 8 | export * from "./Stxwallet" 9 | -------------------------------------------------------------------------------- /packages/coin-stacks/src/network/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2017 Blockstack Inc. 5 | * https://github.com/hirosystems/stacks.js/blob/main/LICENSE 6 | * */ 7 | 8 | export * from './network'; -------------------------------------------------------------------------------- /packages/coin-stacks/src/transactions/clarity/constants.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2017 Blockstack Inc. 5 | * https://github.com/hirosystems/stacks.js/blob/main/LICENSE 6 | * */ 7 | 8 | /** 9 | * Type IDs corresponding to each of the Clarity value types as described here: 10 | * {@link https://github.com/blockstack/blockstack-core/blob/sip/sip-005/sip/sip-005-blocks-and-transactions.md#clarity-value-representation} 11 | */ 12 | export enum ClarityType { 13 | Int = 0x00, 14 | UInt = 0x01, 15 | Buffer = 0x02, 16 | BoolTrue = 0x03, 17 | BoolFalse = 0x04, 18 | PrincipalStandard = 0x05, 19 | PrincipalContract = 0x06, 20 | ResponseOk = 0x07, 21 | ResponseErr = 0x08, 22 | OptionalNone = 0x09, 23 | OptionalSome = 0x0a, 24 | List = 0x0b, 25 | Tuple = 0x0c, 26 | StringASCII = 0x0d, 27 | StringUTF8 = 0x0e, 28 | } -------------------------------------------------------------------------------- /packages/coin-stacks/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "allowJs": true, // Allows javascript files to be compiled 5 | "resolveJsonModule" : true, 6 | "outDir": "./dist", 7 | "rootDir": "./src", 8 | "experimentalDecorators": true, 9 | "lib": [ 10 | "dom" 11 | ] 12 | }, 13 | "include": [ 14 | "src/**/*.ts", 15 | "src/**/*.js", 16 | "src/**/*.json" 17 | ], 18 | "exclude": [ 19 | "**/node_modules" 20 | ] 21 | } 22 | 23 | -------------------------------------------------------------------------------- /packages/coin-starknet/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | # Change Log 3 | 4 | All notable changes to this project will be documented in this file. 5 | 6 | 7 | # [1.1.0](https://github.com/okx/js-wallet-sdk)(2024-01-15) 8 | 9 | ### New Features 10 | 11 | - **coin-starknet:** support signCommonMsg ([](https://github.com/okx/js-wallet-sdk)) 12 | 13 | # [1.0.4](https://github.com/okx/js-wallet-sdk) (2024-08-20) 14 | 15 | ### Fix 16 | 17 | - **coin-starknet:** upgrade private key verification ([](https://github.com/okx/js-wallet-sdk)) 18 | 19 | -------------------------------------------------------------------------------- /packages/coin-starknet/jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ 2 | module.exports = { 3 | preset: 'ts-jest', 4 | testEnvironment: 'node', 5 | }; 6 | 7 | -------------------------------------------------------------------------------- /packages/coin-starknet/src/account/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2021 Sean James Han 5 | * https://raw.githubusercontent.com/0xs34n/starknet.js/develop/LICENSE 6 | * */ 7 | export * from './default'; 8 | export * from './interface'; 9 | -------------------------------------------------------------------------------- /packages/coin-starknet/src/signer/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2021 Sean James Han 5 | * https://raw.githubusercontent.com/0xs34n/starknet.js/develop/LICENSE 6 | * */ 7 | 8 | export * from './interface'; 9 | export * from './default'; 10 | -------------------------------------------------------------------------------- /packages/coin-starknet/src/types/api/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2021 Sean James Han 5 | * https://raw.githubusercontent.com/0xs34n/starknet.js/develop/LICENSE 6 | * */ 7 | 8 | import { BigNumberish } from '../../utils/num'; 9 | import { Signature } from '../lib'; 10 | 11 | export type Calldata = string[]; 12 | 13 | export type Overrides = { 14 | maxFee?: BigNumberish; 15 | nonce?: BigNumberish; 16 | signature?: Signature; 17 | parseRequest: Boolean; 18 | }; 19 | -------------------------------------------------------------------------------- /packages/coin-starknet/src/types/contract.ts: -------------------------------------------------------------------------------- 1 | export type AsyncContractFunction = (...args: Array) => Promise; 2 | export type ContractFunction = (...args: Array) => any; 3 | export type Result = { 4 | [key: string]: any; 5 | }; 6 | -------------------------------------------------------------------------------- /packages/coin-starknet/src/types/index.ts: -------------------------------------------------------------------------------- 1 | export * from './lib'; 2 | export { Calldata, Overrides } from './api'; 3 | export * from './signer'; 4 | export * from './contract'; 5 | export * from './account'; 6 | export * from './provider'; 7 | export * from './api/sequencer'; 8 | export * from './api/rpc'; 9 | -------------------------------------------------------------------------------- /packages/coin-starknet/src/types/lib/contract/abi.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2021 Sean James Han 5 | * https://raw.githubusercontent.com/0xs34n/starknet.js/develop/LICENSE 6 | * */ 7 | 8 | /** ABI */ 9 | export type Abi = Array; 10 | 11 | // Basic elements 12 | export type AbiEntry = { name: string; type: 'felt' | 'felt*' | string }; 13 | 14 | enum FunctionAbiType { 15 | 'function', 16 | 'l1_handler', 17 | 'constructor', 18 | } 19 | 20 | // Sub elements 21 | export type FunctionAbi = { 22 | inputs: AbiEntry[]; 23 | name: string; 24 | outputs: AbiEntry[]; 25 | stateMutability?: 'view'; 26 | state_mutability?: string; // Cairo 1 Abi 27 | type: FunctionAbiType; 28 | }; 29 | 30 | export type AbiStructs = { [name: string]: StructAbi }; 31 | 32 | export type StructAbi = { 33 | members: (AbiEntry & { offset: number })[]; 34 | name: string; 35 | size: number; 36 | type: 'struct'; 37 | }; 38 | 39 | type EventAbi = any; 40 | -------------------------------------------------------------------------------- /packages/coin-starknet/src/types/lib/contract/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2021 Sean James Han 5 | * https://raw.githubusercontent.com/0xs34n/starknet.js/develop/LICENSE 6 | * */ 7 | 8 | import { LegacyCompiledContract, LegacyContractClass } from './legacy'; 9 | import { CompiledSierra, SierraContractClass } from './sierra'; 10 | 11 | // Final types 12 | export type ContractClass = LegacyContractClass | SierraContractClass; 13 | export type CompiledContract = LegacyCompiledContract | CompiledSierra; 14 | export type CairoContract = ContractClass | CompiledContract; 15 | 16 | // Basic elements 17 | export enum EntryPointType { 18 | EXTERNAL = 'EXTERNAL', 19 | L1_HANDLER = 'L1_HANDLER', 20 | CONSTRUCTOR = 'CONSTRUCTOR', 21 | } 22 | 23 | export * from './abi'; 24 | export * from './legacy'; 25 | export * from './sierra'; 26 | -------------------------------------------------------------------------------- /packages/coin-starknet/src/types/lib/contract/legacy.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2021 Sean James Han 5 | * https://raw.githubusercontent.com/0xs34n/starknet.js/develop/LICENSE 6 | * */ 7 | 8 | import { Abi } from './abi'; 9 | 10 | /** LEGACY CONTRACT */ 11 | export type LegacyContractClass = { 12 | program: CompressedProgram; 13 | entry_points_by_type: EntryPointsByType; 14 | abi: Abi; 15 | }; 16 | 17 | export type LegacyCompiledContract = Omit & { 18 | program: Program; 19 | }; 20 | 21 | /** SUBTYPES */ 22 | export type Builtins = string[]; 23 | export type CompressedProgram = string; 24 | 25 | export type EntryPointsByType = { 26 | CONSTRUCTOR: ContractEntryPointFields[]; 27 | EXTERNAL: ContractEntryPointFields[]; 28 | L1_HANDLER: ContractEntryPointFields[]; 29 | }; 30 | 31 | export type ContractEntryPointFields = { 32 | selector: string; 33 | offset: string; 34 | builtins?: Builtins; 35 | }; 36 | 37 | export interface Program extends Record { 38 | builtins: string[]; 39 | data: string[]; 40 | // TODO: Add missing properties 41 | } 42 | -------------------------------------------------------------------------------- /packages/coin-starknet/src/types/signer.ts: -------------------------------------------------------------------------------- 1 | import { StarknetChainId } from '../constants'; 2 | import { BigNumberish } from '../utils/num'; 3 | import { CairoVersion, DeployAccountContractPayload, InvocationsDetails } from './lib'; 4 | 5 | export interface InvocationsSignerDetails extends Required { 6 | walletAddress: string; 7 | chainId: StarknetChainId; 8 | cairoVersion: CairoVersion; 9 | } 10 | 11 | export interface DeclareSignerDetails { 12 | classHash: string; 13 | senderAddress: string; 14 | chainId: StarknetChainId; 15 | maxFee: BigNumberish; 16 | version: BigNumberish; 17 | nonce: BigNumberish; 18 | compiledClassHash?: string; 19 | } 20 | 21 | export type DeployAccountSignerDetails = Required & 22 | Omit, 'cairoVersion'> & { 23 | contractAddress: BigNumberish; 24 | chainId: StarknetChainId; 25 | }; 26 | -------------------------------------------------------------------------------- /packages/coin-starknet/src/utils/address.ts: -------------------------------------------------------------------------------- 1 | import { MASK_251, ZERO } from '../constants'; 2 | import { addHexPrefix, removeHexPrefix } from './encode'; 3 | import { keccakBn } from './hash'; 4 | import { BigNumberish, assertInRange, toHex } from './num'; 5 | 6 | export function addAddressPadding(address: BigNumberish): string { 7 | return addHexPrefix(removeHexPrefix(toHex(address)).padStart(64, '0')); 8 | } 9 | 10 | export function validateAndParseAddress(address: BigNumberish): string { 11 | assertInRange(address, ZERO, MASK_251, 'Starknet Address'); 12 | 13 | const result = addAddressPadding(address); 14 | 15 | if (!result.match(/^(0x)?[0-9a-fA-F]{64}$/)) { 16 | throw new Error('Invalid Address Format'); 17 | } 18 | 19 | return result; 20 | } -------------------------------------------------------------------------------- /packages/coin-starknet/src/utils/assert.ts: -------------------------------------------------------------------------------- 1 | export default function assert(condition: any, message?: string): asserts condition { 2 | if (!condition) { 3 | throw new Error(message || 'Assertion failure'); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /packages/coin-starknet/src/utils/ec.ts: -------------------------------------------------------------------------------- 1 | import {signUtil} from "@okxweb3/crypto-lib" 2 | export const starkCurve = signUtil.schnorr.stark; -------------------------------------------------------------------------------- /packages/coin-starknet/src/utils/json.ts: -------------------------------------------------------------------------------- 1 | // the ts-ignore suppresses an esm to cjs import error that is resolved with bundling 2 | // @ts-ignore 3 | import * as json from '../utils/json/index'; 4 | 5 | const parseIntAsNumberOrBigInt = (x: string) => { 6 | if (!json.isInteger(x)) return parseFloat(x); 7 | const v = parseInt(x, 10); 8 | return Number.isSafeInteger(v) ? v : BigInt(x); 9 | }; 10 | // NOTE: the String() wrapping is used so the behaviour conforms to JSON.parse() 11 | // which can accept simple data types but is not represented in the default typing 12 | export const parse = (x: string): any => json.parse(String(x), undefined, parseIntAsNumberOrBigInt); 13 | export const parseAlwaysAsBig = (x: string): any => 14 | json.parse(String(x), undefined, json.parseNumberAndBigInt); 15 | 16 | // NOTE: the not-null assertion is used so the return type conforms to JSON.stringify() 17 | // which can also return undefined but is not represented in the default typing 18 | export const stringify = (...p: Parameters): string => json.stringify(...p)!; 19 | /** @deprecated */ 20 | export const stringifyAlwaysAsBig = stringify; 21 | -------------------------------------------------------------------------------- /packages/coin-starknet/src/utils/json/index.ts: -------------------------------------------------------------------------------- 1 | export { parse } from './parse' 2 | export { stringify } from './stringify' 3 | export { LosslessNumber, isLosslessNumber, toLosslessNumber } from './LosslessNumber' 4 | export { parseLosslessNumber, parseNumberAndBigInt } from './numberParsers' 5 | export { 6 | UnsafeNumberReason, 7 | isInteger, 8 | isNumber, 9 | isSafeNumber, 10 | toSafeNumberOrThrow, 11 | getUnsafeNumberReason 12 | } from './utils' 13 | export * from './types' -------------------------------------------------------------------------------- /packages/coin-starknet/src/utils/json/numberParsers.ts: -------------------------------------------------------------------------------- 1 | import { LosslessNumber } from './LosslessNumber' 2 | import { isInteger } from './utils' 3 | 4 | export function parseLosslessNumber(value: string): LosslessNumber { 5 | return new LosslessNumber(value) 6 | } 7 | 8 | export function parseNumberAndBigInt(value: string): number | bigint { 9 | return isInteger(value) ? BigInt(value) : parseFloat(value) 10 | } -------------------------------------------------------------------------------- /packages/coin-starknet/src/utils/typedData/utils.ts: -------------------------------------------------------------------------------- 1 | import { TypedData } from './types'; 2 | 3 | /** 4 | * Validates that `data` matches the EIP-712 JSON schema. 5 | * 6 | * @param {any} data 7 | * @return {boolean} 8 | */ 9 | export const validateTypedData = (data: unknown): data is TypedData => { 10 | const typedData = data as TypedData; 11 | 12 | // Validate that the data matches the EIP-712 JSON schema 13 | const valid = Boolean(typedData.types && typedData.primaryType && typedData.message); 14 | 15 | return valid; 16 | }; 17 | -------------------------------------------------------------------------------- /packages/coin-stellar/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | # Change Log 3 | 4 | All notable changes to this project will be documented in this file. 5 | 6 | # [1.0.2](https://github.com/okx/js-wallet-sdk)(2024-02-18) 7 | 8 | ### New Features 9 | 10 | - **coin-stellar:** support PI network , add validAddress for M address ([](https://github.com/okx/js-wallet-sdk)) 11 | 12 | 13 | # [1.0.1](https://github.com/okx/js-wallet-sdk)(2024-02-18) 14 | 15 | ### New Features 16 | 17 | - **coin-stellar:** support PI network ,add test case and function ([](https://github.com/okx/js-wallet-sdk)) 18 | 19 | 20 | # [1.0.0](https://github.com/okx/js-wallet-sdk)(2024-01-15) 21 | 22 | ### New Features 23 | 24 | - **coin-stellar:** support PI network ([](https://github.com/okx/js-wallet-sdk)) 25 | -------------------------------------------------------------------------------- /packages/coin-stellar/babel.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "@babel/preset-env" 4 | ], 5 | "env": { 6 | "development": { 7 | "plugins": [ 8 | "istanbul" 9 | ] 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/coin-stellar/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | preset: 'ts-jest', 3 | testEnvironment: 'node', 4 | moduleFileExtensions: ['ts', 'js', 'json'], 5 | transform: { 6 | '^.+\\.ts$': 'ts-jest', 7 | '^.+\\.js$': 'babel-jest' // 如果需要对 JS 文件也进行转换,可以使用 Babel 或其他 JS 转译器 8 | }, 9 | testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(ts|js)$', // 匹配 .test.ts, .test.js, .spec.ts 和 .spec.js 文件 10 | collectCoverageFrom: [ 11 | 'src/**/*.{js,ts}', // 包括 ts 和 js 文件的覆盖率收集 12 | '!src/**/*.d.ts' // 排除 .d.ts 类型声明文件 13 | ], 14 | globals: { 15 | 'ts-jest': { 16 | tsconfig: 'tsconfig.json', // 指定 tsconfig 文件的位置 17 | diagnostics: true, // 启用诊断(可选) 18 | } 19 | } 20 | }; -------------------------------------------------------------------------------- /packages/coin-stellar/src/index.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | export * from "./stellar_base" 4 | export * from "./StellarWallet" 5 | export * from "./PIWallet" 6 | 7 | 8 | export default module.exports; 9 | -------------------------------------------------------------------------------- /packages/coin-stellar/src/stellar_base/hashing.js: -------------------------------------------------------------------------------- 1 | import { sha256 } from 'sha.js'; 2 | 3 | export function hash(data) { 4 | const hasher = new sha256(); 5 | hasher.update(data, 'utf8'); 6 | return hasher.digest(); 7 | } 8 | -------------------------------------------------------------------------------- /packages/coin-stellar/src/stellar_base/jsxdr.js: -------------------------------------------------------------------------------- 1 | import { XdrWriter, XdrReader } from '@stellar/js-xdr'; 2 | 3 | const cereal = { XdrWriter, XdrReader }; 4 | export default cereal; 5 | -------------------------------------------------------------------------------- /packages/coin-stellar/src/stellar_base/network.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Contains passphrases for common networks: 3 | * * `Networks.PUBLIC`: `Public Global Stellar Network ; September 2015` 4 | * * `Networks.TESTNET`: `Test SDF Network ; September 2015` 5 | * * `Networks.FUTURENET`: `Test SDF Future Network ; October 2022` 6 | * * `Networks.STANDALONE`: `Standalone Network ; February 2017` 7 | * 8 | * @type {{PUBLIC: string, TESTNET: string, FUTURENET: string, STANDALONE: string }} 9 | */ 10 | export const Networks = { 11 | PUBLIC: 'Public Global Stellar Network ; September 2015', 12 | TESTNET: 'Test SDF Network ; September 2015', 13 | FUTURENET: 'Test SDF Future Network ; October 2022', 14 | SANDBOX: 'Local Sandbox Stellar Network ; September 2022', 15 | STANDALONE: 'Standalone Network ; February 2017' 16 | }; 17 | -------------------------------------------------------------------------------- /packages/coin-stellar/src/stellar_base/numbers/int128.js: -------------------------------------------------------------------------------- 1 | import { LargeInt } from '@stellar/js-xdr'; 2 | 3 | export class Int128 extends LargeInt { 4 | /** 5 | * Construct a signed 128-bit integer that can be XDR-encoded. 6 | * 7 | * @param {Array} args - one or more slices to encode 8 | * in big-endian format (i.e. earlier elements are higher bits) 9 | */ 10 | constructor(...args) { 11 | super(args); 12 | } 13 | 14 | get unsigned() { 15 | return false; 16 | } 17 | 18 | get size() { 19 | return 128; 20 | } 21 | } 22 | 23 | Int128.defineIntBoundaries(); 24 | -------------------------------------------------------------------------------- /packages/coin-stellar/src/stellar_base/numbers/int256.js: -------------------------------------------------------------------------------- 1 | import { LargeInt } from '@stellar/js-xdr'; 2 | 3 | export class Int256 extends LargeInt { 4 | /** 5 | * Construct a signed 256-bit integer that can be XDR-encoded. 6 | * 7 | * @param {Array} args - one or more slices to encode 8 | * in big-endian format (i.e. earlier elements are higher bits) 9 | */ 10 | constructor(...args) { 11 | super(args); 12 | } 13 | 14 | get unsigned() { 15 | return false; 16 | } 17 | 18 | get size() { 19 | return 256; 20 | } 21 | } 22 | 23 | Int256.defineIntBoundaries(); 24 | -------------------------------------------------------------------------------- /packages/coin-stellar/src/stellar_base/numbers/uint128.js: -------------------------------------------------------------------------------- 1 | import { LargeInt } from '@stellar/js-xdr'; 2 | 3 | export class Uint128 extends LargeInt { 4 | /** 5 | * Construct an unsigned 128-bit integer that can be XDR-encoded. 6 | * 7 | * @param {Array} args - one or more slices to encode 8 | * in big-endian format (i.e. earlier elements are higher bits) 9 | */ 10 | constructor(...args) { 11 | super(args); 12 | } 13 | 14 | get unsigned() { 15 | return true; 16 | } 17 | 18 | get size() { 19 | return 128; 20 | } 21 | } 22 | 23 | Uint128.defineIntBoundaries(); 24 | -------------------------------------------------------------------------------- /packages/coin-stellar/src/stellar_base/numbers/uint256.js: -------------------------------------------------------------------------------- 1 | import { LargeInt } from '@stellar/js-xdr'; 2 | 3 | export class Uint256 extends LargeInt { 4 | /** 5 | * Construct an unsigned 256-bit integer that can be XDR-encoded. 6 | * 7 | * @param {Array} args - one or more slices to encode 8 | * in big-endian format (i.e. earlier elements are higher bits) 9 | */ 10 | constructor(...args) { 11 | super(args); 12 | } 13 | 14 | get unsigned() { 15 | return true; 16 | } 17 | 18 | get size() { 19 | return 256; 20 | } 21 | } 22 | 23 | Uint256.defineIntBoundaries(); 24 | -------------------------------------------------------------------------------- /packages/coin-stellar/src/stellar_base/operations/account_merge.js: -------------------------------------------------------------------------------- 1 | import xdr from '../xdr'; 2 | import { decodeAddressToMuxedAccount } from '../util/decode_encode_muxed_account'; 3 | 4 | /** 5 | * Transfers native balance to destination account. 6 | * 7 | * @function 8 | * @alias Operation.accountMerge 9 | * 10 | * @param {object} opts - options object 11 | * @param {string} opts.destination - destination to merge the source account into 12 | * @param {string} [opts.source] - operation source account (defaults to 13 | * transaction source) 14 | * 15 | * @returns {xdr.Operation} an Account Merge operation (xdr.AccountMergeOp) 16 | */ 17 | export function accountMerge(opts) { 18 | const opAttributes = {}; 19 | try { 20 | opAttributes.body = xdr.OperationBody.accountMerge( 21 | decodeAddressToMuxedAccount(opts.destination) 22 | ); 23 | } catch (e) { 24 | throw new Error('destination is invalid'); 25 | } 26 | this.setSourceAccount(opAttributes, opts); 27 | 28 | return new xdr.Operation(opAttributes); 29 | } 30 | -------------------------------------------------------------------------------- /packages/coin-stellar/src/stellar_base/operations/end_sponsoring_future_reserves.js: -------------------------------------------------------------------------------- 1 | import xdr from '../xdr'; 2 | 3 | /** 4 | * Create an "end sponsoring future reserves" operation. 5 | * @function 6 | * @alias Operation.endSponsoringFutureReserves 7 | * @param {object} opts Options object 8 | * @param {string} [opts.source] - The source account for the operation. Defaults to the transaction's source account. 9 | * @returns {xdr.Operation} xdr operation 10 | * 11 | * @example 12 | * const op = Operation.endSponsoringFutureReserves(); 13 | * 14 | */ 15 | export function endSponsoringFutureReserves(opts = {}) { 16 | const opAttributes = {}; 17 | opAttributes.body = xdr.OperationBody.endSponsoringFutureReserves(); 18 | this.setSourceAccount(opAttributes, opts); 19 | 20 | return new xdr.Operation(opAttributes); 21 | } 22 | -------------------------------------------------------------------------------- /packages/coin-stellar/src/stellar_base/operations/inflation.js: -------------------------------------------------------------------------------- 1 | import xdr from '../xdr'; 2 | 3 | /** 4 | * This operation generates the inflation. 5 | * @function 6 | * @alias Operation.inflation 7 | * @param {object} [opts] Options object 8 | * @param {string} [opts.source] - The optional source account. 9 | * @returns {xdr.InflationOp} Inflation operation 10 | */ 11 | export function inflation(opts = {}) { 12 | const opAttributes = {}; 13 | opAttributes.body = xdr.OperationBody.inflation(); 14 | this.setSourceAccount(opAttributes, opts); 15 | return new xdr.Operation(opAttributes); 16 | } 17 | -------------------------------------------------------------------------------- /packages/coin-stellar/src/stellar_base/util/bignumber.js: -------------------------------------------------------------------------------- 1 | import OriginBigNumber from 'bignumber.js'; 2 | 3 | const BigNumber = OriginBigNumber.clone(); 4 | 5 | BigNumber.DEBUG = true; // gives us exceptions on bad constructor values 6 | 7 | export default BigNumber; 8 | -------------------------------------------------------------------------------- /packages/coin-stellar/src/stellar_base/util/checksum.js: -------------------------------------------------------------------------------- 1 | export function verifyChecksum(expected, actual) { 2 | if (expected.length !== actual.length) { 3 | return false; 4 | } 5 | 6 | if (expected.length === 0) { 7 | return true; 8 | } 9 | 10 | for (let i = 0; i < expected.length; i += 1) { 11 | if (expected[i] !== actual[i]) { 12 | return false; 13 | } 14 | } 15 | 16 | return true; 17 | } 18 | -------------------------------------------------------------------------------- /packages/coin-stellar/src/stellar_base/util/util.js: -------------------------------------------------------------------------------- 1 | export const trimEnd = (input, char) => { 2 | const isNumber = typeof input === 'number'; 3 | let str = String(input); 4 | 5 | while (str.endsWith(char)) { 6 | str = str.slice(0, -1); 7 | } 8 | 9 | return isNumber ? Number(str) : str; 10 | }; 11 | -------------------------------------------------------------------------------- /packages/coin-stellar/src/stellar_base/xdr.js: -------------------------------------------------------------------------------- 1 | import xdr from './generated/curr_generated'; 2 | 3 | export default xdr; 4 | -------------------------------------------------------------------------------- /packages/coin-stellar/src/utils.ts: -------------------------------------------------------------------------------- 1 | export function convertWithDecimals(numStr: string, decimals: number) { 2 | if (numStr == "0") { 3 | return numStr 4 | } 5 | if (!isPositiveIntegerNoZero(numStr)) { 6 | throw new RangeError("Number should be a positive integer"); 7 | } 8 | if (numStr.length <= decimals) { 9 | numStr = addLeadingZeros(numStr, decimals + 1); 10 | } 11 | let position = numStr.length - decimals 12 | return numStr.slice(0, position) + "." + numStr.slice(position); 13 | } 14 | 15 | function addLeadingZeros(str: string | number, length: number): string { 16 | return String(str).padStart(length, "0"); 17 | } 18 | 19 | function isPositiveIntegerNoZero(str: string): boolean { 20 | return /^[1-9]\d*$/.test(str); 21 | } -------------------------------------------------------------------------------- /packages/coin-stellar/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "target": "es6", 5 | "module": "commonjs", 6 | "strict": true, 7 | "allowJs": true, // Allows javascript files to be compiled 8 | "resolveJsonModule" : true, 9 | "outDir": "./dist", 10 | "rootDir": "./src", 11 | "experimentalDecorators": true, 12 | "esModuleInterop": true, 13 | "skipLibCheck": true, 14 | "forceConsistentCasingInFileNames": true, 15 | // "noEmit": true // 不生成编译输出,只用于类型检查 16 | }, 17 | "include": [ 18 | "src/**/*.ts", 19 | "src/**/*.js", 20 | "src/**/*.json" 21 | ], 22 | "exclude": [ 23 | "**/node_modules" 24 | ] 25 | } -------------------------------------------------------------------------------- /packages/coin-sui/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | # [1.1.0](https://github.com/okx/js-wallet-sdk)(2024-01-15) 6 | 7 | ### New Features 8 | 9 | - **coin-sui:** support signCommonMsg ([](https://github.com/okx/js-wallet-sdk)) 10 | 11 | # [1.0.5](https://github.com/okx/js-wallet-sdk) (2024-08-20) 12 | 13 | ### Fix 14 | 15 | - **coin-sui:** upgrade private key verification ([](https://github.com/okx/js-wallet-sdk)) 16 | 17 | # [1.0.3](https://github.com/okx/js-wallet-sdk) (2024-4-29) 18 | 19 | ###Bug Fixes 20 | 21 | - **coin-sui:** upgrade sui signing message ([](https://github.com/okx/js-wallet-sdk)) 22 | 23 | # [1.0.2](https://github.com/okx/js-wallet-sdk) (2024-3-5) 24 | 25 | ### New Features 26 | 27 | - **coin-sui:** support sui new private key format :suiprivkey**** ([](https://github.com/okx/js-wallet-sdk)) 28 | 29 | # [1.0.1](https://github.com/okx/js-wallet-sdk) (2023-10-16) 30 | 31 | ### Bug Fixes 32 | 33 | - **coin-sui:** change sui derived 34 | path ([904c66c](https://github.com/okx/js-wallet-sdk/pull/4/commits/904c66caaad9c679f0d7263957109f6743265a00)) -------------------------------------------------------------------------------- /packages/coin-sui/jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ 2 | module.exports = { 3 | preset: 'ts-jest', 4 | testEnvironment: 'node', 5 | }; -------------------------------------------------------------------------------- /packages/coin-sui/src/bcs/hex.ts: -------------------------------------------------------------------------------- 1 | // Copyright (c) Mysten Labs, Inc. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | export function fromHEX(hexStr: string): Uint8Array { 5 | // @ts-ignore 6 | let intArr = hexStr 7 | .replace('0x', '') 8 | .match(/.{1,2}/g) 9 | .map(byte => parseInt(byte, 16)); 10 | 11 | if (intArr === null) { 12 | throw new Error(`Unable to parse HEX: ${hexStr}`); 13 | } 14 | 15 | return Uint8Array.from(intArr); 16 | } 17 | 18 | export function toHEX(bytes: Uint8Array): string { 19 | return bytes.reduce( 20 | (str, byte) => str + byte.toString(16).padStart(2, '0'), 21 | '' 22 | ); 23 | } 24 | -------------------------------------------------------------------------------- /packages/coin-sui/src/builder/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright (c) Mysten Labs, Inc. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | export * from './TransactionBlock'; 5 | export {TransactionBlockDataBuilder} from './TransactionBlockData'; 6 | export * from './Transactions'; 7 | export * from './Inputs'; 8 | export * from './bcs'; 9 | export * from './serializer'; 10 | -------------------------------------------------------------------------------- /packages/coin-sui/src/builder/utils.ts: -------------------------------------------------------------------------------- 1 | // Copyright (c) Mysten Labs, Inc. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { create as superstructCreate, Struct } from 'superstruct'; 5 | 6 | export function create(value: T, struct: Struct): T { 7 | return superstructCreate(value, struct); 8 | } 9 | 10 | export type WellKnownEncoding = 11 | | { 12 | kind: 'object'; 13 | } 14 | | { 15 | kind: 'pure'; 16 | type: string; 17 | }; 18 | 19 | export const TRANSACTION_TYPE = Symbol('transaction-argument-type'); 20 | -------------------------------------------------------------------------------- /packages/coin-sui/src/cryptography/hash.ts: -------------------------------------------------------------------------------- 1 | // Copyright (c) Mysten Labs, Inc. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import {base} from "@okxweb3/crypto-lib"; 5 | 6 | /** 7 | * Generates a Blake2b hash of typed data as a base64 string. 8 | * 9 | * @param typeTag type tag (e.g. TransactionData, SenderSignedData) 10 | * @param data data to hash 11 | */ 12 | export function hashTypedData(typeTag: string, data: Uint8Array): Uint8Array { 13 | const typeTagBytes = Array.from(`${typeTag}::`).map((e) => e.charCodeAt(0)); 14 | 15 | const dataWithTag = new Uint8Array(typeTagBytes.length + data.length); 16 | dataWithTag.set(typeTagBytes); 17 | dataWithTag.set(data, typeTagBytes.length); 18 | 19 | return base.blake2b(dataWithTag, { dkLen: 32 }); 20 | } 21 | -------------------------------------------------------------------------------- /packages/coin-sui/src/cryptography/keypair.ts: -------------------------------------------------------------------------------- 1 | // Copyright (c) Mysten Labs, Inc. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { PublicKey } from './publickey'; 5 | import { SignatureScheme } from './signature'; 6 | 7 | export const PRIVATE_KEY_SIZE = 32; 8 | export const LEGACY_PRIVATE_KEY_SIZE = 64; 9 | 10 | export type ExportedKeypair = { 11 | schema: SignatureScheme; 12 | privateKey: string; 13 | }; 14 | 15 | /** 16 | * A keypair used for signing transactions. 17 | */ 18 | export interface Keypair { 19 | /** 20 | * The public key for this keypair 21 | */ 22 | getPublicKey(): PublicKey; 23 | 24 | /** 25 | * Return the signature for the data 26 | */ 27 | signData(data: Uint8Array): Uint8Array; 28 | 29 | /** 30 | * Get the key scheme of the keypair: Secp256k1 or ED25519 31 | */ 32 | getKeyScheme(): SignatureScheme; 33 | } 34 | -------------------------------------------------------------------------------- /packages/coin-sui/src/framework/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright (c) Mysten Labs, Inc. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | export * from './framework'; 5 | -------------------------------------------------------------------------------- /packages/coin-sui/src/pkg-version.ts: -------------------------------------------------------------------------------- 1 | export const pkgVersion = '0.29.1'; 2 | -------------------------------------------------------------------------------- /packages/coin-sui/src/signers/signer.ts: -------------------------------------------------------------------------------- 1 | // Copyright (c) Mysten Labs, Inc. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { SerializedSignature } from '../cryptography/signature'; 5 | 6 | /////////////////////////////// 7 | // Exported Types 8 | 9 | /////////////////////////////// 10 | // Exported Abstracts 11 | /** 12 | * Serializes a transaction to a string that can be signed by a `Signer`. 13 | */ 14 | export interface Signer { 15 | // Returns the checksum address 16 | getAddress(): Promise; 17 | 18 | /** 19 | * Returns the signature for the data and the public key of the signer 20 | */ 21 | signData(data: Uint8Array): Promise; 22 | } 23 | -------------------------------------------------------------------------------- /packages/coin-sui/src/signers/types.ts: -------------------------------------------------------------------------------- 1 | // Copyright (c) Mysten Labs, Inc. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { SerializedSignature } from '../cryptography/signature'; 5 | 6 | export type SignedTransaction = { 7 | transactionBlockBytes: string; 8 | hash: string; 9 | signature: SerializedSignature; 10 | }; 11 | 12 | export type SignedMessage = { 13 | messageBytes: string; 14 | signature: SerializedSignature; 15 | }; 16 | -------------------------------------------------------------------------------- /packages/coin-sui/src/types/faucet.ts: -------------------------------------------------------------------------------- 1 | // Copyright (c) Mysten Labs, Inc. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { array, nullable, number, object, Infer, string } from 'superstruct'; 5 | import { TransactionDigest, ObjectId } from './common'; 6 | 7 | export const FaucetCoinInfo = object({ 8 | amount: number(), 9 | id: ObjectId, 10 | transferTxDigest: TransactionDigest, 11 | }); 12 | 13 | export type FaucetCoinInfo = Infer; 14 | 15 | export const FaucetResponse = object({ 16 | transferredGasObjects: array(FaucetCoinInfo), 17 | error: nullable(string()), 18 | }); 19 | 20 | export type FaucetResponse = Infer; 21 | -------------------------------------------------------------------------------- /packages/coin-sui/src/types/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright (c) Mysten Labs, Inc. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | export * from './common'; 5 | export * from './objects'; 6 | export * from './events'; 7 | export * from './transactions'; 8 | export * from '../framework/framework'; 9 | export * from './sui-bcs'; 10 | export * from './faucet'; 11 | export * from './normalized'; 12 | export * from './validator'; 13 | export * from './coin'; 14 | export { GasCostSummary, CheckpointDigest, Checkpoint } from './checkpoints'; 15 | -------------------------------------------------------------------------------- /packages/coin-sui/src/types/option.ts: -------------------------------------------------------------------------------- 1 | // Copyright (c) Mysten Labs, Inc. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | export type Option = 5 | | T 6 | | { 7 | fields: { 8 | vec: ''; 9 | }; 10 | type: string; 11 | }; 12 | 13 | export function getOption(option: Option): T | undefined { 14 | if ( 15 | typeof option === 'object' && 16 | option !== null && 17 | 'type' in option && 18 | option.type.startsWith('0x1::option::Option<') 19 | ) { 20 | return undefined; 21 | } 22 | return option as T; 23 | } 24 | -------------------------------------------------------------------------------- /packages/coin-sui/src/utils/format.ts: -------------------------------------------------------------------------------- 1 | // Copyright (c) Mysten Labs, Inc. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | const ELLIPSIS = '\u{2026}'; 5 | 6 | export function formatAddress(address: string) { 7 | const offset = address.startsWith('0x') ? 2 : 0; 8 | 9 | return `0x${address.slice(offset, offset + 4)}${ELLIPSIS}${address.slice( 10 | -4, 11 | )}`; 12 | } 13 | 14 | export function formatDigest(digest: string) { 15 | // Use 10 first characters 16 | return `${digest.slice(0, 10)}${ELLIPSIS}`; 17 | } 18 | -------------------------------------------------------------------------------- /packages/coin-sui/src/utils/intent.ts: -------------------------------------------------------------------------------- 1 | // Copyright (c) Mysten Labs, Inc. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | // See: sui/crates/sui-types/src/intent.rs 5 | export enum AppId { 6 | Sui = 0, 7 | } 8 | 9 | export enum IntentVersion { 10 | V0 = 0, 11 | } 12 | 13 | export enum IntentScope { 14 | TransactionData = 0, 15 | TransactionEffects = 1, 16 | CheckpointSummary = 2, 17 | PersonalMessage = 3, 18 | } 19 | 20 | export type Intent = [IntentScope, IntentVersion, AppId]; 21 | 22 | function intentWithScope(scope: IntentScope): Intent { 23 | return [scope, IntentVersion.V0, AppId.Sui]; 24 | } 25 | 26 | export function messageWithIntent(scope: IntentScope, message: Uint8Array) { 27 | const intent = intentWithScope(scope); 28 | const intentMessage = new Uint8Array(intent.length + message.length); 29 | intentMessage.set(intent); 30 | intentMessage.set(message, intent.length); 31 | return intentMessage; 32 | } 33 | -------------------------------------------------------------------------------- /packages/coin-sui/src/utils/properties.ts: -------------------------------------------------------------------------------- 1 | // Copyright (c) Mysten Labs, Inc. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | export function defineReadOnly( 5 | object: T, 6 | name: K, 7 | value: T[K], 8 | ): void { 9 | Object.defineProperty(object, name, { 10 | enumerable: true, 11 | value: value, 12 | writable: false, 13 | }); 14 | } 15 | -------------------------------------------------------------------------------- /packages/coin-sui/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "allowJs": true, // allow build javascript files 5 | "resolveJsonModule" : true, 6 | "outDir": "./dist", 7 | "rootDir": "./src", 8 | "experimentalDecorators": true 9 | }, 10 | "include": [ 11 | "src/**/*.ts", 12 | "src/**/*.js", 13 | "src/**/*.json" 14 | ], 15 | "exclude": [ 16 | "**/node_modules" 17 | ] 18 | } 19 | 20 | -------------------------------------------------------------------------------- /packages/coin-ton/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | # Change Log 3 | 4 | All notable changes to this project will be documented in this file. 5 | 6 | # [1.1.0](https://github.com/okx/js-wallet-sdk)(2024-01-15) 7 | 8 | ### New Features 9 | 10 | - **coin-ton:** support signCommonMsg ([](https://github.com/okx/js-wallet-sdk)) 11 | 12 | # [1.0.3](https://github.com/okx/js-wallet-sdk) (2024-08-20) 13 | 14 | ### Fix 15 | 16 | - **coin-ton:** upgrade private key verification ([](https://github.com/okx/js-wallet-sdk)) 17 | 18 | 19 | # [1.0.1](https://github.com/okx/js-wallet-sdk) (2024-08-15) 20 | 21 | ### Feature 22 | 23 | - **coin-ton:** support ton ([1.0.1](https://github.com/okx/js-wallet-sdk)) 24 | -------------------------------------------------------------------------------- /packages/coin-ton/jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ 2 | module.exports = { 3 | preset: 'ts-jest', 4 | testEnvironment: 'node', 5 | }; -------------------------------------------------------------------------------- /packages/coin-ton/src/api/index.ts: -------------------------------------------------------------------------------- 1 | import {randomBytes} from "crypto"; 2 | 3 | export {signMultiTransaction} from './transaction' 4 | export {buildNftTransferPayload, buildNotcoinVoucherExchange} from './nfts' 5 | 6 | export function generateQueryId() { 7 | return bigintRandom(8); 8 | } 9 | 10 | export function bigintRandom(bytes: number) { 11 | let value = BigInt(0); 12 | for (const randomNumber of randomBytes(bytes)) { 13 | const randomBigInt = BigInt(randomNumber); 14 | // eslint-disable-next-line no-bitwise 15 | value = (value << BigInt(8)) + randomBigInt; 16 | } 17 | return value; 18 | } -------------------------------------------------------------------------------- /packages/coin-ton/src/api/types.ts: -------------------------------------------------------------------------------- 1 | import {Cell} from "../ton-core"; 2 | 3 | export type AnyPayload = string | Cell | Uint8Array; 4 | 5 | export interface TonTransferParams { 6 | toAddress: string; 7 | amount: bigint; 8 | payload?: AnyPayload; 9 | stateInit?: Cell; 10 | isBase64Payload?: boolean; 11 | } -------------------------------------------------------------------------------- /packages/coin-ton/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./TonWallet"; 2 | export * from "./api/address"; 3 | export * from "./api/transaction"; 4 | export * from "./ton-core"; 5 | export * from "./ton"; 6 | -------------------------------------------------------------------------------- /packages/coin-ton/src/ton-core/address/ExternalAddress.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Whales Corp. 3 | * All Rights Reserved. 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | import inspectSymbol from 'symbol.inspect'; 10 | export class ExternalAddress { 11 | 12 | static isAddress(src: any): src is ExternalAddress { 13 | return src instanceof ExternalAddress; 14 | } 15 | 16 | readonly value: bigint; 17 | readonly bits: number; 18 | 19 | constructor(value: bigint, bits: number) { 20 | this.value = value; 21 | this.bits = bits; 22 | } 23 | 24 | toString() { 25 | return `External<${this.bits}:${this.value}>`; 26 | } 27 | 28 | [inspectSymbol] = () => this.toString() 29 | } -------------------------------------------------------------------------------- /packages/coin-ton/src/ton-core/address/contractAddress.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Whales Corp. 3 | * All Rights Reserved. 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | import { beginCell } from "../boc/Builder"; 10 | import { StateInit, storeStateInit } from "../types/StateInit"; 11 | import { Address } from "./Address"; 12 | 13 | export function contractAddress(workchain: number, init: StateInit) { 14 | let hash = beginCell() 15 | .store(storeStateInit(init)) 16 | .endCell() 17 | .hash(); 18 | return new Address(workchain, hash); 19 | } -------------------------------------------------------------------------------- /packages/coin-ton/src/ton-core/boc/CellType.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Whales Corp. 3 | * All Rights Reserved. 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | export enum CellType { 10 | Ordinary = -1, 11 | PrunedBranch = 1, 12 | Library = 2, 13 | MerkleProof = 3, 14 | MerkleUpdate = 4 15 | } -------------------------------------------------------------------------------- /packages/coin-ton/src/ton-core/boc/Writable.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Whales Corp. 3 | * All Rights Reserved. 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | import { Builder } from "./Builder"; 10 | 11 | export type Writable = { writeTo: (builder: Builder) => void }; -------------------------------------------------------------------------------- /packages/coin-ton/src/ton-core/boc/cell/exoticLibrary.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Whales Corp. 3 | * All Rights Reserved. 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | import { BitReader } from "../BitReader"; 10 | import { BitString } from "../BitString"; 11 | import { Cell } from "../Cell"; 12 | 13 | export function exoticLibrary(bits: BitString, refs: Cell[]) { 14 | const reader = new BitReader(bits); 15 | 16 | // type + hash 17 | const size = 8 + 256; 18 | 19 | if (bits.length !== size) { 20 | throw new Error(`Library cell must have exactly (8 + 256) bits, got "${bits.length}"`); 21 | } 22 | 23 | // Check type 24 | let type = reader.loadUint(8); 25 | if (type !== 2) { 26 | throw new Error(`Library cell must have type 2, got "${type}"`); 27 | } 28 | 29 | return {}; 30 | } -------------------------------------------------------------------------------- /packages/coin-ton/src/ton-core/contract/ComputeError.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Whales Corp. 3 | * All Rights Reserved. 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | import { Maybe } from "../utils/maybe"; 10 | 11 | export class ComputeError extends Error { 12 | exitCode: number; 13 | debugLogs: string | null; 14 | logs: string | null; 15 | 16 | constructor(message: string, exitCode: number, opts?: { debugLogs?: Maybe, logs?: Maybe }) { 17 | super(message); 18 | this.exitCode = exitCode; 19 | this.debugLogs = opts && opts.debugLogs ? opts.debugLogs : null; 20 | this.logs = opts && opts.logs ? opts.logs : null; 21 | Object.setPrototypeOf(this, ComputeError.prototype); 22 | } 23 | } -------------------------------------------------------------------------------- /packages/coin-ton/src/ton-core/contract/Contract.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Whales Corp. 3 | * All Rights Reserved. 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | import { Address } from "../address/Address"; 10 | import { Cell } from "../boc/Cell"; 11 | import { StateInit } from "../types/StateInit"; 12 | import { Maybe } from "../utils/maybe"; 13 | import { ContractABI } from "./ContractABI"; 14 | 15 | export interface Contract { 16 | readonly address: Address; 17 | readonly init?: Maybe; 18 | readonly abi?: Maybe; 19 | } -------------------------------------------------------------------------------- /packages/coin-ton/src/ton-core/contract/ContractState.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Whales Corp. 3 | * All Rights Reserved. 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | import { Maybe } from "../utils/maybe"; 10 | 11 | export type ContractState = { 12 | balance: bigint, 13 | last: { lt: bigint, hash: Buffer } | null, 14 | state: { type: 'uninit' } | { type: 'active', code: Maybe, data: Maybe } | { type: 'frozen', stateHash: Buffer } 15 | }; -------------------------------------------------------------------------------- /packages/coin-ton/src/ton-core/contract/Sender.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Whales Corp. 3 | * All Rights Reserved. 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | import { Address } from "../address/Address"; 10 | import { Cell } from "../boc/Cell"; 11 | import { SendMode } from "../types/SendMode"; 12 | import { StateInit } from "../types/StateInit"; 13 | import { Maybe } from "../utils/maybe"; 14 | 15 | export type SenderArguments = { 16 | value: bigint, 17 | to: Address, 18 | sendMode?: Maybe, 19 | bounce?: Maybe, 20 | init?: Maybe, 21 | body?: Maybe 22 | } 23 | 24 | export interface Sender { 25 | readonly address?: Address; 26 | send(args: SenderArguments): Promise; 27 | } -------------------------------------------------------------------------------- /packages/coin-ton/src/ton-core/dict/generateMerkleUpdate.ts: -------------------------------------------------------------------------------- 1 | import { beginCell } from '../boc/Builder'; 2 | import { Cell } from '../boc/Cell'; 3 | import { DictionaryKeyTypes, Dictionary, DictionaryKey } from './Dictionary'; 4 | import { generateMerkleProof } from './generateMerkleProof'; 5 | 6 | function convertToMerkleUpdate(c1: Cell, c2: Cell): Cell { 7 | return beginCell() 8 | .storeUint(4, 8) 9 | .storeBuffer(c1.hash(0)) 10 | .storeBuffer(c2.hash(0)) 11 | .storeUint(c1.depth(0), 16) 12 | .storeUint(c2.depth(0), 16) 13 | .storeRef(c1) 14 | .storeRef(c2) 15 | .endCell({ exotic: true }); 16 | } 17 | 18 | export function generateMerkleUpdate( 19 | dict: Dictionary, 20 | key: K, 21 | keyObject: DictionaryKey, 22 | newValue: V 23 | ): Cell { 24 | const oldProof = generateMerkleProof(dict, [key], keyObject).refs[0]; 25 | dict.set(key, newValue); 26 | const newProof = generateMerkleProof(dict, [key], keyObject).refs[0]; 27 | return convertToMerkleUpdate(oldProof, newProof); 28 | } 29 | -------------------------------------------------------------------------------- /packages/coin-ton/src/ton-core/dict/utils/findCommonPrefix.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Whales Corp. 3 | * All Rights Reserved. 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | export function findCommonPrefix(src: string[], startPos = 0) { 10 | 11 | // Corner cases 12 | if (src.length === 0) { 13 | return ''; 14 | } 15 | 16 | let r = src[0].slice(startPos); 17 | 18 | for (let i = 1; i < src.length; i++) { 19 | const s = src[i]; 20 | while (s.indexOf(r, startPos) !== startPos) { 21 | r = r.substring(0, r.length - 1); 22 | 23 | if (r === '') { 24 | return r; 25 | } 26 | } 27 | } 28 | 29 | return r; 30 | } -------------------------------------------------------------------------------- /packages/coin-ton/src/ton-core/dict/utils/readUnaryLength.ts: -------------------------------------------------------------------------------- 1 | import { Slice } from '../../boc/Slice'; 2 | 3 | export function readUnaryLength(slice: Slice) { 4 | let res = 0; 5 | while (slice.loadBit()) { 6 | res++; 7 | } 8 | return res; 9 | } 10 | -------------------------------------------------------------------------------- /packages/coin-ton/src/ton-core/types/SendMode.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Whales Corp. 3 | * All Rights Reserved. 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | export enum SendMode { 10 | CARRY_ALL_REMAINING_BALANCE = 128, 11 | CARRY_ALL_REMAINING_INCOMING_VALUE = 64, 12 | DESTROY_ACCOUNT_IF_ZERO = 32, 13 | PAY_GAS_SEPARATELY = 1, 14 | IGNORE_ERRORS = 2, 15 | NONE = 0 16 | } 17 | -------------------------------------------------------------------------------- /packages/coin-ton/src/ton-core/types/TickTock.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Whales Corp. 3 | * All Rights Reserved. 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | import { Builder } from "../boc/Builder"; 10 | import { Slice } from "../boc/Slice"; 11 | 12 | // Source: https://github.com/ton-blockchain/ton/blob/24dc184a2ea67f9c47042b4104bbb4d82289fac1/crypto/block/block.tlb#L139 13 | // tick_tock$_ tick:Bool tock:Bool = TickTock; 14 | 15 | export type TickTock = { 16 | tick: boolean; 17 | tock: boolean; 18 | } 19 | 20 | export function loadTickTock(slice: Slice): TickTock { 21 | return { 22 | tick: slice.loadBit(), 23 | tock: slice.loadBit() 24 | }; 25 | } 26 | 27 | export function storeTickTock(src: TickTock) { 28 | return (builder: Builder) => { 29 | builder.storeBit(src.tick); 30 | builder.storeBit(src.tock); 31 | } 32 | } -------------------------------------------------------------------------------- /packages/coin-ton/src/ton-core/utils/bitsForNumber.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Whales Corp. 3 | * All Rights Reserved. 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | export function bitsForNumber(src: bigint | number, mode: 'int' | 'uint'): number { 10 | let v = BigInt(src); 11 | 12 | // Handle negative values 13 | if (mode === 'int') { 14 | 15 | // Corner case for zero or -1 value 16 | if (v === 0n || v === -1n) { 17 | return 1; 18 | } 19 | 20 | let v2 = v > 0 ? v : -v; 21 | return (v2.toString(2).length + 1/* Sign bit */); 22 | } else if (mode === 'uint') { 23 | if (v < 0) { 24 | throw Error(`value is negative. Got ${src}`); 25 | } 26 | return (v.toString(2).length); 27 | } else { 28 | throw Error(`invalid mode. Got ${mode}`); 29 | } 30 | } -------------------------------------------------------------------------------- /packages/coin-ton/src/ton-core/utils/crc16.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Whales Corp. 3 | * All Rights Reserved. 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | export function crc16(data: Buffer) { 10 | const poly = 0x1021; 11 | let reg = 0; 12 | const message = Buffer.alloc(data.length + 2); 13 | message.set(data); 14 | for (let byte of message) { 15 | let mask = 0x80; 16 | while (mask > 0) { 17 | reg <<= 1; 18 | if (byte & mask) { 19 | reg += 1; 20 | } 21 | mask >>= 1 22 | if (reg > 0xffff) { 23 | reg &= 0xffff; 24 | reg ^= poly; 25 | } 26 | } 27 | } 28 | return Buffer.from([Math.floor(reg / 256), reg % 256]); 29 | } -------------------------------------------------------------------------------- /packages/coin-ton/src/ton-core/utils/crc32c.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Whales Corp. 3 | * All Rights Reserved. 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | const POLY = 0x82f63b78; 10 | 11 | export function crc32c(source: Buffer) { 12 | let crc = 0 ^ 0xffffffff; 13 | for (let n = 0; n < source.length; n++) { 14 | crc ^= source[n]; 15 | crc = crc & 1 ? (crc >>> 1) ^ POLY : crc >>> 1; 16 | crc = crc & 1 ? (crc >>> 1) ^ POLY : crc >>> 1; 17 | crc = crc & 1 ? (crc >>> 1) ^ POLY : crc >>> 1; 18 | crc = crc & 1 ? (crc >>> 1) ^ POLY : crc >>> 1; 19 | crc = crc & 1 ? (crc >>> 1) ^ POLY : crc >>> 1; 20 | crc = crc & 1 ? (crc >>> 1) ^ POLY : crc >>> 1; 21 | crc = crc & 1 ? (crc >>> 1) ^ POLY : crc >>> 1; 22 | crc = crc & 1 ? (crc >>> 1) ^ POLY : crc >>> 1; 23 | } 24 | crc = crc ^ 0xffffffff; 25 | 26 | // Convert endianness 27 | let res = Buffer.alloc(4); 28 | res.writeInt32LE(crc); 29 | return res; 30 | } -------------------------------------------------------------------------------- /packages/coin-ton/src/ton-core/utils/maybe.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Whales Corp. 3 | * All Rights Reserved. 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | export type Maybe = T | null | undefined; -------------------------------------------------------------------------------- /packages/coin-ton/src/ton-crypto-primitives/node.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Whales Corp. 3 | * All Rights Reserved. 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | export { getSecureRandomBytes, getSecureRandomWords } from './node/getSecureRandom'; 10 | export { hmac_sha512 } from './node/hmac_sha512'; 11 | export { pbkdf2_sha512 } from './node/pbkdf2_sha512'; 12 | export { sha256 } from './node/sha256'; 13 | export { sha512 } from './node/sha512'; -------------------------------------------------------------------------------- /packages/coin-ton/src/ton-crypto-primitives/node/getSecureRandom.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Whales Corp. 3 | * All Rights Reserved. 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | import crypto from 'crypto'; 10 | 11 | export function getSecureRandomBytes(size: number): Buffer { 12 | return crypto.randomBytes(size); 13 | } 14 | 15 | export function getSecureRandomWords(size: number): Uint16Array { 16 | let res = new Uint16Array(size); 17 | crypto.randomFillSync(res); 18 | return res; 19 | } -------------------------------------------------------------------------------- /packages/coin-ton/src/ton-crypto-primitives/node/hmac_sha512.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Whales Corp. 3 | * All Rights Reserved. 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | import crypto from 'crypto'; 10 | 11 | export async function hmac_sha512(key: string | Buffer, data: string | Buffer): Promise { 12 | let keyBuffer: Buffer = typeof key === 'string' ? Buffer.from(key, 'utf-8') : key; 13 | let dataBuffer: Buffer = typeof data === 'string' ? Buffer.from(data, 'utf-8') : data; 14 | return crypto.createHmac('sha512', keyBuffer) 15 | .update(dataBuffer) 16 | .digest(); 17 | } -------------------------------------------------------------------------------- /packages/coin-ton/src/ton-crypto-primitives/node/pbkdf2_sha512.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Whales Corp. 3 | * All Rights Reserved. 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | import crypto from 'crypto'; 10 | 11 | export function pbkdf2_sha512(key: string | Buffer, salt: string | Buffer, iterations: number, keyLen: number): Promise { 12 | return new Promise((resolve, reject) => crypto.pbkdf2(key, salt, iterations, keyLen, 'sha512', (error, derivedKey) => { 13 | if (error) { 14 | reject(error); 15 | } else { 16 | resolve(derivedKey); 17 | } 18 | })); 19 | } -------------------------------------------------------------------------------- /packages/coin-ton/src/ton-crypto-primitives/node/sha256.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Whales Corp. 3 | * All Rights Reserved. 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | import crypto from 'crypto'; 10 | 11 | export async function sha256(source: Buffer | string): Promise { 12 | return crypto.createHash('sha256').update(source).digest(); 13 | } -------------------------------------------------------------------------------- /packages/coin-ton/src/ton-crypto-primitives/node/sha512.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Whales Corp. 3 | * All Rights Reserved. 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | import crypto from 'crypto'; 10 | 11 | export async function sha512(source: Buffer | string): Promise { 12 | return crypto.createHash('sha512').update(source).digest(); 13 | } -------------------------------------------------------------------------------- /packages/coin-ton/src/ton-crypto/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Whales Corp. 3 | * All Rights Reserved. 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | export { sha256, sha256_sync } from './primitives/sha256'; 10 | export { sha512, sha512_sync } from './primitives/sha512'; 11 | export { pbkdf2_sha512 } from './primitives/pbkdf2_sha512'; 12 | export { hmac_sha512 } from './primitives/hmac_sha512'; 13 | export { getSecureRandomBytes, getSecureRandomWords, getSecureRandomNumber } from './primitives/getSecureRandom'; 14 | export { KeyPair } from './primitives/nacl'; 15 | export { sealBox, openBox } from './primitives/nacl'; 16 | export { keyPairFromSeed, keyPairFromSecretKey, sign, signVerify } from './primitives/nacl'; 17 | -------------------------------------------------------------------------------- /packages/coin-ton/src/ton-crypto/primitives/pbkdf2_sha512.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Whales Corp. 3 | * All Rights Reserved. 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | import { pbkdf2_sha512 as internal } from '../../ton-crypto-primitives/node'; 10 | // import { pbkdf2_sha512 as internal } from '../../ton-crypto-primitives/browser'; 11 | 12 | export function pbkdf2_sha512(key: string | Buffer, salt: string | Buffer, iterations: number, keyLen: number): Promise { 13 | return internal(key, salt, iterations, keyLen); 14 | } -------------------------------------------------------------------------------- /packages/coin-ton/src/ton-crypto/primitives/sha256.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Whales Corp. 3 | * All Rights Reserved. 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | import jsSHA from 'jssha'; 10 | import { sha256 as internal } from '../../ton-crypto-primitives/node'; 11 | // import { sha256 as internal } from '../../ton-crypto-primitives/browser'; 12 | 13 | export function sha256_sync(source: Buffer | string): Buffer { 14 | let src: string; 15 | if (typeof source === 'string') { 16 | src = Buffer.from(source, 'utf-8').toString('hex'); 17 | } else { 18 | src = source.toString('hex'); 19 | } 20 | 21 | let hasher = new jsSHA('SHA-256', 'HEX'); 22 | hasher.update(src); 23 | let res = hasher.getHash('HEX'); 24 | return Buffer.from(res, 'hex'); 25 | } 26 | 27 | export async function sha256_fallback(source: Buffer | string): Promise { 28 | return sha256_sync(source); 29 | } 30 | 31 | export function sha256(source: Buffer | string): Promise { 32 | return internal(source); 33 | } -------------------------------------------------------------------------------- /packages/coin-ton/src/ton-crypto/primitives/sha512.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Whales Corp. 3 | * All Rights Reserved. 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | import jsSHA from 'jssha' 10 | import { sha512 as internal } from '../../ton-crypto-primitives/node'; 11 | // import { sha512 as internal } from '../../ton-crypto-primitives/browser'; 12 | 13 | export function sha512_sync(source: Buffer | string): Buffer { 14 | let src: string; 15 | if (typeof source === 'string') { 16 | src = Buffer.from(source, 'utf-8').toString('hex'); 17 | } else { 18 | src = source.toString('hex'); 19 | } 20 | 21 | let hasher = new jsSHA('SHA-512', 'HEX'); 22 | hasher.update(src); 23 | let res = hasher.getHash('HEX'); 24 | return Buffer.from(res, 'hex'); 25 | } 26 | 27 | export async function sha512_fallback(source: Buffer | string): Promise { 28 | return sha512_sync(source); 29 | } 30 | 31 | export async function sha512(source: Buffer | string): Promise { 32 | return internal(source); 33 | } -------------------------------------------------------------------------------- /packages/coin-ton/src/ton/index.ts: -------------------------------------------------------------------------------- 1 | export { WalletContractV3R2 } from './wallets/WalletContractV3R2'; 2 | export { WalletContractV4 } from './wallets/WalletContractV4'; 3 | export { VenomWalletV3 } from './wallets/VenomWalletV3'; 4 | -------------------------------------------------------------------------------- /packages/coin-ton/src/ton/utils/maybe.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Whales Corp. 3 | * All Rights Reserved. 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | export type Maybe = T | null | undefined; -------------------------------------------------------------------------------- /packages/coin-ton/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "allowJs": true, 5 | // Allows javascript files to be compiled 6 | "resolveJsonModule": true, 7 | "outDir": "./dist", 8 | "rootDir": "./src", 9 | "experimentalDecorators": true 10 | }, 11 | "include": [ 12 | "src/**/*.ts", 13 | "src/**/*.js", 14 | "src/**/*.json" 15 | ], 16 | "exclude": [ 17 | "**/node_modules" 18 | ] 19 | } 20 | 21 | -------------------------------------------------------------------------------- /packages/coin-tron/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | # Change Log 3 | 4 | All notable changes to this project will be documented in this file. 5 | 6 | # [1.1.0](https://github.com/okx/js-wallet-sdk)(2024-01-15) 7 | 8 | ### New Features 9 | 10 | - **coin-tron:** support signCommonMsg ([](https://github.com/okx/js-wallet-sdk)) 11 | 12 | # [1.0.4](https://github.com/okx/js-wallet-sdk) (2024-08-20) 13 | 14 | ### Fix 15 | 16 | - **coin-tron:** upgrade private key verification ([](https://github.com/okx/js-wallet-sdk)) 17 | 18 | 19 | # [1.0.1](https://github.com/okx/js-wallet-sdk) (2024-02-22) 20 | 21 | ### Feature 22 | 23 | - **coin-tron:** support tron v2 signMessage and verifySignature ([](https://github.com/okx/js-wallet-sdk)) 24 | -------------------------------------------------------------------------------- /packages/coin-tron/jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ 2 | module.exports = { 3 | preset: 'ts-jest', 4 | testEnvironment: 'node', 5 | }; -------------------------------------------------------------------------------- /packages/coin-tron/src/protobuf/Discover.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package protocol; 4 | 5 | 6 | option java_package = "org.tron.protos"; //Specify the name of the package that generated the Java file 7 | option java_outer_classname = "Discover"; //Specify the class name of the generated Java file 8 | option go_package = "github.com/tronprotocol/grpc-gateway/core"; 9 | 10 | message Endpoint { 11 | bytes address = 1; 12 | int32 port = 2; 13 | bytes nodeId = 3; 14 | } 15 | 16 | message PingMessage { 17 | Endpoint from = 1; 18 | Endpoint to = 2; 19 | int32 version = 3; 20 | int64 timestamp = 4; 21 | } 22 | 23 | message PongMessage { 24 | Endpoint from = 1; 25 | int32 echo = 2; 26 | int64 timestamp = 3; 27 | } 28 | 29 | message FindNeighbours { 30 | Endpoint from = 1; 31 | bytes targetId = 2; 32 | int64 timestamp = 3; 33 | } 34 | 35 | message Neighbours { 36 | Endpoint from = 1; 37 | repeated Endpoint neighbours = 2; 38 | int64 timestamp = 3; 39 | } 40 | 41 | message BackupMessage { 42 | bool flag = 1; 43 | int32 priority = 2; 44 | } -------------------------------------------------------------------------------- /packages/coin-tron/src/protobuf/attribution.md: -------------------------------------------------------------------------------- 1 | # Attribution for module protobuf 2 | 3 | We got the proto from the `tronprotocol`, thanks for their work, we could write this useful sdk for tron blockchain 4 | 5 | https://github.com/tronprotocol/java-tron/tree/9f8cebd1ff2601b7779715de9b66a7b84f4effdd/protocol/src/main/protos/core 6 | -------------------------------------------------------------------------------- /packages/coin-tron/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "allowJs": true, // allow build javascript files 5 | "resolveJsonModule" : true, 6 | "outDir": "./dist", 7 | "rootDir": "./src" 8 | }, 9 | "include": [ 10 | "src/**/*.ts", 11 | "src/**/*.js", 12 | "src/**/*.json" 13 | ], 14 | "exclude": [ 15 | "**/node_modules" 16 | ] 17 | } 18 | 19 | -------------------------------------------------------------------------------- /packages/coin-zkspace/jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ 2 | module.exports = { 3 | preset: 'ts-jest', 4 | testEnvironment: 'node', 5 | }; -------------------------------------------------------------------------------- /packages/coin-zkspace/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './zkspace' 2 | export {zksyncChangePubkey,zksyncTransfer} from './zksync' 3 | export {closestPackableTransactionAmount,closestPackableTransactionFee} from './zksync/utils' 4 | export * from "./ZksyncWallet" 5 | export * from "./ZkspaceWallet" 6 | 7 | -------------------------------------------------------------------------------- /packages/coin-zkspace/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "allowJs": true, // Allows javascript files to be compiled 5 | 6 | "resolveJsonModule" : true, 7 | "outDir": "./dist", 8 | "rootDir": "./src", 9 | "experimentalDecorators": true 10 | }, 11 | "include": [ 12 | "src/**/*.ts", 13 | "src/**/*.js", 14 | "src/**/*.json" 15 | ], 16 | "exclude": [ 17 | "**/node_modules" 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /packages/crypto-lib/jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ 2 | module.exports = { 3 | preset: 'ts-jest', 4 | testEnvironment: 'node', 5 | }; -------------------------------------------------------------------------------- /packages/crypto-lib/src/abi/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Mozilla Public License Version 2.0 3 | * 4 | * 5 | * https://github.com/ethereumjs/ethereumjs-monorepo/blob/master/packages/util/LICENSE 6 | * 7 | * */ 8 | 9 | const ABI = require("./abi.js") 10 | function RawEncode(types: string[], values: any[]): Buffer { 11 | return ABI.rawEncode(types, values) 12 | } 13 | 14 | function SoliditySHA3(types: string[], values: any[]): Buffer { 15 | return ABI.soliditySHA3(types, values) 16 | } 17 | 18 | export {ABI, RawEncode, SoliditySHA3} -------------------------------------------------------------------------------- /packages/crypto-lib/src/base/base58.ts: -------------------------------------------------------------------------------- 1 | import { base58 } from "@scure/base" 2 | export function toBase58(data: Uint8Array | Buffer | Number[]): string { 3 | const a = Buffer.from(data) 4 | return base58.encode(Uint8Array.from(a)) 5 | } 6 | 7 | export function fromBase58(data: string): Uint8Array { 8 | return base58.decode(data) 9 | } 10 | 11 | export {base58} -------------------------------------------------------------------------------- /packages/crypto-lib/src/base/base58Check.ts: -------------------------------------------------------------------------------- 1 | import {sha256} from "./hash"; 2 | 3 | const createHash = require("create-hash") 4 | 5 | import { base58check } from "@scure/base" 6 | 7 | export function toBase58Check(data: Uint8Array | Buffer | Number[]): string { 8 | const bytesCoder = base58check(sha256); 9 | return bytesCoder.encode(Buffer.from(data)) 10 | } 11 | 12 | export function fromBase58Check(data: string): Buffer { 13 | const bytesCoder = base58check(sha256); 14 | return Buffer.from(bytesCoder.decode(data)) 15 | } -------------------------------------------------------------------------------- /packages/crypto-lib/src/base/base64.ts: -------------------------------------------------------------------------------- 1 | import { base64 } from "@scure/base" 2 | 3 | export function toBase64(data: Uint8Array | Buffer | Number[]): string { 4 | const a = Buffer.from(data) 5 | return base64.encode(Uint8Array.from(a)) 6 | } 7 | 8 | export function fromBase64(data: string): Uint8Array { 9 | return base64.decode(data) 10 | } -------------------------------------------------------------------------------- /packages/crypto-lib/src/base/bech32.ts: -------------------------------------------------------------------------------- 1 | import {bech32} from "@scure/base"; 2 | 3 | export function toBech32(prefix: string, data: Buffer | Uint8Array | Number[], limit?: number | false): string { 4 | const a = Buffer.from(data) 5 | const bit5 = bech32.toWords(Uint8Array.from(a)) 6 | return bech32.encode(prefix, bit5, limit) 7 | } 8 | 9 | export function fromBech32(data: string, limit?: number | false): [string, Buffer] { 10 | const d = bech32.decode(data, limit) 11 | const bit8 = bech32.fromWords(d.words) 12 | return [d.prefix, Buffer.from(bit8)] 13 | } 14 | -------------------------------------------------------------------------------- /packages/crypto-lib/src/base/bignumber-plus.ts: -------------------------------------------------------------------------------- 1 | import {BigNumber} from '../index'; 2 | 3 | import {check} from './precondtion'; 4 | 5 | const toBigIntHex = (value: BigNumber): string => { 6 | let hexStr = value.integerValue().toString(16); 7 | 8 | hexStr = '0x' + hexStr; 9 | return hexStr; 10 | }; 11 | 12 | const fromBigIntHex = (value: string): BigNumber => { 13 | check(value && value.startsWith('0x'), `Invalid hex string. value: ${value}`); 14 | return new BigNumber(value).integerValue(); 15 | }; 16 | 17 | const bigNumber2String = (value: BigNumber, base?: number): string => { 18 | return value.integerValue().toString(base); 19 | }; 20 | 21 | const string2BigNumber = (n: string | number, base?: number): BigNumber => { 22 | return new BigNumber(n, base); 23 | }; 24 | 25 | export {toBigIntHex, fromBigIntHex, bigNumber2String, string2BigNumber}; 26 | -------------------------------------------------------------------------------- /packages/crypto-lib/src/base/helper.ts: -------------------------------------------------------------------------------- 1 | export function isHexString(value: string, length?: number) { 2 | if (!value.match(/^0x[0-9A-Fa-f]*$/)) { 3 | return false; 4 | } 5 | 6 | return !(length && value.length !== 2 + 2 * length); 7 | } 8 | 9 | export function validateHexString(value: string) { 10 | if (!value) { 11 | return false; 12 | } 13 | const hexStr = value.toLowerCase().startsWith("0x") ? value.substring(2).toLowerCase() : value.toLowerCase(); 14 | if(hexStr.length === 0 || hexStr.length % 2 !== 0) { 15 | return false; 16 | } 17 | if (!hexStr.match(/^[0-9A-Fa-f]*$/)) { 18 | return false; 19 | } 20 | return true 21 | } -------------------------------------------------------------------------------- /packages/crypto-lib/src/base/hex.ts: -------------------------------------------------------------------------------- 1 | export function toHex(data: Uint8Array | Buffer | number[], addPrefix: boolean = false): string { 2 | const buffer = Buffer.from(data) 3 | return addPrefix? "0x" + buffer.toString("hex") : buffer.toString("hex") 4 | } 5 | 6 | export function fromHex(data: string): Buffer { 7 | if(data.startsWith("0x")) { 8 | data = data.substring(2) 9 | } 10 | return Buffer.from(data, "hex") 11 | } 12 | 13 | export function stripHexPrefix(hex: string) : string { 14 | if(hex.startsWith("0x")) { 15 | return hex.substring(2) 16 | } 17 | return hex 18 | } 19 | 20 | export function isHexPrefixed(hex: string) : boolean { 21 | return hex.startsWith("0x") 22 | } -------------------------------------------------------------------------------- /packages/crypto-lib/src/base/hmac.ts: -------------------------------------------------------------------------------- 1 | import {Input} from "@noble/hashes/utils"; 2 | 3 | import {hmac} from "@noble/hashes/hmac" 4 | import {sha256, sha512} from "./hash" 5 | 6 | export function hmacSHA256(key: Input, buffer: Input): Buffer { 7 | return Buffer.from(hmac(sha256, key, buffer)); 8 | } 9 | 10 | export function hmacSHA512(key: Input, buffer: Input): Buffer { 11 | return Buffer.from(hmac(sha512, key, buffer)); 12 | } -------------------------------------------------------------------------------- /packages/crypto-lib/src/base/precondtion.ts: -------------------------------------------------------------------------------- 1 | type ErrorType = undefined | string | Error; 2 | 3 | const check = (statement: any, orError?: ErrorType) => { 4 | if (!statement) { 5 | orError = orError ? orError : 'Invalid statement'; 6 | orError = orError instanceof Error ? orError : new Error(orError); 7 | 8 | throw orError; 9 | } 10 | }; 11 | 12 | const checkIsDefined = (something?: T, orError?: ErrorType): T => { 13 | check( 14 | typeof something !== 'undefined', 15 | orError || 'Expect defined but actually undefined', 16 | ); 17 | return something as T; 18 | }; 19 | 20 | const checkIsUndefined = (something: any, orError?: ErrorType) => { 21 | check( 22 | typeof something === 'undefined', 23 | orError || `Expect undefined but actually ${something}`, 24 | ); 25 | }; 26 | 27 | export {check, checkIsDefined, checkIsUndefined}; 28 | -------------------------------------------------------------------------------- /packages/crypto-lib/src/base/utf8.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/naming-convention */ 2 | // Global symbols in both browsers and Node.js since v11 3 | // https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder 4 | // https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder 5 | // https://nodejs.org/docs/latest-v12.x/api/util.html#util_class_util_textencoder 6 | // https://nodejs.org/docs/latest-v12.x/api/util.html#util_class_util_textdecoder 7 | // See https://github.com/microsoft/TypeScript/issues/31535 8 | declare const TextEncoder: any; 9 | declare const TextDecoder: any; 10 | 11 | export function toUtf8(str: string): Uint8Array { 12 | return new TextEncoder().encode(str); 13 | } 14 | 15 | export function fromUtf8(data: Uint8Array): string { 16 | return new TextDecoder("utf-8", { fatal: true }).decode(data); 17 | } 18 | -------------------------------------------------------------------------------- /packages/crypto-lib/src/bip32/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | tinySecp256k1Interface, 3 | BIP32Interface, 4 | fromSeed, 5 | fromBase58, 6 | fromPublicKey, 7 | fromPrivateKey, 8 | } from './bip32'; 9 | -------------------------------------------------------------------------------- /packages/crypto-lib/src/elliptic/curve/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * LICENSE 3 | * This software is licensed under the MIT License. 4 | * 5 | * Copyright Fedor Indutny, 2014. 6 | * */ 7 | 'use strict'; 8 | 9 | var curve = exports; 10 | 11 | curve.base = require('./base'); 12 | curve.short = require('./short'); 13 | curve.mont = require('./mont'); 14 | curve.edwards = require('./edwards'); 15 | -------------------------------------------------------------------------------- /packages/crypto-lib/src/elliptic/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * LICENSE 3 | * This software is licensed under the MIT License. 4 | * 5 | * Copyright Fedor Indutny, 2014. 6 | * */ 7 | 8 | 'use strict'; 9 | 10 | const curve = require('./curve'); 11 | const curves = require('./curves'); 12 | 13 | // Protocols 14 | const ec = require('./ec'); 15 | const eddsa = require('./eddsa'); 16 | 17 | const utils = require('./utils') 18 | 19 | export {ec, eddsa, curve, curves, utils} 20 | -------------------------------------------------------------------------------- /packages/crypto-lib/src/math/index.ts: -------------------------------------------------------------------------------- 1 | export { Decimal } from "./decimal"; 2 | export { Int53, Uint32, Uint53, Uint64 } from "./integers"; 3 | -------------------------------------------------------------------------------- /packages/crypto-lib/src/signutil/index.ts: -------------------------------------------------------------------------------- 1 | export * as secp256k1 from "./secp256k1" 2 | export * as ed25519 from "./ed25519" 3 | export * as p256 from "./p256" 4 | export * as schnorr from "./schnorr" -------------------------------------------------------------------------------- /packages/crypto-lib/src/signutil/schnorr/_shortw_utils.ts: -------------------------------------------------------------------------------- 1 | /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */ 2 | import { hmac } from '@noble/hashes/hmac'; 3 | import { concatBytes, randomBytes } from '@noble/hashes/utils'; 4 | import { weierstrass, CurveType } from './abstract/weierstrass'; 5 | import { CHash } from './abstract/utils'; 6 | 7 | // connects noble-curves to noble-hashes 8 | export function getHash(hash: CHash) { 9 | return { 10 | hash, 11 | hmac: (key: Uint8Array, ...msgs: Uint8Array[]) => hmac(hash, key, concatBytes(...msgs)), 12 | randomBytes, 13 | }; 14 | } 15 | // Same API as @noble/hashes, with ability to create curve with custom hash 16 | type CurveDef = Readonly>; 17 | export function createCurve(curveDef: CurveDef, defHash: CHash) { 18 | const create = (hash: CHash) => weierstrass({ ...curveDef, ...getHash(hash) }); 19 | return Object.freeze({ ...create(defHash), create }); 20 | } -------------------------------------------------------------------------------- /packages/crypto-lib/src/signutil/schnorr/index.ts: -------------------------------------------------------------------------------- 1 | export * as secp256k1 from "./secp256k1" 2 | export * as stark from "./stark" 3 | export {SignatureType} from "./abstract/weierstrass" 4 | export {hexToBytes, bytesToHex} from "./abstract/utils" -------------------------------------------------------------------------------- /packages/crypto-lib/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "allowJs": true, // allow build javascript files 5 | "resolveJsonModule" : true, 6 | "outDir": "./dist", 7 | "rootDir": "./src" 8 | }, 9 | "include": [ 10 | "src/**/*.ts", 11 | "src/**/*.js", 12 | "src/**/*.json" 13 | ], 14 | "exclude": [ 15 | "**/node_modules" 16 | ] 17 | } 18 | 19 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2020", 4 | "lib": [ 5 | "es2020" 6 | ], 7 | "moduleResolution": "node", 8 | "module": "CommonJS", 9 | "strict": true, 10 | "declaration": true, 11 | "sourceMap": true, 12 | "esModuleInterop": true, 13 | "resolveJsonModule": true, 14 | /* Additional Checks */ 15 | "noUnusedLocals": false, 16 | "noUnusedParameters": false, 17 | "noFallthroughCasesInSwitch": true, 18 | /* Debugging Options */ 19 | "traceResolution": false, 20 | "listEmittedFiles": false, 21 | "listFiles": false, 22 | "pretty": false, 23 | "removeComments": true, 24 | "typeRoots": [ 25 | "node_modules/@types" 26 | ], 27 | "skipLibCheck": true 28 | }, 29 | "exclude": [ 30 | "**/node_modules" 31 | ] 32 | } 33 | --------------------------------------------------------------------------------