@mysten/sui 1.37.5 → 1.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/dist/cjs/bcs/index.d.ts +1 -1
- package/dist/cjs/cryptography/intent.d.ts +1 -1
- package/dist/cjs/cryptography/keypair.d.ts +1 -1
- package/dist/cjs/cryptography/keypair.js.map +1 -1
- package/dist/cjs/cryptography/publickey.d.ts +3 -3
- package/dist/cjs/cryptography/publickey.js.map +2 -2
- package/dist/cjs/cryptography/signature.d.ts +3 -3
- package/dist/cjs/experimental/transports/json-rpc-resolver.js +5 -3
- package/dist/cjs/experimental/transports/json-rpc-resolver.js.map +2 -2
- package/dist/cjs/experimental/transports/jsonRPC.d.ts +2 -2
- package/dist/cjs/keypairs/ed25519/keypair.d.ts +1 -1
- package/dist/cjs/keypairs/ed25519/keypair.js.map +1 -1
- package/dist/cjs/keypairs/ed25519/publickey.d.ts +1 -1
- package/dist/cjs/keypairs/ed25519/publickey.js.map +2 -2
- package/dist/cjs/keypairs/passkey/keypair.d.ts +1 -1
- package/dist/cjs/keypairs/passkey/keypair.js.map +1 -1
- package/dist/cjs/keypairs/passkey/publickey.d.ts +1 -1
- package/dist/cjs/keypairs/passkey/publickey.js.map +2 -2
- package/dist/cjs/keypairs/secp256k1/keypair.d.ts +1 -1
- package/dist/cjs/keypairs/secp256k1/keypair.js.map +1 -1
- package/dist/cjs/keypairs/secp256k1/publickey.d.ts +1 -1
- package/dist/cjs/keypairs/secp256k1/publickey.js.map +2 -2
- package/dist/cjs/keypairs/secp256r1/keypair.d.ts +1 -1
- package/dist/cjs/keypairs/secp256r1/keypair.js.map +1 -1
- package/dist/cjs/keypairs/secp256r1/publickey.d.ts +1 -1
- package/dist/cjs/keypairs/secp256r1/publickey.js.map +2 -2
- package/dist/cjs/multisig/publickey.d.ts +1 -1
- package/dist/cjs/multisig/publickey.js.map +2 -2
- package/dist/cjs/transactions/Commands.d.ts +9 -9
- package/dist/cjs/transactions/Commands.js +9 -9
- package/dist/cjs/transactions/Commands.js.map +2 -2
- package/dist/cjs/transactions/Transaction.d.ts +6 -5
- package/dist/cjs/transactions/Transaction.js +5 -5
- package/dist/cjs/transactions/Transaction.js.map +2 -2
- package/dist/cjs/transactions/TransactionData.d.ts +4 -5
- package/dist/cjs/transactions/TransactionData.js +3 -3
- package/dist/cjs/transactions/TransactionData.js.map +2 -2
- package/dist/cjs/transactions/data/internal.d.ts +21 -19
- package/dist/cjs/transactions/data/internal.js +45 -44
- package/dist/cjs/transactions/data/internal.js.map +2 -2
- package/dist/cjs/transactions/data/v1.d.ts +1 -1
- package/dist/cjs/transactions/data/v1.js +1 -1
- package/dist/cjs/transactions/data/v1.js.map +2 -2
- package/dist/cjs/transactions/data/v2.d.ts +4 -2
- package/dist/cjs/transactions/data/v2.js +7 -6
- package/dist/cjs/transactions/data/v2.js.map +2 -2
- package/dist/cjs/transactions/executor/caching.d.ts +1 -1
- package/dist/cjs/transactions/executor/serial.d.ts +1 -1
- package/dist/cjs/transactions/object.js +6 -16
- package/dist/cjs/transactions/object.js.map +2 -2
- package/dist/cjs/transactions/utils.d.ts +1 -2
- package/dist/cjs/transactions/utils.js +1 -1
- package/dist/cjs/transactions/utils.js.map +2 -2
- package/dist/cjs/utils/derived-objects.d.ts +5 -0
- package/dist/cjs/utils/derived-objects.js +34 -0
- package/dist/cjs/utils/derived-objects.js.map +7 -0
- package/dist/cjs/utils/index.d.ts +1 -0
- package/dist/cjs/utils/index.js +2 -0
- package/dist/cjs/utils/index.js.map +2 -2
- package/dist/cjs/version.d.ts +2 -2
- package/dist/cjs/version.js +2 -2
- package/dist/cjs/version.js.map +1 -1
- package/dist/cjs/zklogin/publickey.d.ts +2 -2
- package/dist/cjs/zklogin/publickey.js.map +2 -2
- package/dist/esm/bcs/index.d.ts +1 -1
- package/dist/esm/cryptography/intent.d.ts +1 -1
- package/dist/esm/cryptography/keypair.d.ts +1 -1
- package/dist/esm/cryptography/keypair.js.map +1 -1
- package/dist/esm/cryptography/publickey.d.ts +3 -3
- package/dist/esm/cryptography/publickey.js.map +2 -2
- package/dist/esm/cryptography/signature.d.ts +3 -3
- package/dist/esm/experimental/transports/json-rpc-resolver.js +6 -4
- package/dist/esm/experimental/transports/json-rpc-resolver.js.map +2 -2
- package/dist/esm/experimental/transports/jsonRPC.d.ts +2 -2
- package/dist/esm/keypairs/ed25519/keypair.d.ts +1 -1
- package/dist/esm/keypairs/ed25519/keypair.js.map +1 -1
- package/dist/esm/keypairs/ed25519/publickey.d.ts +1 -1
- package/dist/esm/keypairs/ed25519/publickey.js.map +2 -2
- package/dist/esm/keypairs/passkey/keypair.d.ts +1 -1
- package/dist/esm/keypairs/passkey/keypair.js.map +1 -1
- package/dist/esm/keypairs/passkey/publickey.d.ts +1 -1
- package/dist/esm/keypairs/passkey/publickey.js.map +2 -2
- package/dist/esm/keypairs/secp256k1/keypair.d.ts +1 -1
- package/dist/esm/keypairs/secp256k1/keypair.js.map +1 -1
- package/dist/esm/keypairs/secp256k1/publickey.d.ts +1 -1
- package/dist/esm/keypairs/secp256k1/publickey.js.map +2 -2
- package/dist/esm/keypairs/secp256r1/keypair.d.ts +1 -1
- package/dist/esm/keypairs/secp256r1/keypair.js.map +1 -1
- package/dist/esm/keypairs/secp256r1/publickey.d.ts +1 -1
- package/dist/esm/keypairs/secp256r1/publickey.js.map +2 -2
- package/dist/esm/multisig/publickey.d.ts +1 -1
- package/dist/esm/multisig/publickey.js.map +2 -2
- package/dist/esm/transactions/Commands.d.ts +9 -9
- package/dist/esm/transactions/Commands.js +10 -10
- package/dist/esm/transactions/Commands.js.map +2 -2
- package/dist/esm/transactions/Transaction.d.ts +6 -5
- package/dist/esm/transactions/Transaction.js +12 -7
- package/dist/esm/transactions/Transaction.js.map +2 -2
- package/dist/esm/transactions/TransactionData.d.ts +4 -5
- package/dist/esm/transactions/TransactionData.js +4 -4
- package/dist/esm/transactions/TransactionData.js.map +2 -2
- package/dist/esm/transactions/data/internal.d.ts +21 -19
- package/dist/esm/transactions/data/internal.js +45 -44
- package/dist/esm/transactions/data/internal.js.map +2 -2
- package/dist/esm/transactions/data/v1.d.ts +1 -1
- package/dist/esm/transactions/data/v1.js +2 -2
- package/dist/esm/transactions/data/v1.js.map +2 -2
- package/dist/esm/transactions/data/v2.d.ts +4 -2
- package/dist/esm/transactions/data/v2.js +8 -7
- package/dist/esm/transactions/data/v2.js.map +2 -2
- package/dist/esm/transactions/executor/caching.d.ts +1 -1
- package/dist/esm/transactions/executor/serial.d.ts +1 -1
- package/dist/esm/transactions/object.js +6 -16
- package/dist/esm/transactions/object.js.map +2 -2
- package/dist/esm/transactions/utils.d.ts +1 -2
- package/dist/esm/transactions/utils.js +2 -2
- package/dist/esm/transactions/utils.js.map +2 -2
- package/dist/esm/utils/derived-objects.d.ts +5 -0
- package/dist/esm/utils/derived-objects.js +14 -0
- package/dist/esm/utils/derived-objects.js.map +7 -0
- package/dist/esm/utils/index.d.ts +1 -0
- package/dist/esm/utils/index.js +2 -0
- package/dist/esm/utils/index.js.map +2 -2
- package/dist/esm/version.d.ts +2 -2
- package/dist/esm/version.js +2 -2
- package/dist/esm/version.js.map +1 -1
- package/dist/esm/zklogin/publickey.d.ts +2 -2
- package/dist/esm/zklogin/publickey.js.map +2 -2
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -10
- package/src/cryptography/keypair.ts +1 -1
- package/src/cryptography/publickey.ts +2 -2
- package/src/experimental/transports/json-rpc-resolver.ts +8 -4
- package/src/keypairs/ed25519/keypair.ts +1 -1
- package/src/keypairs/ed25519/publickey.ts +3 -3
- package/src/keypairs/passkey/keypair.ts +2 -2
- package/src/keypairs/passkey/publickey.ts +3 -3
- package/src/keypairs/secp256k1/keypair.ts +1 -1
- package/src/keypairs/secp256k1/publickey.ts +3 -3
- package/src/keypairs/secp256r1/keypair.ts +1 -1
- package/src/keypairs/secp256r1/publickey.ts +3 -3
- package/src/multisig/publickey.ts +3 -3
- package/src/transactions/Commands.ts +27 -22
- package/src/transactions/Transaction.ts +18 -11
- package/src/transactions/TransactionData.ts +7 -6
- package/src/transactions/data/internal.ts +44 -42
- package/src/transactions/data/v1.ts +5 -5
- package/src/transactions/data/v2.ts +7 -6
- package/src/transactions/object.ts +6 -18
- package/src/transactions/utils.ts +3 -3
- package/src/utils/derived-objects.ts +22 -0
- package/src/utils/index.ts +2 -0
- package/src/version.ts +2 -2
- package/src/zklogin/publickey.ts +3 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/keypairs/secp256k1/keypair.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { secp256k1 } from '@noble/curves/secp256k1';\nimport { blake2b } from '@noble/hashes/blake2b';\nimport { sha256 } from '@noble/hashes/sha256';\nimport { bytesToHex } from '@noble/hashes/utils';\nimport { HDKey } from '@scure/bip32';\n\nimport { decodeSuiPrivateKey, encodeSuiPrivateKey, Keypair } from '../../cryptography/keypair.js';\nimport { isValidBIP32Path, mnemonicToSeed } from '../../cryptography/mnemonics.js';\nimport type { PublicKey } from '../../cryptography/publickey.js';\nimport type { SignatureScheme } from '../../cryptography/signature-scheme.js';\nimport { Secp256k1PublicKey } from './publickey.js';\n\nexport const DEFAULT_SECP256K1_DERIVATION_PATH = \"m/54'/784'/0'/0/0\";\n\n/**\n * Secp256k1 Keypair data\n */\nexport interface Secp256k1KeypairData {\n\tpublicKey: Uint8Array;\n\tsecretKey: Uint8Array;\n}\n\n/**\n * An Secp256k1 Keypair used for signing transactions.\n */\nexport class Secp256k1Keypair extends Keypair {\n\tprivate keypair: Secp256k1KeypairData;\n\n\t/**\n\t * Create a new keypair instance.\n\t * Generate random keypair if no {@link Secp256k1Keypair} is provided.\n\t *\n\t * @param keypair secp256k1 keypair\n\t */\n\tconstructor(keypair?: Secp256k1KeypairData) {\n\t\tsuper();\n\t\tif (keypair) {\n\t\t\tthis.keypair = keypair;\n\t\t} else {\n\t\t\tconst secretKey: Uint8Array = secp256k1.utils.randomPrivateKey();\n\t\t\tconst publicKey: Uint8Array = secp256k1.getPublicKey(secretKey, true);\n\n\t\t\tthis.keypair = { publicKey, secretKey };\n\t\t}\n\t}\n\n\t/**\n\t * Get the key scheme of the keypair Secp256k1\n\t */\n\tgetKeyScheme(): SignatureScheme {\n\t\treturn 'Secp256k1';\n\t}\n\n\t/**\n\t * Generate a new random keypair\n\t */\n\tstatic generate(): Secp256k1Keypair {\n\t\treturn new Secp256k1Keypair();\n\t}\n\n\t/**\n\t * Create a keypair from a raw secret key byte array.\n\t *\n\t * This method should only be used to recreate a keypair from a previously\n\t * generated secret key. Generating keypairs from a random seed should be done\n\t * with the {@link Keypair.fromSeed} method.\n\t *\n\t * @throws error if the provided secret key is invalid and validation is not skipped.\n\t *\n\t * @param secretKey secret key byte array or Bech32 secret key string\n\t * @param options: skip secret key validation\n\t */\n\n\tstatic fromSecretKey(\n\t\tsecretKey: Uint8Array | string,\n\t\toptions?: { skipValidation?: boolean },\n\t): Secp256k1Keypair {\n\t\tif (typeof secretKey === 'string') {\n\t\t\tconst decoded = decodeSuiPrivateKey(secretKey);\n\n\t\t\tif (decoded.schema !== 'Secp256k1') {\n\t\t\t\tthrow new Error(`Expected a Secp256k1 keypair, got ${decoded.schema}`);\n\t\t\t}\n\n\t\t\treturn this.fromSecretKey(decoded.secretKey, options);\n\t\t}\n\n\t\tconst publicKey: Uint8Array = secp256k1.getPublicKey(secretKey, true);\n\t\tif (!options || !options.skipValidation) {\n\t\t\tconst encoder = new TextEncoder();\n\t\t\tconst signData = encoder.encode('sui validation');\n\t\t\tconst msgHash = bytesToHex(blake2b(signData, { dkLen: 32 }));\n\t\t\tconst signature = secp256k1.sign(msgHash, secretKey);\n\t\t\tif (!secp256k1.verify(signature, msgHash, publicKey, { lowS: true })) {\n\t\t\t\tthrow new Error('Provided secretKey is invalid');\n\t\t\t}\n\t\t}\n\t\treturn new Secp256k1Keypair({ publicKey, secretKey });\n\t}\n\n\t/**\n\t * Generate a keypair from a 32 byte seed.\n\t *\n\t * @param seed seed byte array\n\t */\n\tstatic fromSeed(seed: Uint8Array): Secp256k1Keypair {\n\t\tconst publicKey = secp256k1.getPublicKey(seed, true);\n\t\treturn new Secp256k1Keypair({ publicKey, secretKey: seed });\n\t}\n\n\t/**\n\t * The public key for this keypair\n\t */\n\tgetPublicKey(): PublicKey {\n\t\treturn new Secp256k1PublicKey(this.keypair.publicKey);\n\t}\n\t/**\n\t * The Bech32 secret key string for this Secp256k1 keypair\n\t */\n\tgetSecretKey(): string {\n\t\treturn encodeSuiPrivateKey(this.keypair.secretKey, this.getKeyScheme());\n\t}\n\n\t/**\n\t * Return the signature for the provided data.\n\t */\n\tasync sign(data: Uint8Array) {\n\t\tconst msgHash = sha256(data);\n\t\tconst sig = secp256k1.sign(msgHash, this.keypair.secretKey, {\n\t\t\tlowS: true,\n\t\t});\n\t\treturn sig.toCompactRawBytes()
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { secp256k1 } from '@noble/curves/secp256k1';\nimport { blake2b } from '@noble/hashes/blake2b';\nimport { sha256 } from '@noble/hashes/sha256';\nimport { bytesToHex } from '@noble/hashes/utils';\nimport { HDKey } from '@scure/bip32';\n\nimport { decodeSuiPrivateKey, encodeSuiPrivateKey, Keypair } from '../../cryptography/keypair.js';\nimport { isValidBIP32Path, mnemonicToSeed } from '../../cryptography/mnemonics.js';\nimport type { PublicKey } from '../../cryptography/publickey.js';\nimport type { SignatureScheme } from '../../cryptography/signature-scheme.js';\nimport { Secp256k1PublicKey } from './publickey.js';\n\nexport const DEFAULT_SECP256K1_DERIVATION_PATH = \"m/54'/784'/0'/0/0\";\n\n/**\n * Secp256k1 Keypair data\n */\nexport interface Secp256k1KeypairData {\n\tpublicKey: Uint8Array;\n\tsecretKey: Uint8Array;\n}\n\n/**\n * An Secp256k1 Keypair used for signing transactions.\n */\nexport class Secp256k1Keypair extends Keypair {\n\tprivate keypair: Secp256k1KeypairData;\n\n\t/**\n\t * Create a new keypair instance.\n\t * Generate random keypair if no {@link Secp256k1Keypair} is provided.\n\t *\n\t * @param keypair secp256k1 keypair\n\t */\n\tconstructor(keypair?: Secp256k1KeypairData) {\n\t\tsuper();\n\t\tif (keypair) {\n\t\t\tthis.keypair = keypair;\n\t\t} else {\n\t\t\tconst secretKey: Uint8Array = secp256k1.utils.randomPrivateKey();\n\t\t\tconst publicKey: Uint8Array = secp256k1.getPublicKey(secretKey, true);\n\n\t\t\tthis.keypair = { publicKey, secretKey };\n\t\t}\n\t}\n\n\t/**\n\t * Get the key scheme of the keypair Secp256k1\n\t */\n\tgetKeyScheme(): SignatureScheme {\n\t\treturn 'Secp256k1';\n\t}\n\n\t/**\n\t * Generate a new random keypair\n\t */\n\tstatic generate(): Secp256k1Keypair {\n\t\treturn new Secp256k1Keypair();\n\t}\n\n\t/**\n\t * Create a keypair from a raw secret key byte array.\n\t *\n\t * This method should only be used to recreate a keypair from a previously\n\t * generated secret key. Generating keypairs from a random seed should be done\n\t * with the {@link Keypair.fromSeed} method.\n\t *\n\t * @throws error if the provided secret key is invalid and validation is not skipped.\n\t *\n\t * @param secretKey secret key byte array or Bech32 secret key string\n\t * @param options: skip secret key validation\n\t */\n\n\tstatic fromSecretKey(\n\t\tsecretKey: Uint8Array | string,\n\t\toptions?: { skipValidation?: boolean },\n\t): Secp256k1Keypair {\n\t\tif (typeof secretKey === 'string') {\n\t\t\tconst decoded = decodeSuiPrivateKey(secretKey);\n\n\t\t\tif (decoded.schema !== 'Secp256k1') {\n\t\t\t\tthrow new Error(`Expected a Secp256k1 keypair, got ${decoded.schema}`);\n\t\t\t}\n\n\t\t\treturn this.fromSecretKey(decoded.secretKey, options);\n\t\t}\n\n\t\tconst publicKey: Uint8Array = secp256k1.getPublicKey(secretKey, true);\n\t\tif (!options || !options.skipValidation) {\n\t\t\tconst encoder = new TextEncoder();\n\t\t\tconst signData = encoder.encode('sui validation');\n\t\t\tconst msgHash = bytesToHex(blake2b(signData, { dkLen: 32 }));\n\t\t\tconst signature = secp256k1.sign(msgHash, secretKey);\n\t\t\tif (!secp256k1.verify(signature, msgHash, publicKey, { lowS: true })) {\n\t\t\t\tthrow new Error('Provided secretKey is invalid');\n\t\t\t}\n\t\t}\n\t\treturn new Secp256k1Keypair({ publicKey, secretKey });\n\t}\n\n\t/**\n\t * Generate a keypair from a 32 byte seed.\n\t *\n\t * @param seed seed byte array\n\t */\n\tstatic fromSeed(seed: Uint8Array): Secp256k1Keypair {\n\t\tconst publicKey = secp256k1.getPublicKey(seed, true);\n\t\treturn new Secp256k1Keypair({ publicKey, secretKey: seed });\n\t}\n\n\t/**\n\t * The public key for this keypair\n\t */\n\tgetPublicKey(): PublicKey {\n\t\treturn new Secp256k1PublicKey(this.keypair.publicKey);\n\t}\n\t/**\n\t * The Bech32 secret key string for this Secp256k1 keypair\n\t */\n\tgetSecretKey(): string {\n\t\treturn encodeSuiPrivateKey(this.keypair.secretKey, this.getKeyScheme());\n\t}\n\n\t/**\n\t * Return the signature for the provided data.\n\t */\n\tasync sign(data: Uint8Array) {\n\t\tconst msgHash = sha256(data);\n\t\tconst sig = secp256k1.sign(msgHash, this.keypair.secretKey, {\n\t\t\tlowS: true,\n\t\t});\n\t\treturn sig.toCompactRawBytes() as Uint8Array<ArrayBuffer>;\n\t}\n\n\t/**\n\t * Derive Secp256k1 keypair from mnemonics and path. The mnemonics must be normalized\n\t * and validated against the english wordlist.\n\t *\n\t * If path is none, it will default to m/54'/784'/0'/0/0, otherwise the path must\n\t * be compliant to BIP-32 in form m/54'/784'/{account_index}'/{change_index}/{address_index}.\n\t */\n\tstatic deriveKeypair(mnemonics: string, path?: string): Secp256k1Keypair {\n\t\tif (path == null) {\n\t\t\tpath = DEFAULT_SECP256K1_DERIVATION_PATH;\n\t\t}\n\t\tif (!isValidBIP32Path(path)) {\n\t\t\tthrow new Error('Invalid derivation path');\n\t\t}\n\t\tconst key = HDKey.fromMasterSeed(mnemonicToSeed(mnemonics)).derive(path);\n\t\tif (key.publicKey == null || key.privateKey == null) {\n\t\t\tthrow new Error('Invalid key');\n\t\t}\n\t\treturn new Secp256k1Keypair({\n\t\t\tpublicKey: key.publicKey,\n\t\t\tsecretKey: key.privateKey,\n\t\t});\n\t}\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAA0B;AAC1B,qBAAwB;AACxB,oBAAuB;AACvB,mBAA2B;AAC3B,mBAAsB;AAEtB,qBAAkE;AAClE,uBAAiD;AAGjD,uBAAmC;AAE5B,MAAM,oCAAoC;AAa1C,MAAM,yBAAyB,uBAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAS7C,YAAY,SAAgC;AAC3C,UAAM;AACN,QAAI,SAAS;AACZ,WAAK,UAAU;AAAA,IAChB,OAAO;AACN,YAAM,YAAwB,2BAAU,MAAM,iBAAiB;AAC/D,YAAM,YAAwB,2BAAU,aAAa,WAAW,IAAI;AAEpE,WAAK,UAAU,EAAE,WAAW,UAAU;AAAA,IACvC;AAAA,EACD;AAAA;AAAA;AAAA;AAAA,EAKA,eAAgC;AAC/B,WAAO;AAAA,EACR;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO,WAA6B;AACnC,WAAO,IAAI,iBAAiB;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAeA,OAAO,cACN,WACA,SACmB;AACnB,QAAI,OAAO,cAAc,UAAU;AAClC,YAAM,cAAU,oCAAoB,SAAS;AAE7C,UAAI,QAAQ,WAAW,aAAa;AACnC,cAAM,IAAI,MAAM,qCAAqC,QAAQ,MAAM,EAAE;AAAA,M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aAAO;AAAA,IACR;AACA,QAAI,KAAC,mCAAiB,IAAI,GAAG;AAC5B,YAAM,IAAI,MAAM,yBAAyB;AAAA,IAC1C;AACA,UAAM,MAAM,mBAAM,mBAAe,iCAAe,SAAS,CAAC,EAAE,OAAO,IAAI;AACvE,QAAI,IAAI,aAAa,QAAQ,IAAI,cAAc,MAAM;AACpD,YAAM,IAAI,MAAM,aAAa;AAAA,IAC9B;AACA,WAAO,IAAI,iBAAiB;AAAA,MAC3B,WAAW,IAAI;AAAA,MACf,WAAW,IAAI;AAAA,IAChB,CAAC;AAAA,EACF;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -18,7 +18,7 @@ export declare class Secp256k1PublicKey extends PublicKey {
|
|
|
18
18
|
/**
|
|
19
19
|
* Return the byte array representation of the Secp256k1 public key
|
|
20
20
|
*/
|
|
21
|
-
toRawBytes(): Uint8Array
|
|
21
|
+
toRawBytes(): Uint8Array<ArrayBuffer>;
|
|
22
22
|
/**
|
|
23
23
|
* Return the Sui address associated with this Secp256k1 public key
|
|
24
24
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/keypairs/secp256k1/publickey.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase64 } from '@mysten/bcs';\nimport { secp256k1 } from '@noble/curves/secp256k1';\nimport { sha256 } from '@noble/hashes/sha256';\n\nimport {\n\tbytesEqual,\n\tparseSerializedKeypairSignature,\n\tPublicKey,\n} from '../../cryptography/publickey.js';\nimport type { PublicKeyInitData } from '../../cryptography/publickey.js';\nimport { SIGNATURE_SCHEME_TO_FLAG } from '../../cryptography/signature-scheme.js';\n\nconst SECP256K1_PUBLIC_KEY_SIZE = 33;\n\n/**\n * A Secp256k1 public key\n */\nexport class Secp256k1PublicKey extends PublicKey {\n\tstatic SIZE = SECP256K1_PUBLIC_KEY_SIZE;\n\tprivate data: Uint8Array
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAA2B;AAC3B,uBAA0B;AAC1B,oBAAuB;AAEvB,uBAIO;AAEP,8BAAyC;AAEzC,MAAM,4BAA4B;AAK3B,MAAM,2BAA2B,2BAAU;AAAA;AAAA;AAAA;AAAA;AAAA,EAQjD,YAAY,OAA0B;AACrC,UAAM;AAEN,QAAI,OAAO,UAAU,UAAU;AAC9B,WAAK,WAAO,uBAAW,KAAK;AAAA,IAC7B,WAAW,iBAAiB,YAAY;AACvC,WAAK,OAAO;AAAA,IACb,OAAO;AACN,WAAK,OAAO,WAAW,KAAK,KAAK;AAAA,IAClC;AAEA,QAAI,KAAK,KAAK,WAAW,2BAA2B;AACnD,YAAM,IAAI;AAAA,QACT,sCAAsC,yBAAyB,eAAe,KAAK,KAAK,MAAM;AAAA,MAC/F;AAAA,IACD;AAAA,EACD;AAAA;AAAA;AAAA;AAAA,EAKS,OAAO,WAAwC;AACvD,WAAO,MAAM,OAAO,SAAS;AAAA,EAC9B;AAAA;AAAA;AAAA;AAAA,EAKA,
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase64 } from '@mysten/bcs';\nimport { secp256k1 } from '@noble/curves/secp256k1';\nimport { sha256 } from '@noble/hashes/sha256';\n\nimport {\n\tbytesEqual,\n\tparseSerializedKeypairSignature,\n\tPublicKey,\n} from '../../cryptography/publickey.js';\nimport type { PublicKeyInitData } from '../../cryptography/publickey.js';\nimport { SIGNATURE_SCHEME_TO_FLAG } from '../../cryptography/signature-scheme.js';\n\nconst SECP256K1_PUBLIC_KEY_SIZE = 33;\n\n/**\n * A Secp256k1 public key\n */\nexport class Secp256k1PublicKey extends PublicKey {\n\tstatic SIZE = SECP256K1_PUBLIC_KEY_SIZE;\n\tprivate data: Uint8Array<ArrayBuffer>;\n\n\t/**\n\t * Create a new Secp256k1PublicKey object\n\t * @param value secp256k1 public key as buffer or base-64 encoded string\n\t */\n\tconstructor(value: PublicKeyInitData) {\n\t\tsuper();\n\n\t\tif (typeof value === 'string') {\n\t\t\tthis.data = fromBase64(value);\n\t\t} else if (value instanceof Uint8Array) {\n\t\t\tthis.data = value as Uint8Array<ArrayBuffer>;\n\t\t} else {\n\t\t\tthis.data = Uint8Array.from(value);\n\t\t}\n\n\t\tif (this.data.length !== SECP256K1_PUBLIC_KEY_SIZE) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid public key input. Expected ${SECP256K1_PUBLIC_KEY_SIZE} bytes, got ${this.data.length}`,\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Checks if two Secp256k1 public keys are equal\n\t */\n\toverride equals(publicKey: Secp256k1PublicKey): boolean {\n\t\treturn super.equals(publicKey);\n\t}\n\n\t/**\n\t * Return the byte array representation of the Secp256k1 public key\n\t */\n\ttoRawBytes(): Uint8Array<ArrayBuffer> {\n\t\treturn this.data;\n\t}\n\n\t/**\n\t * Return the Sui address associated with this Secp256k1 public key\n\t */\n\tflag(): number {\n\t\treturn SIGNATURE_SCHEME_TO_FLAG['Secp256k1'];\n\t}\n\n\t/**\n\t * Verifies that the signature is valid for for the provided message\n\t */\n\tasync verify(message: Uint8Array, signature: Uint8Array | string): Promise<boolean> {\n\t\tlet bytes;\n\t\tif (typeof signature === 'string') {\n\t\t\tconst parsed = parseSerializedKeypairSignature(signature);\n\t\t\tif (parsed.signatureScheme !== 'Secp256k1') {\n\t\t\t\tthrow new Error('Invalid signature scheme');\n\t\t\t}\n\n\t\t\tif (!bytesEqual(this.toRawBytes(), parsed.publicKey)) {\n\t\t\t\tthrow new Error('Signature does not match public key');\n\t\t\t}\n\n\t\t\tbytes = parsed.signature;\n\t\t} else {\n\t\t\tbytes = signature;\n\t\t}\n\n\t\treturn secp256k1.verify(\n\t\t\tsecp256k1.Signature.fromCompact(bytes),\n\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;AAAA,IACT;AAEA,WAAO,2BAAU;AAAA,MAChB,2BAAU,UAAU,YAAY,KAAK;AAAA,UACrC,sBAAO,OAAO;AAAA,MACd,KAAK,WAAW;AAAA,IACjB;AAAA,EACD;AACD;AAzEa,mBACL,OAAO;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -61,7 +61,7 @@ export declare class Secp256r1Keypair extends Keypair {
|
|
|
61
61
|
/**
|
|
62
62
|
* Return the signature for the provided data.
|
|
63
63
|
*/
|
|
64
|
-
sign(data: Uint8Array): Promise<Uint8Array<
|
|
64
|
+
sign(data: Uint8Array): Promise<Uint8Array<ArrayBuffer>>;
|
|
65
65
|
/**
|
|
66
66
|
* Derive Secp256r1 keypair from mnemonics and path. The mnemonics must be normalized
|
|
67
67
|
* and validated against the english wordlist.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/keypairs/secp256r1/keypair.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { secp256r1 } from '@noble/curves/p256';\nimport { blake2b } from '@noble/hashes/blake2b';\nimport { sha256 } from '@noble/hashes/sha256';\nimport { bytesToHex } from '@noble/hashes/utils';\nimport { HDKey } from '@scure/bip32';\n\nimport { decodeSuiPrivateKey, encodeSuiPrivateKey, Keypair } from '../../cryptography/keypair.js';\nimport { isValidBIP32Path, mnemonicToSeed } from '../../cryptography/mnemonics.js';\nimport type { PublicKey } from '../../cryptography/publickey.js';\nimport type { SignatureScheme } from '../../cryptography/signature-scheme.js';\nimport { Secp256r1PublicKey } from './publickey.js';\n\nexport const DEFAULT_SECP256R1_DERIVATION_PATH = \"m/74'/784'/0'/0/0\";\n\n/**\n * Secp256r1 Keypair data\n */\nexport interface Secp256r1KeypairData {\n\tpublicKey: Uint8Array;\n\tsecretKey: Uint8Array;\n}\n\n/**\n * An Secp256r1 Keypair used for signing transactions.\n */\nexport class Secp256r1Keypair extends Keypair {\n\tprivate keypair: Secp256r1KeypairData;\n\n\t/**\n\t * Create a new keypair instance.\n\t * Generate random keypair if no {@link Secp256r1Keypair} is provided.\n\t *\n\t * @param keypair Secp256r1 keypair\n\t */\n\tconstructor(keypair?: Secp256r1KeypairData) {\n\t\tsuper();\n\t\tif (keypair) {\n\t\t\tthis.keypair = keypair;\n\t\t} else {\n\t\t\tconst secretKey: Uint8Array = secp256r1.utils.randomPrivateKey();\n\t\t\tconst publicKey: Uint8Array = secp256r1.getPublicKey(secretKey, true);\n\n\t\t\tthis.keypair = { publicKey, secretKey };\n\t\t}\n\t}\n\n\t/**\n\t * Get the key scheme of the keypair Secp256r1\n\t */\n\tgetKeyScheme(): SignatureScheme {\n\t\treturn 'Secp256r1';\n\t}\n\n\t/**\n\t * Generate a new random keypair\n\t */\n\tstatic generate(): Secp256r1Keypair {\n\t\treturn new Secp256r1Keypair();\n\t}\n\n\t/**\n\t * Create a keypair from a raw secret key byte array.\n\t *\n\t * This method should only be used to recreate a keypair from a previously\n\t * generated secret key. Generating keypairs from a random seed should be done\n\t * with the {@link Keypair.fromSeed} method.\n\t *\n\t * @throws error if the provided secret key is invalid and validation is not skipped.\n\t *\n\t * @param secretKey secret key byte array or Bech32 secret key string\n\t * @param options: skip secret key validation\n\t */\n\n\tstatic fromSecretKey(\n\t\tsecretKey: Uint8Array | string,\n\t\toptions?: { skipValidation?: boolean },\n\t): Secp256r1Keypair {\n\t\tif (typeof secretKey === 'string') {\n\t\t\tconst decoded = decodeSuiPrivateKey(secretKey);\n\n\t\t\tif (decoded.schema !== 'Secp256r1') {\n\t\t\t\tthrow new Error(`Expected a Secp256r1 keypair, got ${decoded.schema}`);\n\t\t\t}\n\n\t\t\treturn this.fromSecretKey(decoded.secretKey, options);\n\t\t}\n\n\t\tconst publicKey: Uint8Array = secp256r1.getPublicKey(secretKey, true);\n\t\tif (!options || !options.skipValidation) {\n\t\t\tconst encoder = new TextEncoder();\n\t\t\tconst signData = encoder.encode('sui validation');\n\t\t\tconst msgHash = bytesToHex(blake2b(signData, { dkLen: 32 }));\n\t\t\tconst signature = secp256r1.sign(msgHash, secretKey, { lowS: true });\n\t\t\tif (!secp256r1.verify(signature, msgHash, publicKey, { lowS: true })) {\n\t\t\t\tthrow new Error('Provided secretKey is invalid');\n\t\t\t}\n\t\t}\n\t\treturn new Secp256r1Keypair({ publicKey, secretKey });\n\t}\n\n\t/**\n\t * Generate a keypair from a 32 byte seed.\n\t *\n\t * @param seed seed byte array\n\t */\n\tstatic fromSeed(seed: Uint8Array): Secp256r1Keypair {\n\t\tconst publicKey = secp256r1.getPublicKey(seed, true);\n\t\treturn new Secp256r1Keypair({ publicKey, secretKey: seed });\n\t}\n\n\t/**\n\t * The public key for this keypair\n\t */\n\tgetPublicKey(): PublicKey {\n\t\treturn new Secp256r1PublicKey(this.keypair.publicKey);\n\t}\n\n\t/**\n\t * The Bech32 secret key string for this Secp256r1 keypair\n\t */\n\tgetSecretKey(): string {\n\t\treturn encodeSuiPrivateKey(this.keypair.secretKey, this.getKeyScheme());\n\t}\n\n\t/**\n\t * Return the signature for the provided data.\n\t */\n\tasync sign(data: Uint8Array) {\n\t\tconst msgHash = sha256(data);\n\t\tconst sig = secp256r1.sign(msgHash, this.keypair.secretKey, {\n\t\t\tlowS: true,\n\t\t});\n\t\treturn sig.toCompactRawBytes()
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { secp256r1 } from '@noble/curves/p256';\nimport { blake2b } from '@noble/hashes/blake2b';\nimport { sha256 } from '@noble/hashes/sha256';\nimport { bytesToHex } from '@noble/hashes/utils';\nimport { HDKey } from '@scure/bip32';\n\nimport { decodeSuiPrivateKey, encodeSuiPrivateKey, Keypair } from '../../cryptography/keypair.js';\nimport { isValidBIP32Path, mnemonicToSeed } from '../../cryptography/mnemonics.js';\nimport type { PublicKey } from '../../cryptography/publickey.js';\nimport type { SignatureScheme } from '../../cryptography/signature-scheme.js';\nimport { Secp256r1PublicKey } from './publickey.js';\n\nexport const DEFAULT_SECP256R1_DERIVATION_PATH = \"m/74'/784'/0'/0/0\";\n\n/**\n * Secp256r1 Keypair data\n */\nexport interface Secp256r1KeypairData {\n\tpublicKey: Uint8Array;\n\tsecretKey: Uint8Array;\n}\n\n/**\n * An Secp256r1 Keypair used for signing transactions.\n */\nexport class Secp256r1Keypair extends Keypair {\n\tprivate keypair: Secp256r1KeypairData;\n\n\t/**\n\t * Create a new keypair instance.\n\t * Generate random keypair if no {@link Secp256r1Keypair} is provided.\n\t *\n\t * @param keypair Secp256r1 keypair\n\t */\n\tconstructor(keypair?: Secp256r1KeypairData) {\n\t\tsuper();\n\t\tif (keypair) {\n\t\t\tthis.keypair = keypair;\n\t\t} else {\n\t\t\tconst secretKey: Uint8Array = secp256r1.utils.randomPrivateKey();\n\t\t\tconst publicKey: Uint8Array = secp256r1.getPublicKey(secretKey, true);\n\n\t\t\tthis.keypair = { publicKey, secretKey };\n\t\t}\n\t}\n\n\t/**\n\t * Get the key scheme of the keypair Secp256r1\n\t */\n\tgetKeyScheme(): SignatureScheme {\n\t\treturn 'Secp256r1';\n\t}\n\n\t/**\n\t * Generate a new random keypair\n\t */\n\tstatic generate(): Secp256r1Keypair {\n\t\treturn new Secp256r1Keypair();\n\t}\n\n\t/**\n\t * Create a keypair from a raw secret key byte array.\n\t *\n\t * This method should only be used to recreate a keypair from a previously\n\t * generated secret key. Generating keypairs from a random seed should be done\n\t * with the {@link Keypair.fromSeed} method.\n\t *\n\t * @throws error if the provided secret key is invalid and validation is not skipped.\n\t *\n\t * @param secretKey secret key byte array or Bech32 secret key string\n\t * @param options: skip secret key validation\n\t */\n\n\tstatic fromSecretKey(\n\t\tsecretKey: Uint8Array | string,\n\t\toptions?: { skipValidation?: boolean },\n\t): Secp256r1Keypair {\n\t\tif (typeof secretKey === 'string') {\n\t\t\tconst decoded = decodeSuiPrivateKey(secretKey);\n\n\t\t\tif (decoded.schema !== 'Secp256r1') {\n\t\t\t\tthrow new Error(`Expected a Secp256r1 keypair, got ${decoded.schema}`);\n\t\t\t}\n\n\t\t\treturn this.fromSecretKey(decoded.secretKey, options);\n\t\t}\n\n\t\tconst publicKey: Uint8Array = secp256r1.getPublicKey(secretKey, true);\n\t\tif (!options || !options.skipValidation) {\n\t\t\tconst encoder = new TextEncoder();\n\t\t\tconst signData = encoder.encode('sui validation');\n\t\t\tconst msgHash = bytesToHex(blake2b(signData, { dkLen: 32 }));\n\t\t\tconst signature = secp256r1.sign(msgHash, secretKey, { lowS: true });\n\t\t\tif (!secp256r1.verify(signature, msgHash, publicKey, { lowS: true })) {\n\t\t\t\tthrow new Error('Provided secretKey is invalid');\n\t\t\t}\n\t\t}\n\t\treturn new Secp256r1Keypair({ publicKey, secretKey });\n\t}\n\n\t/**\n\t * Generate a keypair from a 32 byte seed.\n\t *\n\t * @param seed seed byte array\n\t */\n\tstatic fromSeed(seed: Uint8Array): Secp256r1Keypair {\n\t\tconst publicKey = secp256r1.getPublicKey(seed, true);\n\t\treturn new Secp256r1Keypair({ publicKey, secretKey: seed });\n\t}\n\n\t/**\n\t * The public key for this keypair\n\t */\n\tgetPublicKey(): PublicKey {\n\t\treturn new Secp256r1PublicKey(this.keypair.publicKey);\n\t}\n\n\t/**\n\t * The Bech32 secret key string for this Secp256r1 keypair\n\t */\n\tgetSecretKey(): string {\n\t\treturn encodeSuiPrivateKey(this.keypair.secretKey, this.getKeyScheme());\n\t}\n\n\t/**\n\t * Return the signature for the provided data.\n\t */\n\tasync sign(data: Uint8Array) {\n\t\tconst msgHash = sha256(data);\n\t\tconst sig = secp256r1.sign(msgHash, this.keypair.secretKey, {\n\t\t\tlowS: true,\n\t\t});\n\t\treturn sig.toCompactRawBytes() as Uint8Array<ArrayBuffer>;\n\t}\n\n\t/**\n\t * Derive Secp256r1 keypair from mnemonics and path. The mnemonics must be normalized\n\t * and validated against the english wordlist.\n\t *\n\t * If path is none, it will default to m/74'/784'/0'/0/0, otherwise the path must\n\t * be compliant to BIP-32 in form m/74'/784'/{account_index}'/{change_index}/{address_index}.\n\t */\n\tstatic deriveKeypair(mnemonics: string, path?: string): Secp256r1Keypair {\n\t\tif (path == null) {\n\t\t\tpath = DEFAULT_SECP256R1_DERIVATION_PATH;\n\t\t}\n\t\tif (!isValidBIP32Path(path)) {\n\t\t\tthrow new Error('Invalid derivation path');\n\t\t}\n\t\t// We use HDKey which is hardcoded to use Secp256k1 but since we only need the 32 bytes for the private key it's okay to use here as well.\n\t\tconst privateKey = HDKey.fromMasterSeed(mnemonicToSeed(mnemonics)).derive(path).privateKey;\n\t\treturn Secp256r1Keypair.fromSecretKey(privateKey!);\n\t}\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA0B;AAC1B,qBAAwB;AACxB,oBAAuB;AACvB,mBAA2B;AAC3B,mBAAsB;AAEtB,qBAAkE;AAClE,uBAAiD;AAGjD,uBAAmC;AAE5B,MAAM,oCAAoC;AAa1C,MAAM,yBAAyB,uBAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAS7C,YAAY,SAAgC;AAC3C,UAAM;AACN,QAAI,SAAS;AACZ,WAAK,UAAU;AAAA,IAChB,OAAO;AACN,YAAM,YAAwB,sBAAU,MAAM,iBAAiB;AAC/D,YAAM,YAAwB,sBAAU,aAAa,WAAW,IAAI;AAEpE,WAAK,UAAU,EAAE,WAAW,UAAU;AAAA,IACvC;AAAA,EACD;AAAA;AAAA;AAAA;AAAA,EAKA,eAAgC;AAC/B,WAAO;AAAA,EACR;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO,WAA6B;AACnC,WAAO,IAAI,iBAAiB;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAeA,OAAO,cACN,WACA,SACmB;A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C3D,MAAM;AAAA,IACP,CAAC;AACD,WAAO,IAAI,kBAAkB;AAAA,EAC9B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,OAAO,cAAc,WAAmB,MAAiC;AACxE,QAAI,QAAQ,MAAM;AACjB,aAAO;AAAA,IACR;AACA,QAAI,KAAC,mCAAiB,IAAI,GAAG;AAC5B,YAAM,IAAI,MAAM,yBAAyB;AAAA,IAC1C;AAEA,UAAM,aAAa,mBAAM,mBAAe,iCAAe,SAAS,CAAC,EAAE,OAAO,IAAI,EAAE;AAChF,WAAO,iBAAiB,cAAc,UAAW;AAAA,EAClD;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -18,7 +18,7 @@ export declare class Secp256r1PublicKey extends PublicKey {
|
|
|
18
18
|
/**
|
|
19
19
|
* Return the byte array representation of the Secp256r1 public key
|
|
20
20
|
*/
|
|
21
|
-
toRawBytes(): Uint8Array
|
|
21
|
+
toRawBytes(): Uint8Array<ArrayBuffer>;
|
|
22
22
|
/**
|
|
23
23
|
* Return the Sui address associated with this Secp256r1 public key
|
|
24
24
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/keypairs/secp256r1/publickey.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase64 } from '@mysten/bcs';\nimport { secp256r1 } from '@noble/curves/p256';\nimport { sha256 } from '@noble/hashes/sha256';\n\nimport { bytesEqual, PublicKey } from '../../cryptography/publickey.js';\nimport type { PublicKeyInitData } from '../../cryptography/publickey.js';\nimport { SIGNATURE_SCHEME_TO_FLAG } from '../../cryptography/signature-scheme.js';\nimport { parseSerializedSignature } from '../../cryptography/signature.js';\n\nconst SECP256R1_PUBLIC_KEY_SIZE = 33;\n\n/**\n * A Secp256r1 public key\n */\nexport class Secp256r1PublicKey extends PublicKey {\n\tstatic SIZE = SECP256R1_PUBLIC_KEY_SIZE;\n\tprivate data: Uint8Array
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAA2B;AAC3B,kBAA0B;AAC1B,oBAAuB;AAEvB,uBAAsC;AAEtC,8BAAyC;AACzC,uBAAyC;AAEzC,MAAM,4BAA4B;AAK3B,MAAM,2BAA2B,2BAAU;AAAA;AAAA;AAAA;AAAA;AAAA,EAQjD,YAAY,OAA0B;AACrC,UAAM;AAEN,QAAI,OAAO,UAAU,UAAU;AAC9B,WAAK,WAAO,uBAAW,KAAK;AAAA,IAC7B,WAAW,iBAAiB,YAAY;AACvC,WAAK,OAAO;AAAA,IACb,OAAO;AACN,WAAK,OAAO,WAAW,KAAK,KAAK;AAAA,IAClC;AAEA,QAAI,KAAK,KAAK,WAAW,2BAA2B;AACnD,YAAM,IAAI;AAAA,QACT,sCAAsC,yBAAyB,eAAe,KAAK,KAAK,MAAM;AAAA,MAC/F;AAAA,IACD;AAAA,EACD;AAAA;AAAA;AAAA;AAAA,EAKS,OAAO,WAAwC;AACvD,WAAO,MAAM,OAAO,SAAS;AAAA,EAC9B;AAAA;AAAA;AAAA;AAAA,EAKA,
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase64 } from '@mysten/bcs';\nimport { secp256r1 } from '@noble/curves/p256';\nimport { sha256 } from '@noble/hashes/sha256';\n\nimport { bytesEqual, PublicKey } from '../../cryptography/publickey.js';\nimport type { PublicKeyInitData } from '../../cryptography/publickey.js';\nimport { SIGNATURE_SCHEME_TO_FLAG } from '../../cryptography/signature-scheme.js';\nimport { parseSerializedSignature } from '../../cryptography/signature.js';\n\nconst SECP256R1_PUBLIC_KEY_SIZE = 33;\n\n/**\n * A Secp256r1 public key\n */\nexport class Secp256r1PublicKey extends PublicKey {\n\tstatic SIZE = SECP256R1_PUBLIC_KEY_SIZE;\n\tprivate data: Uint8Array<ArrayBuffer>;\n\n\t/**\n\t * Create a new Secp256r1PublicKey object\n\t * @param value secp256r1 public key as buffer or base-64 encoded string\n\t */\n\tconstructor(value: PublicKeyInitData) {\n\t\tsuper();\n\n\t\tif (typeof value === 'string') {\n\t\t\tthis.data = fromBase64(value);\n\t\t} else if (value instanceof Uint8Array) {\n\t\t\tthis.data = value as Uint8Array<ArrayBuffer>;\n\t\t} else {\n\t\t\tthis.data = Uint8Array.from(value);\n\t\t}\n\n\t\tif (this.data.length !== SECP256R1_PUBLIC_KEY_SIZE) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid public key input. Expected ${SECP256R1_PUBLIC_KEY_SIZE} bytes, got ${this.data.length}`,\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Checks if two Secp256r1 public keys are equal\n\t */\n\toverride equals(publicKey: Secp256r1PublicKey): boolean {\n\t\treturn super.equals(publicKey);\n\t}\n\n\t/**\n\t * Return the byte array representation of the Secp256r1 public key\n\t */\n\ttoRawBytes(): Uint8Array<ArrayBuffer> {\n\t\treturn this.data;\n\t}\n\n\t/**\n\t * Return the Sui address associated with this Secp256r1 public key\n\t */\n\tflag(): number {\n\t\treturn SIGNATURE_SCHEME_TO_FLAG['Secp256r1'];\n\t}\n\n\t/**\n\t * Verifies that the signature is valid for for the provided message\n\t */\n\tasync verify(message: Uint8Array, signature: Uint8Array | string): Promise<boolean> {\n\t\tlet bytes;\n\t\tif (typeof signature === 'string') {\n\t\t\tconst parsed = parseSerializedSignature(signature);\n\t\t\tif (parsed.signatureScheme !== 'Secp256r1') {\n\t\t\t\tthrow new Error('Invalid signature scheme');\n\t\t\t}\n\n\t\t\tif (!bytesEqual(this.toRawBytes(), parsed.publicKey)) {\n\t\t\t\tthrow new Error('Signature does not match public key');\n\t\t\t}\n\n\t\t\tbytes = parsed.signature;\n\t\t} else {\n\t\t\tbytes = signature;\n\t\t}\n\n\t\treturn secp256r1.verify(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,MACtD;AAEA,cAAQ,OAAO;AAAA,IAChB,OAAO;AACN,cAAQ;AAAA,IACT;AAEA,WAAO,sBAAU;AAAA,MAChB,sBAAU,UAAU,YAAY,KAAK;AAAA,UACrC,sBAAO,OAAO;AAAA,MACd,KAAK,WAAW;AAAA,IACjB;AAAA,EACD;AACD;AAzEa,mBACL,OAAO;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -80,7 +80,7 @@ export declare class MultiSigPublicKey extends PublicKey {
|
|
|
80
80
|
/**
|
|
81
81
|
* Return the byte array representation of the MultiSig public key
|
|
82
82
|
*/
|
|
83
|
-
toRawBytes(): Uint8Array
|
|
83
|
+
toRawBytes(): Uint8Array<ArrayBuffer>;
|
|
84
84
|
getPublicKeys(): {
|
|
85
85
|
weight: number;
|
|
86
86
|
publicKey: PublicKey;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/multisig/publickey.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase64, toBase64 } from '@mysten/bcs';\nimport { blake2b } from '@noble/hashes/blake2b';\nimport { bytesToHex } from '@noble/hashes/utils';\n\nimport { bcs } from '../bcs/index.js';\nimport type { Signer } from '../cryptography/keypair.js';\nimport { bytesEqual, PublicKey } from '../cryptography/publickey.js';\nimport {\n\tSIGNATURE_FLAG_TO_SCHEME,\n\tSIGNATURE_SCHEME_TO_FLAG,\n} from '../cryptography/signature-scheme.js';\nimport type { SignatureFlag, SignatureScheme } from '../cryptography/signature-scheme.js';\nimport { parseSerializedSignature } from '../cryptography/signature.js';\nimport { normalizeSuiAddress } from '../utils/sui-types.js';\n// eslint-disable-next-line import/no-cycle\nimport { publicKeyFromRawBytes } from '../verify/index.js';\nimport type { ZkLoginCompatibleClient } from '../zklogin/publickey.js';\nimport { toZkLoginPublicIdentifier } from '../zklogin/publickey.js';\nimport { MultiSigSigner } from './signer.js';\n\ntype CompressedSignature =\n\t| { ED25519: number[] }\n\t| { Secp256k1: number[] }\n\t| { Secp256r1: number[] }\n\t| { ZkLogin: number[] }\n\t| { Passkey: number[] };\n\ntype PublicKeyEnum =\n\t| { ED25519: number[] }\n\t| { Secp256k1: number[] }\n\t| { Secp256r1: number[] }\n\t| { ZkLogin: number[] }\n\t| { Passkey: number[] };\n\ntype PubkeyEnumWeightPair = {\n\tpubKey: PublicKeyEnum;\n\tweight: number;\n};\n\ntype MultiSigPublicKeyStruct = {\n\tpk_map: PubkeyEnumWeightPair[];\n\tthreshold: number;\n};\n\nexport type MultiSigStruct = {\n\tsigs: CompressedSignature[];\n\tbitmap: number;\n\tmultisig_pk: MultiSigPublicKeyStruct;\n};\n\ntype ParsedPartialMultiSigSignature = {\n\tsignatureScheme: SignatureScheme;\n\tsignature: Uint8Array;\n\tpublicKey: PublicKey;\n\tweight: number;\n};\n\nexport const MAX_SIGNER_IN_MULTISIG = 10;\nexport const MIN_SIGNER_IN_MULTISIG = 1;\n/**\n * A MultiSig public key\n */\nexport class MultiSigPublicKey extends PublicKey {\n\tprivate rawBytes: Uint8Array;\n\tprivate multisigPublicKey: MultiSigPublicKeyStruct;\n\tprivate publicKeys: {\n\t\tweight: number;\n\t\tpublicKey: PublicKey;\n\t}[];\n\t/**\n\t * Create a new MultiSigPublicKey object\n\t */\n\tconstructor(\n\t\t/**\n\t\t * MultiSig public key as buffer or base-64 encoded string\n\t\t */\n\t\tvalue: string | Uint8Array | MultiSigPublicKeyStruct,\n\t\toptions: { client?: ZkLoginCompatibleClient } = {},\n\t) {\n\t\tsuper();\n\n\t\tif (typeof value === 'string') {\n\t\t\tthis.rawBytes = fromBase64(value);\n\n\t\t\tthis.multisigPublicKey = bcs.MultiSigPublicKey.parse(this.rawBytes);\n\t\t} else if (value instanceof Uint8Array) {\n\t\t\tthis.rawBytes = value;\n\t\t\tthis.multisigPublicKey = bcs.MultiSigPublicKey.parse(this.rawBytes);\n\t\t} else {\n\t\t\tthis.multisigPublicKey = value;\n\t\t\tthis.rawBytes = bcs.MultiSigPublicKey.serialize(value).toBytes();\n\t\t}\n\t\tif (this.multisigPublicKey.threshold < 1) {\n\t\t\tthrow new Error('Invalid threshold');\n\t\t}\n\n\t\tconst seenPublicKeys = new Set<string>();\n\n\t\tthis.publicKeys = this.multisigPublicKey.pk_map.map(({ pubKey, weight }) => {\n\t\t\tconst [scheme, bytes] = Object.entries(pubKey).filter(([name]) => name !== '$kind')[0] as [\n\t\t\t\tSignatureScheme,\n\t\t\t\tnumber[],\n\t\t\t];\n\t\t\tconst publicKeyStr = Uint8Array.from(bytes).toString();\n\n\t\t\tif (seenPublicKeys.has(publicKeyStr)) {\n\t\t\t\tthrow new Error(`Multisig does not support duplicate public keys`);\n\t\t\t}\n\t\t\tseenPublicKeys.add(publicKeyStr);\n\n\t\t\tif (weight < 1) {\n\t\t\t\tthrow new Error(`Invalid weight`);\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tpublicKey: publicKeyFromRawBytes(scheme, Uint8Array.from(bytes), options),\n\t\t\t\tweight,\n\t\t\t};\n\t\t});\n\n\t\tconst totalWeight = this.publicKeys.reduce((sum, { weight }) => sum + weight, 0);\n\n\t\tif (this.multisigPublicKey.threshold > totalWeight) {\n\t\t\tthrow new Error(`Unreachable threshold`);\n\t\t}\n\n\t\tif (this.publicKeys.length > MAX_SIGNER_IN_MULTISIG) {\n\t\t\tthrow new Error(`Max number of signers in a multisig is ${MAX_SIGNER_IN_MULTISIG}`);\n\t\t}\n\n\t\tif (this.publicKeys.length < MIN_SIGNER_IN_MULTISIG) {\n\t\t\tthrow new Error(`Min number of signers in a multisig is ${MIN_SIGNER_IN_MULTISIG}`);\n\t\t}\n\t}\n\t/**\n\t * \tA static method to create a new MultiSig publickey instance from a set of public keys and their associated weights pairs and threshold.\n\t */\n\n\tstatic fromPublicKeys({\n\t\tthreshold,\n\t\tpublicKeys,\n\t}: {\n\t\tthreshold: number;\n\t\tpublicKeys: { publicKey: PublicKey; weight: number }[];\n\t}) {\n\t\treturn new MultiSigPublicKey({\n\t\t\tpk_map: publicKeys.map(({ publicKey, weight }) => {\n\t\t\t\tconst scheme = SIGNATURE_FLAG_TO_SCHEME[publicKey.flag() as SignatureFlag];\n\n\t\t\t\treturn {\n\t\t\t\t\tpubKey: { [scheme]: Array.from(publicKey.toRawBytes()) } as PublicKeyEnum,\n\t\t\t\t\tweight,\n\t\t\t\t};\n\t\t\t}),\n\t\t\tthreshold,\n\t\t});\n\t}\n\n\t/**\n\t * Checks if two MultiSig public keys are equal\n\t */\n\toverride equals(publicKey: MultiSigPublicKey): boolean {\n\t\treturn super.equals(publicKey);\n\t}\n\n\t/**\n\t * Return the byte array representation of the MultiSig public key\n\t */\n\ttoRawBytes(): Uint8Array {\n\t\treturn this.rawBytes;\n\t}\n\n\tgetPublicKeys() {\n\t\treturn this.publicKeys;\n\t}\n\n\tgetThreshold() {\n\t\treturn this.multisigPublicKey.threshold;\n\t}\n\n\tgetSigner(...signers: [signer: Signer]) {\n\t\treturn new MultiSigSigner(this, signers);\n\t}\n\n\t/**\n\t * Return the Sui address associated with this MultiSig public key\n\t */\n\toverride toSuiAddress(): string {\n\t\t// max length = 1 flag byte + (max pk size + max weight size (u8)) * max signer size + 2 threshold bytes (u16)\n\t\tconst maxLength = 1 + (64 + 1) * MAX_SIGNER_IN_MULTISIG + 2;\n\t\tconst tmp = new Uint8Array(maxLength);\n\t\ttmp.set([SIGNATURE_SCHEME_TO_FLAG['MultiSig']]);\n\n\t\ttmp.set(bcs.u16().serialize(this.multisigPublicKey.threshold).toBytes(), 1);\n\t\t// The initial value 3 ensures that following data will be after the flag byte and threshold bytes\n\t\tlet i = 3;\n\t\tfor (const { publicKey, weight } of this.publicKeys) {\n\t\t\tconst bytes = publicKey.toSuiBytes();\n\t\t\ttmp.set(bytes, i);\n\t\t\ti += bytes.length;\n\t\t\ttmp.set([weight], i++);\n\t\t}\n\t\treturn normalizeSuiAddress(bytesToHex(blake2b(tmp.slice(0, i), { dkLen: 32 })));\n\t}\n\n\t/**\n\t * Return the Sui address associated with this MultiSig public key\n\t */\n\tflag(): number {\n\t\treturn SIGNATURE_SCHEME_TO_FLAG['MultiSig'];\n\t}\n\n\t/**\n\t * Verifies that the signature is valid for for the provided message\n\t */\n\tasync verify(message: Uint8Array, multisigSignature: string): Promise<boolean> {\n\t\t// Multisig verification only supports serialized signature\n\t\tconst parsed = parseSerializedSignature(multisigSignature);\n\n\t\tif (parsed.signatureScheme !== 'MultiSig') {\n\t\t\tthrow new Error('Invalid signature scheme');\n\t\t}\n\n\t\tconst { multisig } = parsed;\n\n\t\tlet signatureWeight = 0;\n\n\t\tif (\n\t\t\t!bytesEqual(\n\t\t\t\tbcs.MultiSigPublicKey.serialize(this.multisigPublicKey).toBytes(),\n\t\t\t\tbcs.MultiSigPublicKey.serialize(multisig.multisig_pk).toBytes(),\n\t\t\t)\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\n\t\tfor (const { publicKey, weight, signature } of parsePartialSignatures(multisig)) {\n\t\t\tif (!(await publicKey.verify(message, signature))) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tsignatureWeight += weight;\n\t\t}\n\n\t\treturn signatureWeight >= this.multisigPublicKey.threshold;\n\t}\n\n\t/**\n\t * Combines multiple partial signatures into a single multisig, ensuring that each public key signs only once\n\t * and that all the public keys involved are known and valid, and then serializes multisig into the standard format\n\t */\n\tcombinePartialSignatures(signatures: string[]): string {\n\t\tif (signatures.length > MAX_SIGNER_IN_MULTISIG) {\n\t\t\tthrow new Error(`Max number of signatures in a multisig is ${MAX_SIGNER_IN_MULTISIG}`);\n\t\t}\n\n\t\tlet bitmap = 0;\n\t\tconst compressedSignatures: CompressedSignature[] = new Array(signatures.length);\n\n\t\tfor (let i = 0; i < signatures.length; i++) {\n\t\t\tconst parsed = parseSerializedSignature(signatures[i]);\n\t\t\tif (parsed.signatureScheme === 'MultiSig') {\n\t\t\t\tthrow new Error('MultiSig is not supported inside MultiSig');\n\t\t\t}\n\n\t\t\tlet publicKey;\n\t\t\tif (parsed.signatureScheme === 'ZkLogin') {\n\t\t\t\tpublicKey = toZkLoginPublicIdentifier(\n\t\t\t\t\tparsed.zkLogin?.addressSeed,\n\t\t\t\t\tparsed.zkLogin?.iss,\n\t\t\t\t).toRawBytes();\n\t\t\t} else {\n\t\t\t\tpublicKey = parsed.publicKey;\n\t\t\t}\n\n\t\t\tcompressedSignatures[i] = {\n\t\t\t\t[parsed.signatureScheme]: Array.from(parsed.signature.map((x: number) => Number(x))),\n\t\t\t} as CompressedSignature;\n\n\t\t\tlet publicKeyIndex;\n\t\t\tfor (let j = 0; j < this.publicKeys.length; j++) {\n\t\t\t\tif (bytesEqual(publicKey, this.publicKeys[j].publicKey.toRawBytes())) {\n\t\t\t\t\tif (bitmap & (1 << j)) {\n\t\t\t\t\t\tthrow new Error('Received multiple signatures from the same public key');\n\t\t\t\t\t}\n\n\t\t\t\t\tpublicKeyIndex = j;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (publicKeyIndex === undefined) {\n\t\t\t\tthrow new Error('Received signature from unknown public key');\n\t\t\t}\n\n\t\t\tbitmap |= 1 << publicKeyIndex;\n\t\t}\n\n\t\tconst multisig: MultiSigStruct = {\n\t\t\tsigs: compressedSignatures,\n\t\t\tbitmap,\n\t\t\tmultisig_pk: this.multisigPublicKey,\n\t\t};\n\t\tconst bytes = bcs.MultiSig.serialize(multisig, { maxSize: 8192 }).toBytes();\n\t\tconst tmp = new Uint8Array(bytes.length + 1);\n\t\ttmp.set([SIGNATURE_SCHEME_TO_FLAG['MultiSig']]);\n\t\ttmp.set(bytes, 1);\n\t\treturn toBase64(tmp);\n\t}\n}\n\n/**\n * Parse multisig structure into an array of individual signatures: signature scheme, the actual individual signature, public key and its weight.\n */\nexport function parsePartialSignatures(\n\tmultisig: MultiSigStruct,\n\toptions: { client?: ZkLoginCompatibleClient } = {},\n): ParsedPartialMultiSigSignature[] {\n\tconst res: ParsedPartialMultiSigSignature[] = new Array(multisig.sigs.length);\n\tfor (let i = 0; i < multisig.sigs.length; i++) {\n\t\tconst [signatureScheme, signature] = Object.entries(multisig.sigs[i]).filter(\n\t\t\t([name]) => name !== '$kind',\n\t\t)[0] as [SignatureScheme, number[]];\n\t\tconst pkIndex = asIndices(multisig.bitmap).at(i)!;\n\t\tconst pair = multisig.multisig_pk.pk_map[pkIndex];\n\t\tconst pkBytes = Uint8Array.from(Object.values(pair.pubKey)[0]);\n\n\t\tif (signatureScheme === 'MultiSig') {\n\t\t\tthrow new Error('MultiSig is not supported inside MultiSig');\n\t\t}\n\n\t\tconst publicKey = publicKeyFromRawBytes(signatureScheme, pkBytes, options);\n\n\t\tres[i] = {\n\t\t\tsignatureScheme,\n\t\t\tsignature: Uint8Array.from(signature),\n\t\t\tpublicKey: publicKey,\n\t\t\tweight: pair.weight,\n\t\t};\n\t}\n\treturn res;\n}\n\nfunction asIndices(bitmap: number): Uint8Array {\n\tif (bitmap < 0 || bitmap > 1024) {\n\t\tthrow new Error('Invalid bitmap');\n\t}\n\tconst res: number[] = [];\n\tfor (let i = 0; i < 10; i++) {\n\t\tif ((bitmap & (1 << i)) !== 0) {\n\t\t\tres.push(i);\n\t\t}\n\t}\n\treturn Uint8Array.from(res);\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAqC;AACrC,qBAAwB;AACxB,mBAA2B;AAE3B,IAAAA,cAAoB;AAEpB,uBAAsC;AACtC,8BAGO;AAEP,uBAAyC;AACzC,uBAAoC;AAEpC,oBAAsC;AAEtC,IAAAC,oBAA0C;AAC1C,oBAA+B;AAuCxB,MAAM,yBAAyB;AAC/B,MAAM,yBAAyB;AAI/B,MAAM,0BAA0B,2BAAU;AAAA;AAAA;AAAA;AAAA,EAUhD,YAIC,OACA,UAAgD,CAAC,GA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C,sBAAsB,EAAE;AAAA,IACnF;AAEA,QAAI,KAAK,WAAW,SAAS,wBAAwB;AACpD,YAAM,IAAI,MAAM,0CAA0C,sBAAsB,EAAE;AAAA,IACnF;AAAA,EACD;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO,eAAe;AAAA,IACrB;AAAA,IACA;AAAA,EACD,GAGG;AACF,WAAO,IAAI,kBAAkB;AAAA,MAC5B,QAAQ,WAAW,IAAI,CAAC,EAAE,WAAW,OAAO,MAAM;AACjD,cAAM,SAAS,iDAAyB,UAAU,KAAK,CAAkB;AAEzE,eAAO;AAAA,UACN,QAAQ,EAAE,CAAC,MAAM,GAAG,MAAM,KAAK,UAAU,WAAW,CAAC,EAAE;AAAA,UACvD;AAAA,QACD;AAAA,MACD,CAAC;AAAA,MACD;AAAA,IACD,CAAC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKS,OAAO,WAAuC;AACtD,WAAO,MAAM,OAAO,SAAS;AAAA,EAC9B;AAAA;AAAA;AAAA;AAAA,EAKA,
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase64, toBase64 } from '@mysten/bcs';\nimport { blake2b } from '@noble/hashes/blake2b';\nimport { bytesToHex } from '@noble/hashes/utils';\n\nimport { bcs } from '../bcs/index.js';\nimport type { Signer } from '../cryptography/keypair.js';\nimport { bytesEqual, PublicKey } from '../cryptography/publickey.js';\nimport {\n\tSIGNATURE_FLAG_TO_SCHEME,\n\tSIGNATURE_SCHEME_TO_FLAG,\n} from '../cryptography/signature-scheme.js';\nimport type { SignatureFlag, SignatureScheme } from '../cryptography/signature-scheme.js';\nimport { parseSerializedSignature } from '../cryptography/signature.js';\nimport { normalizeSuiAddress } from '../utils/sui-types.js';\n// eslint-disable-next-line import/no-cycle\nimport { publicKeyFromRawBytes } from '../verify/index.js';\nimport type { ZkLoginCompatibleClient } from '../zklogin/publickey.js';\nimport { toZkLoginPublicIdentifier } from '../zklogin/publickey.js';\nimport { MultiSigSigner } from './signer.js';\n\ntype CompressedSignature =\n\t| { ED25519: number[] }\n\t| { Secp256k1: number[] }\n\t| { Secp256r1: number[] }\n\t| { ZkLogin: number[] }\n\t| { Passkey: number[] };\n\ntype PublicKeyEnum =\n\t| { ED25519: number[] }\n\t| { Secp256k1: number[] }\n\t| { Secp256r1: number[] }\n\t| { ZkLogin: number[] }\n\t| { Passkey: number[] };\n\ntype PubkeyEnumWeightPair = {\n\tpubKey: PublicKeyEnum;\n\tweight: number;\n};\n\ntype MultiSigPublicKeyStruct = {\n\tpk_map: PubkeyEnumWeightPair[];\n\tthreshold: number;\n};\n\nexport type MultiSigStruct = {\n\tsigs: CompressedSignature[];\n\tbitmap: number;\n\tmultisig_pk: MultiSigPublicKeyStruct;\n};\n\ntype ParsedPartialMultiSigSignature = {\n\tsignatureScheme: SignatureScheme;\n\tsignature: Uint8Array;\n\tpublicKey: PublicKey;\n\tweight: number;\n};\n\nexport const MAX_SIGNER_IN_MULTISIG = 10;\nexport const MIN_SIGNER_IN_MULTISIG = 1;\n/**\n * A MultiSig public key\n */\nexport class MultiSigPublicKey extends PublicKey {\n\tprivate rawBytes: Uint8Array<ArrayBuffer>;\n\tprivate multisigPublicKey: MultiSigPublicKeyStruct;\n\tprivate publicKeys: {\n\t\tweight: number;\n\t\tpublicKey: PublicKey;\n\t}[];\n\t/**\n\t * Create a new MultiSigPublicKey object\n\t */\n\tconstructor(\n\t\t/**\n\t\t * MultiSig public key as buffer or base-64 encoded string\n\t\t */\n\t\tvalue: string | Uint8Array | MultiSigPublicKeyStruct,\n\t\toptions: { client?: ZkLoginCompatibleClient } = {},\n\t) {\n\t\tsuper();\n\n\t\tif (typeof value === 'string') {\n\t\t\tthis.rawBytes = fromBase64(value);\n\n\t\t\tthis.multisigPublicKey = bcs.MultiSigPublicKey.parse(this.rawBytes);\n\t\t} else if (value instanceof Uint8Array) {\n\t\t\tthis.rawBytes = value as Uint8Array<ArrayBuffer>;\n\t\t\tthis.multisigPublicKey = bcs.MultiSigPublicKey.parse(this.rawBytes);\n\t\t} else {\n\t\t\tthis.multisigPublicKey = value;\n\t\t\tthis.rawBytes = bcs.MultiSigPublicKey.serialize(value).toBytes();\n\t\t}\n\t\tif (this.multisigPublicKey.threshold < 1) {\n\t\t\tthrow new Error('Invalid threshold');\n\t\t}\n\n\t\tconst seenPublicKeys = new Set<string>();\n\n\t\tthis.publicKeys = this.multisigPublicKey.pk_map.map(({ pubKey, weight }) => {\n\t\t\tconst [scheme, bytes] = Object.entries(pubKey).filter(([name]) => name !== '$kind')[0] as [\n\t\t\t\tSignatureScheme,\n\t\t\t\tnumber[],\n\t\t\t];\n\t\t\tconst publicKeyStr = Uint8Array.from(bytes).toString();\n\n\t\t\tif (seenPublicKeys.has(publicKeyStr)) {\n\t\t\t\tthrow new Error(`Multisig does not support duplicate public keys`);\n\t\t\t}\n\t\t\tseenPublicKeys.add(publicKeyStr);\n\n\t\t\tif (weight < 1) {\n\t\t\t\tthrow new Error(`Invalid weight`);\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tpublicKey: publicKeyFromRawBytes(scheme, Uint8Array.from(bytes), options),\n\t\t\t\tweight,\n\t\t\t};\n\t\t});\n\n\t\tconst totalWeight = this.publicKeys.reduce((sum, { weight }) => sum + weight, 0);\n\n\t\tif (this.multisigPublicKey.threshold > totalWeight) {\n\t\t\tthrow new Error(`Unreachable threshold`);\n\t\t}\n\n\t\tif (this.publicKeys.length > MAX_SIGNER_IN_MULTISIG) {\n\t\t\tthrow new Error(`Max number of signers in a multisig is ${MAX_SIGNER_IN_MULTISIG}`);\n\t\t}\n\n\t\tif (this.publicKeys.length < MIN_SIGNER_IN_MULTISIG) {\n\t\t\tthrow new Error(`Min number of signers in a multisig is ${MIN_SIGNER_IN_MULTISIG}`);\n\t\t}\n\t}\n\t/**\n\t * \tA static method to create a new MultiSig publickey instance from a set of public keys and their associated weights pairs and threshold.\n\t */\n\n\tstatic fromPublicKeys({\n\t\tthreshold,\n\t\tpublicKeys,\n\t}: {\n\t\tthreshold: number;\n\t\tpublicKeys: { publicKey: PublicKey; weight: number }[];\n\t}) {\n\t\treturn new MultiSigPublicKey({\n\t\t\tpk_map: publicKeys.map(({ publicKey, weight }) => {\n\t\t\t\tconst scheme = SIGNATURE_FLAG_TO_SCHEME[publicKey.flag() as SignatureFlag];\n\n\t\t\t\treturn {\n\t\t\t\t\tpubKey: { [scheme]: Array.from(publicKey.toRawBytes()) } as PublicKeyEnum,\n\t\t\t\t\tweight,\n\t\t\t\t};\n\t\t\t}),\n\t\t\tthreshold,\n\t\t});\n\t}\n\n\t/**\n\t * Checks if two MultiSig public keys are equal\n\t */\n\toverride equals(publicKey: MultiSigPublicKey): boolean {\n\t\treturn super.equals(publicKey);\n\t}\n\n\t/**\n\t * Return the byte array representation of the MultiSig public key\n\t */\n\ttoRawBytes(): Uint8Array<ArrayBuffer> {\n\t\treturn this.rawBytes;\n\t}\n\n\tgetPublicKeys() {\n\t\treturn this.publicKeys;\n\t}\n\n\tgetThreshold() {\n\t\treturn this.multisigPublicKey.threshold;\n\t}\n\n\tgetSigner(...signers: [signer: Signer]) {\n\t\treturn new MultiSigSigner(this, signers);\n\t}\n\n\t/**\n\t * Return the Sui address associated with this MultiSig public key\n\t */\n\toverride toSuiAddress(): string {\n\t\t// max length = 1 flag byte + (max pk size + max weight size (u8)) * max signer size + 2 threshold bytes (u16)\n\t\tconst maxLength = 1 + (64 + 1) * MAX_SIGNER_IN_MULTISIG + 2;\n\t\tconst tmp = new Uint8Array(maxLength);\n\t\ttmp.set([SIGNATURE_SCHEME_TO_FLAG['MultiSig']]);\n\n\t\ttmp.set(bcs.u16().serialize(this.multisigPublicKey.threshold).toBytes(), 1);\n\t\t// The initial value 3 ensures that following data will be after the flag byte and threshold bytes\n\t\tlet i = 3;\n\t\tfor (const { publicKey, weight } of this.publicKeys) {\n\t\t\tconst bytes = publicKey.toSuiBytes();\n\t\t\ttmp.set(bytes, i);\n\t\t\ti += bytes.length;\n\t\t\ttmp.set([weight], i++);\n\t\t}\n\t\treturn normalizeSuiAddress(bytesToHex(blake2b(tmp.slice(0, i), { dkLen: 32 })));\n\t}\n\n\t/**\n\t * Return the Sui address associated with this MultiSig public key\n\t */\n\tflag(): number {\n\t\treturn SIGNATURE_SCHEME_TO_FLAG['MultiSig'];\n\t}\n\n\t/**\n\t * Verifies that the signature is valid for for the provided message\n\t */\n\tasync verify(message: Uint8Array, multisigSignature: string): Promise<boolean> {\n\t\t// Multisig verification only supports serialized signature\n\t\tconst parsed = parseSerializedSignature(multisigSignature);\n\n\t\tif (parsed.signatureScheme !== 'MultiSig') {\n\t\t\tthrow new Error('Invalid signature scheme');\n\t\t}\n\n\t\tconst { multisig } = parsed;\n\n\t\tlet signatureWeight = 0;\n\n\t\tif (\n\t\t\t!bytesEqual(\n\t\t\t\tbcs.MultiSigPublicKey.serialize(this.multisigPublicKey).toBytes(),\n\t\t\t\tbcs.MultiSigPublicKey.serialize(multisig.multisig_pk).toBytes(),\n\t\t\t)\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\n\t\tfor (const { publicKey, weight, signature } of parsePartialSignatures(multisig)) {\n\t\t\tif (!(await publicKey.verify(message, signature))) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tsignatureWeight += weight;\n\t\t}\n\n\t\treturn signatureWeight >= this.multisigPublicKey.threshold;\n\t}\n\n\t/**\n\t * Combines multiple partial signatures into a single multisig, ensuring that each public key signs only once\n\t * and that all the public keys involved are known and valid, and then serializes multisig into the standard format\n\t */\n\tcombinePartialSignatures(signatures: string[]): string {\n\t\tif (signatures.length > MAX_SIGNER_IN_MULTISIG) {\n\t\t\tthrow new Error(`Max number of signatures in a multisig is ${MAX_SIGNER_IN_MULTISIG}`);\n\t\t}\n\n\t\tlet bitmap = 0;\n\t\tconst compressedSignatures: CompressedSignature[] = new Array(signatures.length);\n\n\t\tfor (let i = 0; i < signatures.length; i++) {\n\t\t\tconst parsed = parseSerializedSignature(signatures[i]);\n\t\t\tif (parsed.signatureScheme === 'MultiSig') {\n\t\t\t\tthrow new Error('MultiSig is not supported inside MultiSig');\n\t\t\t}\n\n\t\t\tlet publicKey;\n\t\t\tif (parsed.signatureScheme === 'ZkLogin') {\n\t\t\t\tpublicKey = toZkLoginPublicIdentifier(\n\t\t\t\t\tparsed.zkLogin?.addressSeed,\n\t\t\t\t\tparsed.zkLogin?.iss,\n\t\t\t\t).toRawBytes();\n\t\t\t} else {\n\t\t\t\tpublicKey = parsed.publicKey;\n\t\t\t}\n\n\t\t\tcompressedSignatures[i] = {\n\t\t\t\t[parsed.signatureScheme]: Array.from(parsed.signature.map((x: number) => Number(x))),\n\t\t\t} as CompressedSignature;\n\n\t\t\tlet publicKeyIndex;\n\t\t\tfor (let j = 0; j < this.publicKeys.length; j++) {\n\t\t\t\tif (bytesEqual(publicKey, this.publicKeys[j].publicKey.toRawBytes())) {\n\t\t\t\t\tif (bitmap & (1 << j)) {\n\t\t\t\t\t\tthrow new Error('Received multiple signatures from the same public key');\n\t\t\t\t\t}\n\n\t\t\t\t\tpublicKeyIndex = j;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (publicKeyIndex === undefined) {\n\t\t\t\tthrow new Error('Received signature from unknown public key');\n\t\t\t}\n\n\t\t\tbitmap |= 1 << publicKeyIndex;\n\t\t}\n\n\t\tconst multisig: MultiSigStruct = {\n\t\t\tsigs: compressedSignatures,\n\t\t\tbitmap,\n\t\t\tmultisig_pk: this.multisigPublicKey,\n\t\t};\n\t\tconst bytes = bcs.MultiSig.serialize(multisig, { maxSize: 8192 }).toBytes();\n\t\tconst tmp = new Uint8Array(bytes.length + 1);\n\t\ttmp.set([SIGNATURE_SCHEME_TO_FLAG['MultiSig']]);\n\t\ttmp.set(bytes, 1);\n\t\treturn toBase64(tmp);\n\t}\n}\n\n/**\n * Parse multisig structure into an array of individual signatures: signature scheme, the actual individual signature, public key and its weight.\n */\nexport function parsePartialSignatures(\n\tmultisig: MultiSigStruct,\n\toptions: { client?: ZkLoginCompatibleClient } = {},\n): ParsedPartialMultiSigSignature[] {\n\tconst res: ParsedPartialMultiSigSignature[] = new Array(multisig.sigs.length);\n\tfor (let i = 0; i < multisig.sigs.length; i++) {\n\t\tconst [signatureScheme, signature] = Object.entries(multisig.sigs[i]).filter(\n\t\t\t([name]) => name !== '$kind',\n\t\t)[0] as [SignatureScheme, number[]];\n\t\tconst pkIndex = asIndices(multisig.bitmap).at(i)!;\n\t\tconst pair = multisig.multisig_pk.pk_map[pkIndex];\n\t\tconst pkBytes = Uint8Array.from(Object.values(pair.pubKey)[0]);\n\n\t\tif (signatureScheme === 'MultiSig') {\n\t\t\tthrow new Error('MultiSig is not supported inside MultiSig');\n\t\t}\n\n\t\tconst publicKey = publicKeyFromRawBytes(signatureScheme, pkBytes, options);\n\n\t\tres[i] = {\n\t\t\tsignatureScheme,\n\t\t\tsignature: Uint8Array.from(signature),\n\t\t\tpublicKey: publicKey,\n\t\t\tweight: pair.weight,\n\t\t};\n\t}\n\treturn res;\n}\n\nfunction asIndices(bitmap: number): Uint8Array {\n\tif (bitmap < 0 || bitmap > 1024) {\n\t\tthrow new Error('Invalid bitmap');\n\t}\n\tconst res: number[] = [];\n\tfor (let i = 0; i < 10; i++) {\n\t\tif ((bitmap & (1 << i)) !== 0) {\n\t\t\tres.push(i);\n\t\t}\n\t}\n\treturn Uint8Array.from(res);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAqC;AACrC,qBAAwB;AACxB,mBAA2B;AAE3B,IAAAA,cAAoB;AAEpB,uBAAsC;AACtC,8BAGO;AAEP,uBAAyC;AACzC,uBAAoC;AAEpC,oBAAsC;AAEtC,IAAAC,oBAA0C;AAC1C,oBAA+B;AAuCxB,MAAM,yBAAyB;AAC/B,MAAM,yBAAyB;AAI/B,MAAM,0BAA0B,2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G,IAAI,SAAS,KAAK,QAAQ,KAAK;AAC9C,UAAM,CAAC,iBAAiB,SAAS,IAAI,OAAO,QAAQ,SAAS,KAAK,CAAC,CAAC,EAAE;AAAA,MACrE,CAAC,CAAC,IAAI,MAAM,SAAS;AAAA,IACtB,EAAE,CAAC;AACH,UAAM,UAAU,UAAU,SAAS,MAAM,EAAE,GAAG,CAAC;AAC/C,UAAM,OAAO,SAAS,YAAY,OAAO,OAAO;AAChD,UAAM,UAAU,WAAW,KAAK,OAAO,OAAO,KAAK,MAAM,EAAE,CAAC,CAAC;AAE7D,QAAI,oBAAoB,YAAY;AACnC,YAAM,IAAI,MAAM,2CAA2C;AAAA,IAC5D;AAEA,UAAM,gBAAY,qCAAsB,iBAAiB,SAAS,OAAO;AAEzE,QAAI,CAAC,IAAI;AAAA,MACR;AAAA,MACA,WAAW,WAAW,KAAK,SAAS;AAAA,MACpC;AAAA,MACA,QAAQ,KAAK;AAAA,IACd;AAAA,EACD;AACA,SAAO;AACR;AAEA,SAAS,UAAU,QAA4B;AAC9C,MAAI,SAAS,KAAK,SAAS,MAAM;AAChC,UAAM,IAAI,MAAM,gBAAgB;AAAA,EACjC;AACA,QAAM,MAAgB,CAAC;AACvB,WAAS,IAAI,GAAG,IAAI,IAAI,KAAK;AAC5B,SAAK,SAAU,KAAK,OAAQ,GAAG;AAC9B,UAAI,KAAK,CAAC;AAAA,IACX;AAAA,EACD;AACA,SAAO,WAAW,KAAK,GAAG;AAC3B;",
|
|
6
6
|
"names": ["import_bcs", "import_publickey"]
|
|
7
7
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { InferInput } from 'valibot';
|
|
2
|
-
import { Argument } from './data/internal.js';
|
|
3
|
-
import
|
|
2
|
+
import type { Argument, CallArg, Command } from './data/internal.js';
|
|
3
|
+
import { ArgumentSchema } from './data/internal.js';
|
|
4
4
|
import type { AsyncTransactionThunk, Transaction } from './Transaction.js';
|
|
5
|
-
export type TransactionArgument = InferInput<typeof
|
|
5
|
+
export type TransactionArgument = InferInput<typeof ArgumentSchema> | ((tx: Transaction) => InferInput<typeof ArgumentSchema>) | AsyncTransactionThunk;
|
|
6
6
|
export type TransactionInput = CallArg;
|
|
7
7
|
export declare enum UpgradePolicy {
|
|
8
8
|
COMPATIBLE = 0,
|
|
@@ -31,9 +31,9 @@ export declare const Commands: {
|
|
|
31
31
|
arguments?: Argument[];
|
|
32
32
|
typeArguments?: string[];
|
|
33
33
|
}): TransactionShape<"MoveCall">;
|
|
34
|
-
TransferObjects(objects: InferInput<typeof
|
|
35
|
-
SplitCoins(coin: InferInput<typeof
|
|
36
|
-
MergeCoins(destination: InferInput<typeof
|
|
34
|
+
TransferObjects(objects: InferInput<typeof ArgumentSchema>[], address: InferInput<typeof ArgumentSchema>): TransactionShape<"TransferObjects">;
|
|
35
|
+
SplitCoins(coin: InferInput<typeof ArgumentSchema>, amounts: InferInput<typeof ArgumentSchema>[]): TransactionShape<"SplitCoins">;
|
|
36
|
+
MergeCoins(destination: InferInput<typeof ArgumentSchema>, sources: InferInput<typeof ArgumentSchema>[]): TransactionShape<"MergeCoins">;
|
|
37
37
|
Publish({ modules, dependencies, }: {
|
|
38
38
|
modules: number[][] | string[];
|
|
39
39
|
dependencies: string[];
|
|
@@ -42,15 +42,15 @@ export declare const Commands: {
|
|
|
42
42
|
modules: number[][] | string[];
|
|
43
43
|
dependencies: string[];
|
|
44
44
|
package: string;
|
|
45
|
-
ticket: InferInput<typeof
|
|
45
|
+
ticket: InferInput<typeof ArgumentSchema>;
|
|
46
46
|
}): TransactionShape<"Upgrade">;
|
|
47
47
|
MakeMoveVec({ type, elements, }: {
|
|
48
48
|
type?: string;
|
|
49
|
-
elements: InferInput<typeof
|
|
49
|
+
elements: InferInput<typeof ArgumentSchema>[];
|
|
50
50
|
}): TransactionShape<"MakeMoveVec">;
|
|
51
51
|
Intent({ name, inputs, data, }: {
|
|
52
52
|
name: string;
|
|
53
|
-
inputs?: Record<string, InferInput<typeof
|
|
53
|
+
inputs?: Record<string, InferInput<typeof ArgumentSchema> | InferInput<typeof ArgumentSchema>[]>;
|
|
54
54
|
data?: Record<string, unknown>;
|
|
55
55
|
}): TransactionShape<"$Intent">;
|
|
56
56
|
};
|
|
@@ -50,8 +50,8 @@ const Commands = {
|
|
|
50
50
|
return {
|
|
51
51
|
$kind: "TransferObjects",
|
|
52
52
|
TransferObjects: {
|
|
53
|
-
objects: objects.map((o) => (0, import_valibot.parse)(import_internal.
|
|
54
|
-
address: (0, import_valibot.parse)(import_internal.
|
|
53
|
+
objects: objects.map((o) => (0, import_valibot.parse)(import_internal.ArgumentSchema, o)),
|
|
54
|
+
address: (0, import_valibot.parse)(import_internal.ArgumentSchema, address)
|
|
55
55
|
}
|
|
56
56
|
};
|
|
57
57
|
},
|
|
@@ -59,8 +59,8 @@ const Commands = {
|
|
|
59
59
|
return {
|
|
60
60
|
$kind: "SplitCoins",
|
|
61
61
|
SplitCoins: {
|
|
62
|
-
coin: (0, import_valibot.parse)(import_internal.
|
|
63
|
-
amounts: amounts.map((o) => (0, import_valibot.parse)(import_internal.
|
|
62
|
+
coin: (0, import_valibot.parse)(import_internal.ArgumentSchema, coin),
|
|
63
|
+
amounts: amounts.map((o) => (0, import_valibot.parse)(import_internal.ArgumentSchema, o))
|
|
64
64
|
}
|
|
65
65
|
};
|
|
66
66
|
},
|
|
@@ -68,8 +68,8 @@ const Commands = {
|
|
|
68
68
|
return {
|
|
69
69
|
$kind: "MergeCoins",
|
|
70
70
|
MergeCoins: {
|
|
71
|
-
destination: (0, import_valibot.parse)(import_internal.
|
|
72
|
-
sources: sources.map((o) => (0, import_valibot.parse)(import_internal.
|
|
71
|
+
destination: (0, import_valibot.parse)(import_internal.ArgumentSchema, destination),
|
|
72
|
+
sources: sources.map((o) => (0, import_valibot.parse)(import_internal.ArgumentSchema, o))
|
|
73
73
|
}
|
|
74
74
|
};
|
|
75
75
|
},
|
|
@@ -101,7 +101,7 @@ const Commands = {
|
|
|
101
101
|
),
|
|
102
102
|
dependencies: dependencies.map((dep) => (0, import_sui_types.normalizeSuiObjectId)(dep)),
|
|
103
103
|
package: packageId,
|
|
104
|
-
ticket: (0, import_valibot.parse)(import_internal.
|
|
104
|
+
ticket: (0, import_valibot.parse)(import_internal.ArgumentSchema, ticket)
|
|
105
105
|
}
|
|
106
106
|
};
|
|
107
107
|
},
|
|
@@ -113,7 +113,7 @@ const Commands = {
|
|
|
113
113
|
$kind: "MakeMoveVec",
|
|
114
114
|
MakeMoveVec: {
|
|
115
115
|
type: type ?? null,
|
|
116
|
-
elements: elements.map((o) => (0, import_valibot.parse)(import_internal.
|
|
116
|
+
elements: elements.map((o) => (0, import_valibot.parse)(import_internal.ArgumentSchema, o))
|
|
117
117
|
}
|
|
118
118
|
};
|
|
119
119
|
},
|
|
@@ -129,7 +129,7 @@ const Commands = {
|
|
|
129
129
|
inputs: Object.fromEntries(
|
|
130
130
|
Object.entries(inputs).map(([key, value]) => [
|
|
131
131
|
key,
|
|
132
|
-
Array.isArray(value) ? value.map((o) => (0, import_valibot.parse)(import_internal.
|
|
132
|
+
Array.isArray(value) ? value.map((o) => (0, import_valibot.parse)(import_internal.ArgumentSchema, o)) : (0, import_valibot.parse)(import_internal.ArgumentSchema, value)
|
|
133
133
|
])
|
|
134
134
|
),
|
|
135
135
|
data
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/transactions/Commands.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { toBase64 } from '@mysten/bcs';\nimport type { InferInput } from 'valibot';\nimport { parse } from 'valibot';\n\nimport { normalizeSuiObjectId } from '../utils/sui-types.js';\nimport { Argument } from './data/internal.js';\nimport
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAyB;AAEzB,qBAAsB;AAEtB,uBAAqC;
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { toBase64 } from '@mysten/bcs';\nimport type { InferInput } from 'valibot';\nimport { parse } from 'valibot';\n\nimport { normalizeSuiObjectId } from '../utils/sui-types.js';\nimport type { Argument, CallArg, Command } from './data/internal.js';\nimport { ArgumentSchema } from './data/internal.js';\nimport type { AsyncTransactionThunk, Transaction } from './Transaction.js';\n\nexport type TransactionArgument =\n\t| InferInput<typeof ArgumentSchema>\n\t| ((tx: Transaction) => InferInput<typeof ArgumentSchema>)\n\t| AsyncTransactionThunk;\nexport type TransactionInput = CallArg;\n\n// Keep in sync with constants in\n// crates/sui-framework/packages/sui-framework/sources/package.move\nexport enum UpgradePolicy {\n\tCOMPATIBLE = 0,\n\tADDITIVE = 128,\n\tDEP_ONLY = 192,\n}\n\ntype TransactionShape<T extends Command['$kind']> = { $kind: T } & {\n\t[K in T]: Extract<Command, { [K in T]: any }>[T];\n};\n\n/**\n * Simple helpers used to construct transactions:\n */\nexport const Commands = {\n\tMoveCall(\n\t\tinput:\n\t\t\t| {\n\t\t\t\t\tpackage: string;\n\t\t\t\t\tmodule: string;\n\t\t\t\t\tfunction: string;\n\t\t\t\t\targuments?: Argument[];\n\t\t\t\t\ttypeArguments?: string[];\n\t\t\t }\n\t\t\t| {\n\t\t\t\t\ttarget: string;\n\t\t\t\t\targuments?: Argument[];\n\t\t\t\t\ttypeArguments?: string[];\n\t\t\t },\n\t): TransactionShape<'MoveCall'> {\n\t\tconst [pkg, mod = '', fn = ''] =\n\t\t\t'target' in input ? input.target.split('::') : [input.package, input.module, input.function];\n\n\t\treturn {\n\t\t\t$kind: 'MoveCall',\n\t\t\tMoveCall: {\n\t\t\t\tpackage: pkg,\n\t\t\t\tmodule: mod,\n\t\t\t\tfunction: fn,\n\t\t\t\ttypeArguments: input.typeArguments ?? [],\n\t\t\t\targuments: input.arguments ?? [],\n\t\t\t},\n\t\t};\n\t},\n\n\tTransferObjects(\n\t\tobjects: InferInput<typeof ArgumentSchema>[],\n\t\taddress: InferInput<typeof ArgumentSchema>,\n\t): TransactionShape<'TransferObjects'> {\n\t\treturn {\n\t\t\t$kind: 'TransferObjects',\n\t\t\tTransferObjects: {\n\t\t\t\tobjects: objects.map((o) => parse(ArgumentSchema, o)),\n\t\t\t\taddress: parse(ArgumentSchema, address),\n\t\t\t},\n\t\t};\n\t},\n\tSplitCoins(\n\t\tcoin: InferInput<typeof ArgumentSchema>,\n\t\tamounts: InferInput<typeof ArgumentSchema>[],\n\t): TransactionShape<'SplitCoins'> {\n\t\treturn {\n\t\t\t$kind: 'SplitCoins',\n\t\t\tSplitCoins: {\n\t\t\t\tcoin: parse(ArgumentSchema, coin),\n\t\t\t\tamounts: amounts.map((o) => parse(ArgumentSchema, o)),\n\t\t\t},\n\t\t};\n\t},\n\tMergeCoins(\n\t\tdestination: InferInput<typeof ArgumentSchema>,\n\t\tsources: InferInput<typeof ArgumentSchema>[],\n\t): TransactionShape<'MergeCoins'> {\n\t\treturn {\n\t\t\t$kind: 'MergeCoins',\n\t\t\tMergeCoins: {\n\t\t\t\tdestination: parse(ArgumentSchema, destination),\n\t\t\t\tsources: sources.map((o) => parse(ArgumentSchema, o)),\n\t\t\t},\n\t\t};\n\t},\n\tPublish({\n\t\tmodules,\n\t\tdependencies,\n\t}: {\n\t\tmodules: number[][] | string[];\n\t\tdependencies: string[];\n\t}): TransactionShape<'Publish'> {\n\t\treturn {\n\t\t\t$kind: 'Publish',\n\t\t\tPublish: {\n\t\t\t\tmodules: modules.map((module) =>\n\t\t\t\t\ttypeof module === 'string' ? module : toBase64(new Uint8Array(module)),\n\t\t\t\t),\n\t\t\t\tdependencies: dependencies.map((dep) => normalizeSuiObjectId(dep)),\n\t\t\t},\n\t\t};\n\t},\n\tUpgrade({\n\t\tmodules,\n\t\tdependencies,\n\t\tpackage: packageId,\n\t\tticket,\n\t}: {\n\t\tmodules: number[][] | string[];\n\t\tdependencies: string[];\n\t\tpackage: string;\n\t\tticket: InferInput<typeof ArgumentSchema>;\n\t}): TransactionShape<'Upgrade'> {\n\t\treturn {\n\t\t\t$kind: 'Upgrade',\n\t\t\tUpgrade: {\n\t\t\t\tmodules: modules.map((module) =>\n\t\t\t\t\ttypeof module === 'string' ? module : toBase64(new Uint8Array(module)),\n\t\t\t\t),\n\t\t\t\tdependencies: dependencies.map((dep) => normalizeSuiObjectId(dep)),\n\t\t\t\tpackage: packageId,\n\t\t\t\tticket: parse(ArgumentSchema, ticket),\n\t\t\t},\n\t\t};\n\t},\n\tMakeMoveVec({\n\t\ttype,\n\t\telements,\n\t}: {\n\t\ttype?: string;\n\t\telements: InferInput<typeof ArgumentSchema>[];\n\t}): TransactionShape<'MakeMoveVec'> {\n\t\treturn {\n\t\t\t$kind: 'MakeMoveVec',\n\t\t\tMakeMoveVec: {\n\t\t\t\ttype: type ?? null,\n\t\t\t\telements: elements.map((o) => parse(ArgumentSchema, o)),\n\t\t\t},\n\t\t};\n\t},\n\tIntent({\n\t\tname,\n\t\tinputs = {},\n\t\tdata = {},\n\t}: {\n\t\tname: string;\n\t\tinputs?: Record<\n\t\t\tstring,\n\t\t\tInferInput<typeof ArgumentSchema> | InferInput<typeof ArgumentSchema>[]\n\t\t>;\n\t\tdata?: Record<string, unknown>;\n\t}): TransactionShape<'$Intent'> {\n\t\treturn {\n\t\t\t$kind: '$Intent',\n\t\t\t$Intent: {\n\t\t\t\tname,\n\t\t\t\tinputs: Object.fromEntries(\n\t\t\t\t\tObject.entries(inputs).map(([key, value]) => [\n\t\t\t\t\t\tkey,\n\t\t\t\t\t\tArray.isArray(value)\n\t\t\t\t\t\t\t? value.map((o) => parse(ArgumentSchema, o))\n\t\t\t\t\t\t\t: parse(ArgumentSchema, value),\n\t\t\t\t\t]),\n\t\t\t\t),\n\t\t\t\tdata,\n\t\t\t},\n\t\t};\n\t},\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;A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AAC,CAAC,KAAK,KAAK,MAAM;AAAA,YAC5C;AAAA,YACA,MAAM,QAAQ,KAAK,IAChB,MAAM,IAAI,CAAC,UAAM,sBAAM,gCAAgB,CAAC,CAAC,QACzC,sBAAM,gCAAgB,KAAK;AAAA,UAC/B,CAAC;AAAA,QACF;AAAA,QACA;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACD;",
|
|
6
6
|
"names": ["UpgradePolicy", "module"]
|
|
7
7
|
}
|
|
@@ -3,16 +3,16 @@ import type { InferInput } from 'valibot';
|
|
|
3
3
|
import type { SuiClient } from '../client/index.js';
|
|
4
4
|
import type { SignatureWithBytes, Signer } from '../cryptography/index.js';
|
|
5
5
|
import type { TransactionArgument } from './Commands.js';
|
|
6
|
-
import type { CallArg, Command } from './data/internal.js';
|
|
7
|
-
import {
|
|
6
|
+
import type { CallArg, Command, Argument, ObjectRef } from './data/internal.js';
|
|
7
|
+
import { ArgumentSchema, TransactionExpiration } from './data/internal.js';
|
|
8
8
|
import { Inputs } from './Inputs.js';
|
|
9
9
|
import type { BuildTransactionOptions, SerializeTransactionOptions, TransactionPlugin } from './resolve.js';
|
|
10
10
|
import { createObjectMethods } from './object.js';
|
|
11
11
|
import { createPure } from './pure.js';
|
|
12
|
-
export type TransactionObjectArgument = Exclude<InferInput<typeof
|
|
12
|
+
export type TransactionObjectArgument = Exclude<InferInput<typeof ArgumentSchema>, {
|
|
13
13
|
Input: unknown;
|
|
14
14
|
type?: 'pure';
|
|
15
|
-
}> | ((tx: Transaction) => Exclude<InferInput<typeof
|
|
15
|
+
}> | ((tx: Transaction) => Exclude<InferInput<typeof ArgumentSchema>, {
|
|
16
16
|
Input: unknown;
|
|
17
17
|
type?: 'pure';
|
|
18
18
|
}>) | AsyncTransactionThunk<TransactionResultArgument>;
|
|
@@ -344,6 +344,7 @@ export declare class Transaction {
|
|
|
344
344
|
version?: string | number | null | undefined;
|
|
345
345
|
digest?: string | null | undefined;
|
|
346
346
|
initialSharedVersion?: string | number | null | undefined;
|
|
347
|
+
mutable?: boolean | null | undefined;
|
|
347
348
|
};
|
|
348
349
|
}, "Pure" | "Object" | "UnresolvedPure" | "UnresolvedObject">[];
|
|
349
350
|
commands: import("@mysten/bcs").EnumOutputShapeWithKeys<{
|
|
@@ -696,7 +697,7 @@ export declare class Transaction {
|
|
|
696
697
|
*/
|
|
697
698
|
isFullyResolved(): boolean;
|
|
698
699
|
/** Build the transaction to BCS bytes. */
|
|
699
|
-
build(options?: BuildTransactionOptions): Promise<Uint8Array
|
|
700
|
+
build(options?: BuildTransactionOptions): Promise<Uint8Array<ArrayBuffer>>;
|
|
700
701
|
/** Derive transaction digest */
|
|
701
702
|
getDigest(options?: {
|
|
702
703
|
client?: SuiClient;
|
|
@@ -128,7 +128,7 @@ const _Transaction = class _Transaction {
|
|
|
128
128
|
if (typeof value === "function") {
|
|
129
129
|
return this.object(this.add(value));
|
|
130
130
|
}
|
|
131
|
-
if (typeof value === "object" && (0, import_valibot.is)(import_internal.
|
|
131
|
+
if (typeof value === "object" && (0, import_valibot.is)(import_internal.ArgumentSchema, value)) {
|
|
132
132
|
return value;
|
|
133
133
|
}
|
|
134
134
|
const id = (0, import_utils.getIdFromCallArg)(value);
|
|
@@ -243,7 +243,7 @@ const _Transaction = class _Transaction {
|
|
|
243
243
|
__privateGet(this, _data).gasConfig.owner = owner;
|
|
244
244
|
}
|
|
245
245
|
setGasPayment(payments) {
|
|
246
|
-
__privateGet(this, _data).gasConfig.payment = payments.map((payment) => (0, import_valibot.parse)(import_internal.
|
|
246
|
+
__privateGet(this, _data).gasConfig.payment = payments.map((payment) => (0, import_valibot.parse)(import_internal.ObjectRefSchema, payment));
|
|
247
247
|
}
|
|
248
248
|
/** @deprecated Use `getData()` instead. */
|
|
249
249
|
get blockData() {
|
|
@@ -421,7 +421,7 @@ const _Transaction = class _Transaction {
|
|
|
421
421
|
const fullyResolved = this.isFullyResolved();
|
|
422
422
|
return JSON.stringify(
|
|
423
423
|
(0, import_valibot.parse)(
|
|
424
|
-
import_v2.
|
|
424
|
+
import_v2.SerializedTransactionDataV2Schema,
|
|
425
425
|
fullyResolved ? {
|
|
426
426
|
...__privateGet(this, _data).snapshot(),
|
|
427
427
|
digest: __privateGet(this, _data).getDigest()
|
|
@@ -564,9 +564,9 @@ resolveArgument_fn = function(arg) {
|
|
|
564
564
|
if (typeof resolved === "function") {
|
|
565
565
|
return __privateMethod(this, _Transaction_instances, resolveArgument_fn).call(this, resolved);
|
|
566
566
|
}
|
|
567
|
-
return (0, import_valibot.parse)(import_internal.
|
|
567
|
+
return (0, import_valibot.parse)(import_internal.ArgumentSchema, resolved);
|
|
568
568
|
}
|
|
569
|
-
return (0, import_valibot.parse)(import_internal.
|
|
569
|
+
return (0, import_valibot.parse)(import_internal.ArgumentSchema, arg);
|
|
570
570
|
};
|
|
571
571
|
prepareBuild_fn = async function(options) {
|
|
572
572
|
if (!options.onlyTransactionKind && !__privateGet(this, _data).sender) {
|