@mysten/sui 1.28.2 → 1.29.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 +8 -0
- package/README.md +5 -4
- package/dist/cjs/client/client.d.ts +2 -1
- package/dist/cjs/client/client.js +7 -0
- package/dist/cjs/client/client.js.map +2 -2
- package/dist/cjs/experimental/core.d.ts +1 -1
- package/dist/cjs/experimental/core.js +3 -2
- package/dist/cjs/experimental/core.js.map +2 -2
- package/dist/cjs/experimental/transports/graphql.d.ts +26 -0
- package/dist/cjs/experimental/transports/graphql.js +310 -0
- package/dist/cjs/experimental/transports/graphql.js.map +7 -0
- package/dist/cjs/experimental/transports/jsonRPC.d.ts +5 -3
- package/dist/cjs/experimental/transports/jsonRPC.js +53 -105
- package/dist/cjs/experimental/transports/jsonRPC.js.map +3 -3
- package/dist/cjs/experimental/transports/utils.d.ts +6 -0
- package/dist/cjs/experimental/transports/utils.js +102 -0
- package/dist/cjs/experimental/transports/utils.js.map +7 -0
- package/dist/cjs/experimental/types.d.ts +21 -6
- package/dist/cjs/experimental/types.js.map +1 -1
- package/dist/cjs/faucet/faucet.d.ts +1 -1
- package/dist/cjs/faucet/faucet.js.map +1 -1
- package/dist/cjs/graphql/client.d.ts +10 -3
- package/dist/cjs/graphql/client.js +12 -4
- package/dist/cjs/graphql/client.js.map +3 -3
- package/dist/cjs/graphql/generated/queries.d.ts +5653 -0
- package/dist/cjs/graphql/generated/queries.js +722 -0
- package/dist/cjs/graphql/generated/queries.js.map +7 -0
- package/dist/cjs/multisig/publickey.d.ts +3 -3
- package/dist/cjs/multisig/publickey.js.map +2 -2
- package/dist/cjs/transactions/Commands.d.ts +2 -2
- package/dist/cjs/transactions/Commands.js.map +2 -2
- package/dist/cjs/transactions/Transaction.d.ts +10 -2
- package/dist/cjs/transactions/Transaction.js +165 -21
- package/dist/cjs/transactions/Transaction.js.map +3 -3
- package/dist/cjs/transactions/TransactionData.d.ts +4 -2
- package/dist/cjs/transactions/TransactionData.js +72 -41
- package/dist/cjs/transactions/TransactionData.js.map +2 -2
- package/dist/cjs/transactions/intents/CoinWithBalance.js.map +1 -1
- package/dist/cjs/verify/verify.d.ts +5 -5
- package/dist/cjs/verify/verify.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 +9 -3
- package/dist/cjs/zklogin/publickey.js +8 -30
- package/dist/cjs/zklogin/publickey.js.map +2 -2
- package/dist/esm/client/client.d.ts +2 -1
- package/dist/esm/client/client.js +7 -0
- package/dist/esm/client/client.js.map +2 -2
- package/dist/esm/experimental/core.d.ts +1 -1
- package/dist/esm/experimental/core.js +3 -2
- package/dist/esm/experimental/core.js.map +2 -2
- package/dist/esm/experimental/transports/graphql.d.ts +26 -0
- package/dist/esm/experimental/transports/graphql.js +303 -0
- package/dist/esm/experimental/transports/graphql.js.map +7 -0
- package/dist/esm/experimental/transports/jsonRPC.d.ts +5 -3
- package/dist/esm/experimental/transports/jsonRPC.js +52 -104
- package/dist/esm/experimental/transports/jsonRPC.js.map +2 -2
- package/dist/esm/experimental/transports/utils.d.ts +6 -0
- package/dist/esm/experimental/transports/utils.js +82 -0
- package/dist/esm/experimental/transports/utils.js.map +7 -0
- package/dist/esm/experimental/types.d.ts +21 -6
- package/dist/esm/faucet/faucet.d.ts +1 -1
- package/dist/esm/faucet/faucet.js.map +1 -1
- package/dist/esm/graphql/client.d.ts +10 -3
- package/dist/esm/graphql/client.js +12 -4
- package/dist/esm/graphql/client.js.map +2 -2
- package/dist/esm/graphql/generated/queries.d.ts +5653 -0
- package/dist/esm/graphql/generated/queries.js +702 -0
- package/dist/esm/graphql/generated/queries.js.map +7 -0
- package/dist/esm/multisig/publickey.d.ts +3 -3
- package/dist/esm/multisig/publickey.js.map +2 -2
- package/dist/esm/transactions/Commands.d.ts +2 -2
- package/dist/esm/transactions/Commands.js.map +2 -2
- package/dist/esm/transactions/Transaction.d.ts +10 -2
- package/dist/esm/transactions/Transaction.js +165 -21
- package/dist/esm/transactions/Transaction.js.map +3 -3
- package/dist/esm/transactions/TransactionData.d.ts +4 -2
- package/dist/esm/transactions/TransactionData.js +72 -41
- package/dist/esm/transactions/TransactionData.js.map +2 -2
- package/dist/esm/transactions/intents/CoinWithBalance.js.map +1 -1
- package/dist/esm/verify/verify.d.ts +5 -5
- package/dist/esm/verify/verify.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 +9 -3
- package/dist/esm/zklogin/publickey.js +8 -30
- 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 +4 -1
- package/src/client/client.ts +10 -0
- package/src/experimental/core.ts +5 -2
- package/src/experimental/transports/graphql.ts +421 -0
- package/src/experimental/transports/jsonRPC.ts +47 -132
- package/src/experimental/transports/utils.ts +117 -0
- package/src/experimental/types.ts +30 -7
- package/src/faucet/faucet.ts +1 -1
- package/src/graphql/client.ts +21 -3
- package/src/graphql/generated/queries.ts +6061 -0
- package/src/graphql/queries/getAllBalances.graphql +20 -0
- package/src/graphql/queries/getBalance.graphql +14 -0
- package/src/graphql/queries/getCoins.graphql +29 -0
- package/src/graphql/queries/getDynamicFields.graphql +36 -0
- package/src/graphql/queries/getReferenceGasPrice.graphql +8 -0
- package/src/graphql/queries/objects.graphql +89 -0
- package/src/graphql/queries/transactions.graphql +80 -0
- package/src/graphql/queries/verifyZkLoginSignature.graphql +16 -0
- package/src/multisig/publickey.ts +3 -3
- package/src/transactions/Commands.ts +3 -2
- package/src/transactions/Transaction.ts +215 -12
- package/src/transactions/TransactionData.ts +86 -46
- package/src/transactions/intents/CoinWithBalance.ts +1 -1
- package/src/verify/verify.ts +6 -6
- package/src/version.ts +2 -2
- package/src/zklogin/publickey.ts +23 -39
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Signer } from '../cryptography/keypair.js';
|
|
2
2
|
import { PublicKey } from '../cryptography/publickey.js';
|
|
3
3
|
import type { SignatureScheme } from '../cryptography/signature-scheme.js';
|
|
4
|
-
import type {
|
|
4
|
+
import type { ZkLoginCompatibleClient } from '../zklogin/publickey.js';
|
|
5
5
|
import { MultiSigSigner } from './signer.js';
|
|
6
6
|
type CompressedSignature = {
|
|
7
7
|
ED25519: number[];
|
|
@@ -57,7 +57,7 @@ export declare class MultiSigPublicKey extends PublicKey {
|
|
|
57
57
|
* MultiSig public key as buffer or base-64 encoded string
|
|
58
58
|
*/
|
|
59
59
|
value: string | Uint8Array | MultiSigPublicKeyStruct, options?: {
|
|
60
|
-
client?:
|
|
60
|
+
client?: ZkLoginCompatibleClient;
|
|
61
61
|
});
|
|
62
62
|
/**
|
|
63
63
|
* A static method to create a new MultiSig publickey instance from a set of public keys and their associated weights pairs and threshold.
|
|
@@ -105,6 +105,6 @@ export declare class MultiSigPublicKey extends PublicKey {
|
|
|
105
105
|
* Parse multisig structure into an array of individual signatures: signature scheme, the actual individual signature, public key and its weight.
|
|
106
106
|
*/
|
|
107
107
|
export declare function parsePartialSignatures(multisig: MultiSigStruct, options?: {
|
|
108
|
-
client?:
|
|
108
|
+
client?: ZkLoginCompatibleClient;
|
|
109
109
|
}): ParsedPartialMultiSigSignature[];
|
|
110
110
|
export {};
|
|
@@ -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 type { SuiGraphQLClient } from '../graphql/client.js';\nimport { normalizeSuiAddress } from '../utils/sui-types.js';\n// eslint-disable-next-line import/no-cycle\nimport { publicKeyFromRawBytes } from '../verify/index.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\ntype PublicKeyEnum =\n\t| { ED25519: number[] }\n\t| { Secp256k1: number[] }\n\t| { Secp256r1: number[] }\n\t| { ZkLogin: 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?: SuiGraphQLClient } = {},\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?: SuiGraphQLClient } = {},\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;
|
|
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\ntype PublicKeyEnum =\n\t| { ED25519: number[] }\n\t| { Secp256k1: number[] }\n\t| { Secp256r1: number[] }\n\t| { ZkLogin: 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;AAqCxB,MAAM,yBAAyB;AAC/B,MAAM,yBAAyB;AAI/B,MAAM,0BAA0B,2BAAU;AAAA;AAAA;AAAA;AAAA,EAUhD,YAIC,OACA,UAAgD,CAAC,GAChD;AACD,UAAM;AAEN,QAAI,OAAO,UAAU,UAAU;AAC9B,WAAK,eAAW,uBAAW,KAAK;AAEhC,WAAK,oBAAoB,gBAAI,kBAAkB,MAAM,KAAK,QAAQ;AAAA,IACnE,WAAW,iBAAiB,YAAY;AACvC,WAAK,WAAW;AAChB,WAAK,oBAAoB,gBAAI,kBAAkB,MAAM,KAAK,QAAQ;AAAA,IACnE,OAAO;AACN,WAAK,oBAAoB;AACzB,WAAK,WAAW,gBAAI,kBAAkB,UAAU,KAAK,EAAE,QAAQ;AAAA,IAChE;AACA,QAAI,KAAK,kBAAkB,YAAY,GAAG;AACzC,YAAM,IAAI,MAAM,mBAAmB;AAAA,IACpC;AAEA,UAAM,iBAAiB,oBAAI,IAAY;AAEvC,SAAK,aAAa,KAAK,kBAAkB,OAAO,IAAI,CAAC,EA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AAA,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
2
|
import { Argument } from './data/internal.js';
|
|
3
3
|
import type { CallArg, Command } from './data/internal.js';
|
|
4
|
-
import type { Transaction } from './Transaction.js';
|
|
5
|
-
export type TransactionArgument = InferInput<typeof Argument> | ((tx: Transaction) => InferInput<typeof Argument>);
|
|
4
|
+
import type { AsyncTransactionThunk, Transaction } from './Transaction.js';
|
|
5
|
+
export type TransactionArgument = InferInput<typeof Argument> | ((tx: Transaction) => InferInput<typeof Argument>) | AsyncTransactionThunk;
|
|
6
6
|
export type TransactionInput = CallArg;
|
|
7
7
|
export declare enum UpgradePolicy {
|
|
8
8
|
COMPATIBLE = 0,
|
|
@@ -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 type { CallArg, Command } from './data/internal.js';\nimport type { Transaction } from './Transaction.js';\n\nexport type TransactionArgument =\n\t| InferInput<typeof Argument>\n\t| ((tx: Transaction) => InferInput<typeof Argument>);\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 Argument>[],\n\t\taddress: InferInput<typeof Argument>,\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(Argument, o)),\n\t\t\t\taddress: parse(Argument, address),\n\t\t\t},\n\t\t};\n\t},\n\tSplitCoins(\n\t\tcoin: InferInput<typeof Argument>,\n\t\tamounts: InferInput<typeof Argument>[],\n\t): TransactionShape<'SplitCoins'> {\n\t\treturn {\n\t\t\t$kind: 'SplitCoins',\n\t\t\tSplitCoins: {\n\t\t\t\tcoin: parse(Argument, coin),\n\t\t\t\tamounts: amounts.map((o) => parse(Argument, o)),\n\t\t\t},\n\t\t};\n\t},\n\tMergeCoins(\n\t\tdestination: InferInput<typeof Argument>,\n\t\tsources: InferInput<typeof Argument>[],\n\t): TransactionShape<'MergeCoins'> {\n\t\treturn {\n\t\t\t$kind: 'MergeCoins',\n\t\t\tMergeCoins: {\n\t\t\t\tdestination: parse(Argument, destination),\n\t\t\t\tsources: sources.map((o) => parse(Argument, 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 Argument>;\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(Argument, 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 Argument>[];\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(Argument, 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<string, InferInput<typeof Argument> | InferInput<typeof Argument>[]>;\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) ? value.map((o) => parse(Argument, o)) : parse(Argument, 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;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAyB;AAEzB,qBAAsB;AAEtB,uBAAqC;AACrC,sBAAyB;
|
|
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 type { CallArg, Command } from './data/internal.js';\nimport type { AsyncTransactionThunk, Transaction } from './Transaction.js';\n\nexport type TransactionArgument =\n\t| InferInput<typeof Argument>\n\t| ((tx: Transaction) => InferInput<typeof Argument>)\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 Argument>[],\n\t\taddress: InferInput<typeof Argument>,\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(Argument, o)),\n\t\t\t\taddress: parse(Argument, address),\n\t\t\t},\n\t\t};\n\t},\n\tSplitCoins(\n\t\tcoin: InferInput<typeof Argument>,\n\t\tamounts: InferInput<typeof Argument>[],\n\t): TransactionShape<'SplitCoins'> {\n\t\treturn {\n\t\t\t$kind: 'SplitCoins',\n\t\t\tSplitCoins: {\n\t\t\t\tcoin: parse(Argument, coin),\n\t\t\t\tamounts: amounts.map((o) => parse(Argument, o)),\n\t\t\t},\n\t\t};\n\t},\n\tMergeCoins(\n\t\tdestination: InferInput<typeof Argument>,\n\t\tsources: InferInput<typeof Argument>[],\n\t): TransactionShape<'MergeCoins'> {\n\t\treturn {\n\t\t\t$kind: 'MergeCoins',\n\t\t\tMergeCoins: {\n\t\t\t\tdestination: parse(Argument, destination),\n\t\t\t\tsources: sources.map((o) => parse(Argument, 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 Argument>;\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(Argument, 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 Argument>[];\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(Argument, 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<string, InferInput<typeof Argument> | InferInput<typeof Argument>[]>;\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) ? value.map((o) => parse(Argument, o)) : parse(Argument, 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;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAyB;AAEzB,qBAAsB;AAEtB,uBAAqC;AACrC,sBAAyB;AAYlB,IAAK,gBAAL,kBAAKA,mBAAL;AACN,EAAAA,8BAAA,gBAAa,KAAb;AACA,EAAAA,8BAAA,cAAW,OAAX;AACA,EAAAA,8BAAA,cAAW,OAAX;AAHW,SAAAA;AAAA,GAAA;AAaL,MAAM,WAAW;AAAA,EACvB,SACC,OAa+B;AAC/B,UAAM,CAAC,KAAK,MAAM,IAAI,KAAK,EAAE,IAC5B,YAAY,QAAQ,MAAM,OAAO,MAAM,IAAI,IAAI,CAAC,MAAM,SAAS,MAAM,QAAQ,MAAM,QAAQ;AAE5F,WAAO;AAAA,MACN,OAAO;AAAA,MACP,UAAU;AAAA,QACT,SAAS;AAAA,QACT,QAAQ;AAAA,QACR,UAAU;AAAA,QACV,eAAe,MAAM,iBAAiB,CAAC;AAAA,QACvC,WAAW,MAAM,aAAa,CAAC;AAAA,MAChC;AAAA,IACD;AAAA,EACD;AAAA,EAEA,gBACC,SACA,SACsC;AACtC,WAAO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,GAAG,CAAC;AAAA,QACjE,SAAS;AAAA,QACT,YAAQ,sBAAM,0BAAU,MAAM;AAAA,MAC/B;AAAA,IACD;AAAA,EACD;AAAA,EACA,YAAY;AAAA,IACX;AAAA,IACA;AAAA,EACD,GAGoC;AACnC,WAAO;AAAA,MACN,OAAO;AAAA,MACP,aAAa;AAAA,QACZ,MAAM,QAAQ;AAAA,QACd,UAAU,SAAS,IAAI,CAAC,UAAM,sBAAM,0BAAU,CAAC,CAAC;AAAA,MACjD;AAAA,IACD;AAAA,EACD;AAAA,EACA,OAAO;AAAA,IACN;AAAA,IACA,SAAS,CAAC;AAAA,IACV,OAAO,CAAC;AAAA,EACT,GAIgC;AAC/B,WAAO;AAAA,MACN,OAAO;AAAA,MACP,SAAS;AAAA,QACR;AAAA,QACA,QAAQ,OAAO;AAAA,UACd,OAAO,QAAQ,MAAM,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AAAA,YAC5C;AAAA,YACA,MAAM,QAAQ,KAAK,IAAI,MAAM,IAAI,CAAC,UAAM,sBAAM,0BAAU,CAAC,CAAC,QAAI,sBAAM,0BAAU,KAAK;AAAA,UACpF,CAAC;AAAA,QACF;AAAA,QACA;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACD;",
|
|
6
6
|
"names": ["UpgradePolicy", "module"]
|
|
7
7
|
}
|
|
@@ -15,12 +15,18 @@ export type TransactionObjectArgument = Exclude<InferInput<typeof Argument>, {
|
|
|
15
15
|
}> | ((tx: Transaction) => Exclude<InferInput<typeof Argument>, {
|
|
16
16
|
Input: unknown;
|
|
17
17
|
type?: 'pure';
|
|
18
|
-
}>)
|
|
18
|
+
}>) | AsyncTransactionThunk<TransactionResultArgument>;
|
|
19
19
|
export type TransactionResult = Extract<Argument, {
|
|
20
20
|
Result: unknown;
|
|
21
21
|
}> & Extract<Argument, {
|
|
22
22
|
NestedResult: unknown;
|
|
23
23
|
}>[];
|
|
24
|
+
export type TransactionResultArgument = Extract<Argument, {
|
|
25
|
+
Result: unknown;
|
|
26
|
+
}> | readonly Extract<Argument, {
|
|
27
|
+
NestedResult: unknown;
|
|
28
|
+
}>[];
|
|
29
|
+
export type AsyncTransactionThunk<T extends TransactionResultArgument | void = TransactionResultArgument | void> = (tx: Transaction) => Promise<T | void>;
|
|
24
30
|
declare const TRANSACTION_BRAND: never;
|
|
25
31
|
interface SignOptions extends BuildTransactionOptions {
|
|
26
32
|
signer: Signer;
|
|
@@ -634,7 +640,9 @@ export declare class Transaction {
|
|
|
634
640
|
type?: "object";
|
|
635
641
|
};
|
|
636
642
|
/** Add a transaction to the transaction */
|
|
637
|
-
add<T
|
|
643
|
+
add<T extends Command>(command: T): TransactionResult;
|
|
644
|
+
add<T extends void | TransactionResultArgument | TransactionArgument | Command>(thunk: (tx: Transaction) => T): T;
|
|
645
|
+
add<T extends TransactionResultArgument | void>(asyncTransactionThunk: AsyncTransactionThunk<T>): T;
|
|
638
646
|
splitCoins<const Amounts extends (TransactionArgument | SerializedBcs<any> | number | string | bigint)[]>(coin: TransactionObjectArgument | string, amounts: Amounts): Extract<Argument, {
|
|
639
647
|
Result: unknown;
|
|
640
648
|
}> & { [K in keyof Amounts]: Extract<Argument, {
|
|
@@ -43,7 +43,7 @@ var import_object = require("./object.js");
|
|
|
43
43
|
var import_pure = require("./pure.js");
|
|
44
44
|
var import_TransactionData = require("./TransactionData.js");
|
|
45
45
|
var import_utils = require("./utils.js");
|
|
46
|
-
var _serializationPlugins, _buildPlugins, _intentResolvers, _data, _Transaction_instances, normalizeTransactionArgument_fn, resolveArgument_fn, prepareBuild_fn, runPlugins_fn;
|
|
46
|
+
var _serializationPlugins, _buildPlugins, _intentResolvers, _inputSection, _commandSection, _availableResults, _pendingPromises, _added, _data, _Transaction_instances, fork_fn, addCommand_fn, addInput_fn, normalizeTransactionArgument_fn, resolveArgument_fn, prepareBuild_fn, runPlugins_fn, waitForPendingTasks_fn, sortCommandsAndInputs_fn;
|
|
47
47
|
function createTransactionResult(index, length = Infinity) {
|
|
48
48
|
const baseResult = { $kind: "Result", Result: index };
|
|
49
49
|
const nestedResults = [];
|
|
@@ -106,6 +106,11 @@ const _Transaction = class _Transaction {
|
|
|
106
106
|
__privateAdd(this, _serializationPlugins);
|
|
107
107
|
__privateAdd(this, _buildPlugins);
|
|
108
108
|
__privateAdd(this, _intentResolvers, /* @__PURE__ */ new Map());
|
|
109
|
+
__privateAdd(this, _inputSection, []);
|
|
110
|
+
__privateAdd(this, _commandSection, []);
|
|
111
|
+
__privateAdd(this, _availableResults, /* @__PURE__ */ new Set());
|
|
112
|
+
__privateAdd(this, _pendingPromises, /* @__PURE__ */ new Set());
|
|
113
|
+
__privateAdd(this, _added, /* @__PURE__ */ new Map());
|
|
109
114
|
__privateAdd(this, _data);
|
|
110
115
|
/**
|
|
111
116
|
* Add a new object input to the transaction.
|
|
@@ -113,7 +118,7 @@ const _Transaction = class _Transaction {
|
|
|
113
118
|
this.object = (0, import_object.createObjectMethods)(
|
|
114
119
|
(value) => {
|
|
115
120
|
if (typeof value === "function") {
|
|
116
|
-
return this.object(value
|
|
121
|
+
return this.object(this.add(value));
|
|
117
122
|
}
|
|
118
123
|
if (typeof value === "object" && (0, import_valibot.is)(import_internal.Argument, value)) {
|
|
119
124
|
return value;
|
|
@@ -123,13 +128,10 @@ const _Transaction = class _Transaction {
|
|
|
123
128
|
if (inserted?.Object?.SharedObject && typeof value === "object" && value.Object?.SharedObject) {
|
|
124
129
|
inserted.Object.SharedObject.mutable = inserted.Object.SharedObject.mutable || value.Object.SharedObject.mutable;
|
|
125
130
|
}
|
|
126
|
-
return inserted ? { $kind: "Input", Input: __privateGet(this, _data).inputs.indexOf(inserted), type: "object" } :
|
|
127
|
-
"
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
UnresolvedObject: { objectId: (0, import_sui_types.normalizeSuiAddress)(value) }
|
|
131
|
-
} : value
|
|
132
|
-
);
|
|
131
|
+
return inserted ? { $kind: "Input", Input: __privateGet(this, _data).inputs.indexOf(inserted), type: "object" } : __privateMethod(this, _Transaction_instances, addInput_fn).call(this, "object", typeof value === "string" ? {
|
|
132
|
+
$kind: "UnresolvedObject",
|
|
133
|
+
UnresolvedObject: { objectId: (0, import_sui_types.normalizeSuiAddress)(value) }
|
|
134
|
+
} : value);
|
|
133
135
|
}
|
|
134
136
|
);
|
|
135
137
|
const globalPlugins = getGlobalPluginRegistry();
|
|
@@ -146,6 +148,8 @@ const _Transaction = class _Transaction {
|
|
|
146
148
|
__privateSet(tx, _data, import_TransactionData.TransactionDataBuilder.fromKindBytes(
|
|
147
149
|
typeof serialized === "string" ? (0, import_bcs.fromBase64)(serialized) : serialized
|
|
148
150
|
));
|
|
151
|
+
__privateSet(tx, _inputSection, __privateGet(tx, _data).inputs);
|
|
152
|
+
__privateSet(tx, _commandSection, __privateGet(tx, _data).commands);
|
|
149
153
|
return tx;
|
|
150
154
|
}
|
|
151
155
|
/**
|
|
@@ -165,6 +169,8 @@ const _Transaction = class _Transaction {
|
|
|
165
169
|
} else {
|
|
166
170
|
__privateSet(newTransaction, _data, import_TransactionData.TransactionDataBuilder.restore(JSON.parse(transaction)));
|
|
167
171
|
}
|
|
172
|
+
__privateSet(newTransaction, _inputSection, __privateGet(newTransaction, _data).inputs);
|
|
173
|
+
__privateSet(newTransaction, _commandSection, __privateGet(newTransaction, _data).commands);
|
|
168
174
|
return newTransaction;
|
|
169
175
|
}
|
|
170
176
|
static registerGlobalSerializationPlugin(stepOrStep, step) {
|
|
@@ -248,17 +254,14 @@ const _Transaction = class _Transaction {
|
|
|
248
254
|
enumerable: false,
|
|
249
255
|
value: (0, import_pure.createPure)((value) => {
|
|
250
256
|
if ((0, import_bcs.isSerializedBcs)(value)) {
|
|
251
|
-
return
|
|
257
|
+
return __privateMethod(this, _Transaction_instances, addInput_fn).call(this, "pure", {
|
|
252
258
|
$kind: "Pure",
|
|
253
259
|
Pure: {
|
|
254
260
|
bytes: value.toBase64()
|
|
255
261
|
}
|
|
256
262
|
});
|
|
257
263
|
}
|
|
258
|
-
return
|
|
259
|
-
"pure",
|
|
260
|
-
(0, import_valibot.is)(import_internal.NormalizedCallArg, value) ? (0, import_valibot.parse)(import_internal.NormalizedCallArg, value) : value instanceof Uint8Array ? import_Inputs.Inputs.Pure(value) : { $kind: "UnresolvedPure", UnresolvedPure: { value } }
|
|
261
|
-
);
|
|
264
|
+
return __privateMethod(this, _Transaction_instances, addInput_fn).call(this, "pure", (0, import_valibot.is)(import_internal.NormalizedCallArg, value) ? (0, import_valibot.parse)(import_internal.NormalizedCallArg, value) : value instanceof Uint8Array ? import_Inputs.Inputs.Pure(value) : { $kind: "UnresolvedPure", UnresolvedPure: { value } });
|
|
262
265
|
})
|
|
263
266
|
});
|
|
264
267
|
return this.pure;
|
|
@@ -288,13 +291,40 @@ const _Transaction = class _Transaction {
|
|
|
288
291
|
sharedObjectRef(...args) {
|
|
289
292
|
return this.object(import_Inputs.Inputs.SharedObjectRef(...args));
|
|
290
293
|
}
|
|
291
|
-
/** Add a transaction to the transaction */
|
|
292
294
|
add(command) {
|
|
293
295
|
if (typeof command === "function") {
|
|
294
|
-
|
|
296
|
+
if (__privateGet(this, _added).has(command)) {
|
|
297
|
+
return __privateGet(this, _added).get(command);
|
|
298
|
+
}
|
|
299
|
+
const fork = __privateMethod(this, _Transaction_instances, fork_fn).call(this);
|
|
300
|
+
const result = command(fork);
|
|
301
|
+
if (!(result && typeof result === "object" && "then" in result)) {
|
|
302
|
+
__privateSet(this, _availableResults, __privateGet(fork, _availableResults));
|
|
303
|
+
__privateGet(this, _added).set(command, result);
|
|
304
|
+
return result;
|
|
305
|
+
}
|
|
306
|
+
const placeholder = __privateMethod(this, _Transaction_instances, addCommand_fn).call(this, {
|
|
307
|
+
$kind: "$Intent",
|
|
308
|
+
$Intent: {
|
|
309
|
+
name: "AsyncTransactionThunk",
|
|
310
|
+
inputs: {},
|
|
311
|
+
data: {
|
|
312
|
+
result: null
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
__privateGet(this, _pendingPromises).add(
|
|
317
|
+
Promise.resolve(result).then((result2) => {
|
|
318
|
+
placeholder.$Intent.data.result = result2;
|
|
319
|
+
})
|
|
320
|
+
);
|
|
321
|
+
const txResult = createTransactionResult(__privateGet(this, _data).commands.length - 1);
|
|
322
|
+
__privateGet(this, _added).set(command, txResult);
|
|
323
|
+
return txResult;
|
|
324
|
+
} else {
|
|
325
|
+
__privateMethod(this, _Transaction_instances, addCommand_fn).call(this, command);
|
|
295
326
|
}
|
|
296
|
-
|
|
297
|
-
return createTransactionResult(index - 1);
|
|
327
|
+
return createTransactionResult(__privateGet(this, _data).commands.length - 1);
|
|
298
328
|
}
|
|
299
329
|
// Method shorthands:
|
|
300
330
|
splitCoins(coin, amounts) {
|
|
@@ -304,8 +334,8 @@ const _Transaction = class _Transaction {
|
|
|
304
334
|
(amount) => typeof amount === "number" || typeof amount === "bigint" || typeof amount === "string" ? this.pure.u64(amount) : __privateMethod(this, _Transaction_instances, normalizeTransactionArgument_fn).call(this, amount)
|
|
305
335
|
)
|
|
306
336
|
);
|
|
307
|
-
|
|
308
|
-
return createTransactionResult(
|
|
337
|
+
__privateMethod(this, _Transaction_instances, addCommand_fn).call(this, command);
|
|
338
|
+
return createTransactionResult(__privateGet(this, _data).commands.length - 1, amounts.length);
|
|
309
339
|
}
|
|
310
340
|
mergeCoins(destination, sources) {
|
|
311
341
|
return this.add(
|
|
@@ -403,6 +433,8 @@ const _Transaction = class _Transaction {
|
|
|
403
433
|
return __privateGet(this, _data).getDigest();
|
|
404
434
|
}
|
|
405
435
|
async prepareForSerialization(options) {
|
|
436
|
+
await __privateMethod(this, _Transaction_instances, waitForPendingTasks_fn).call(this);
|
|
437
|
+
__privateMethod(this, _Transaction_instances, sortCommandsAndInputs_fn).call(this);
|
|
406
438
|
const intents = /* @__PURE__ */ new Set();
|
|
407
439
|
for (const command of __privateGet(this, _data).commands) {
|
|
408
440
|
if (command.$Intent) {
|
|
@@ -425,8 +457,55 @@ const _Transaction = class _Transaction {
|
|
|
425
457
|
_serializationPlugins = new WeakMap();
|
|
426
458
|
_buildPlugins = new WeakMap();
|
|
427
459
|
_intentResolvers = new WeakMap();
|
|
460
|
+
_inputSection = new WeakMap();
|
|
461
|
+
_commandSection = new WeakMap();
|
|
462
|
+
_availableResults = new WeakMap();
|
|
463
|
+
_pendingPromises = new WeakMap();
|
|
464
|
+
_added = new WeakMap();
|
|
428
465
|
_data = new WeakMap();
|
|
429
466
|
_Transaction_instances = new WeakSet();
|
|
467
|
+
fork_fn = function() {
|
|
468
|
+
const fork = new _Transaction();
|
|
469
|
+
__privateSet(fork, _data, __privateGet(this, _data));
|
|
470
|
+
__privateSet(fork, _serializationPlugins, __privateGet(this, _serializationPlugins));
|
|
471
|
+
__privateSet(fork, _buildPlugins, __privateGet(this, _buildPlugins));
|
|
472
|
+
__privateSet(fork, _intentResolvers, __privateGet(this, _intentResolvers));
|
|
473
|
+
__privateSet(fork, _pendingPromises, __privateGet(this, _pendingPromises));
|
|
474
|
+
__privateSet(fork, _availableResults, new Set(__privateGet(this, _availableResults)));
|
|
475
|
+
__privateSet(fork, _added, __privateGet(this, _added));
|
|
476
|
+
__privateGet(this, _inputSection).push(__privateGet(fork, _inputSection));
|
|
477
|
+
__privateGet(this, _commandSection).push(__privateGet(fork, _commandSection));
|
|
478
|
+
return fork;
|
|
479
|
+
};
|
|
480
|
+
addCommand_fn = function(command) {
|
|
481
|
+
const resultIndex = __privateGet(this, _data).commands.length;
|
|
482
|
+
__privateGet(this, _commandSection).push(command);
|
|
483
|
+
__privateGet(this, _availableResults).add(resultIndex);
|
|
484
|
+
__privateGet(this, _data).commands.push(command);
|
|
485
|
+
__privateGet(this, _data).mapCommandArguments(resultIndex, (arg) => {
|
|
486
|
+
if (arg.$kind === "Result" && !__privateGet(this, _availableResults).has(arg.Result)) {
|
|
487
|
+
throw new Error(
|
|
488
|
+
`Result { Result: ${arg.Result} } is not available to use the current transaction`
|
|
489
|
+
);
|
|
490
|
+
}
|
|
491
|
+
if (arg.$kind === "NestedResult" && !__privateGet(this, _availableResults).has(arg.NestedResult[0])) {
|
|
492
|
+
throw new Error(
|
|
493
|
+
`Result { NestedResult: [${arg.NestedResult[0]}, ${arg.NestedResult[1]}] } is not available to use the current transaction`
|
|
494
|
+
);
|
|
495
|
+
}
|
|
496
|
+
if (arg.$kind === "Input" && arg.Input >= __privateGet(this, _data).inputs.length) {
|
|
497
|
+
throw new Error(
|
|
498
|
+
`Input { Input: ${arg.Input} } references an input that does not exist in the current transaction`
|
|
499
|
+
);
|
|
500
|
+
}
|
|
501
|
+
return arg;
|
|
502
|
+
});
|
|
503
|
+
return command;
|
|
504
|
+
};
|
|
505
|
+
addInput_fn = function(type, input) {
|
|
506
|
+
__privateGet(this, _inputSection).push(input);
|
|
507
|
+
return __privateGet(this, _data).addInput(type, input);
|
|
508
|
+
};
|
|
430
509
|
normalizeTransactionArgument_fn = function(arg) {
|
|
431
510
|
if ((0, import_bcs.isSerializedBcs)(arg)) {
|
|
432
511
|
return this.pure(arg);
|
|
@@ -435,7 +514,11 @@ normalizeTransactionArgument_fn = function(arg) {
|
|
|
435
514
|
};
|
|
436
515
|
resolveArgument_fn = function(arg) {
|
|
437
516
|
if (typeof arg === "function") {
|
|
438
|
-
|
|
517
|
+
const resolved = this.add(arg);
|
|
518
|
+
if (typeof resolved === "function") {
|
|
519
|
+
return __privateMethod(this, _Transaction_instances, resolveArgument_fn).call(this, resolved);
|
|
520
|
+
}
|
|
521
|
+
return (0, import_valibot.parse)(import_internal.Argument, resolved);
|
|
439
522
|
}
|
|
440
523
|
return (0, import_valibot.parse)(import_internal.Argument, arg);
|
|
441
524
|
};
|
|
@@ -473,6 +556,67 @@ runPlugins_fn = async function(plugins, options) {
|
|
|
473
556
|
};
|
|
474
557
|
};
|
|
475
558
|
await createNext(0)();
|
|
559
|
+
__privateSet(this, _inputSection, __privateGet(this, _data).inputs);
|
|
560
|
+
__privateSet(this, _commandSection, __privateGet(this, _data).commands);
|
|
561
|
+
};
|
|
562
|
+
waitForPendingTasks_fn = async function() {
|
|
563
|
+
while (__privateGet(this, _pendingPromises).size > 0) {
|
|
564
|
+
const newPromise = Promise.all(__privateGet(this, _pendingPromises));
|
|
565
|
+
__privateGet(this, _pendingPromises).clear();
|
|
566
|
+
__privateGet(this, _pendingPromises).add(newPromise);
|
|
567
|
+
await newPromise;
|
|
568
|
+
__privateGet(this, _pendingPromises).delete(newPromise);
|
|
569
|
+
}
|
|
570
|
+
};
|
|
571
|
+
sortCommandsAndInputs_fn = function() {
|
|
572
|
+
const unorderedCommands = __privateGet(this, _data).commands;
|
|
573
|
+
const unorderedInputs = __privateGet(this, _data).inputs;
|
|
574
|
+
const orderedCommands = __privateGet(this, _commandSection).flat(Infinity);
|
|
575
|
+
const orderedInputs = __privateGet(this, _inputSection).flat(Infinity);
|
|
576
|
+
if (orderedCommands.length !== unorderedCommands.length) {
|
|
577
|
+
throw new Error("Unexpected number of commands found in transaction data");
|
|
578
|
+
}
|
|
579
|
+
if (orderedInputs.length !== unorderedInputs.length) {
|
|
580
|
+
throw new Error("Unexpected number of inputs found in transaction data");
|
|
581
|
+
}
|
|
582
|
+
const filteredCommands = orderedCommands.filter(
|
|
583
|
+
(cmd) => cmd.$Intent?.name !== "AsyncTransactionThunk"
|
|
584
|
+
);
|
|
585
|
+
__privateGet(this, _data).commands = filteredCommands;
|
|
586
|
+
__privateGet(this, _data).inputs = orderedInputs;
|
|
587
|
+
__privateSet(this, _commandSection, filteredCommands);
|
|
588
|
+
__privateSet(this, _inputSection, orderedInputs);
|
|
589
|
+
function getOriginalIndex(index) {
|
|
590
|
+
const command = unorderedCommands[index];
|
|
591
|
+
if (command.$Intent?.name === "AsyncTransactionThunk") {
|
|
592
|
+
const result = command.$Intent.data.result;
|
|
593
|
+
if (result == null) {
|
|
594
|
+
throw new Error("AsyncTransactionThunk has not been resolved");
|
|
595
|
+
}
|
|
596
|
+
return getOriginalIndex(result.Result);
|
|
597
|
+
}
|
|
598
|
+
const updated = filteredCommands.indexOf(command);
|
|
599
|
+
if (updated === -1) {
|
|
600
|
+
throw new Error("Unable to find original index for command");
|
|
601
|
+
}
|
|
602
|
+
return updated;
|
|
603
|
+
}
|
|
604
|
+
__privateGet(this, _data).mapArguments((arg) => {
|
|
605
|
+
if (arg.$kind === "Input") {
|
|
606
|
+
const updated = orderedInputs.indexOf(unorderedInputs[arg.Input]);
|
|
607
|
+
if (updated === -1) {
|
|
608
|
+
throw new Error("Input has not been resolved");
|
|
609
|
+
}
|
|
610
|
+
return { ...arg, Input: updated };
|
|
611
|
+
} else if (arg.$kind === "Result") {
|
|
612
|
+
const updated = getOriginalIndex(arg.Result);
|
|
613
|
+
return { ...arg, Result: updated };
|
|
614
|
+
} else if (arg.$kind === "NestedResult") {
|
|
615
|
+
const updated = getOriginalIndex(arg.NestedResult[0]);
|
|
616
|
+
return { ...arg, NestedResult: [updated, arg.NestedResult[1]] };
|
|
617
|
+
}
|
|
618
|
+
return arg;
|
|
619
|
+
});
|
|
476
620
|
};
|
|
477
621
|
let Transaction = _Transaction;
|
|
478
622
|
//# sourceMappingURL=Transaction.js.map
|