@algorandfoundation/algokit-utils 10.0.0-alpha.24 → 10.0.0-alpha.25

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.
Files changed (39) hide show
  1. package/package.json +1 -1
  2. package/packages/transact/src/logicsig.d.ts +36 -22
  3. package/packages/transact/src/logicsig.js +69 -52
  4. package/packages/transact/src/logicsig.js.map +1 -1
  5. package/packages/transact/src/logicsig.mjs +70 -54
  6. package/packages/transact/src/logicsig.mjs.map +1 -1
  7. package/packages/transact/src/multisig.d.ts +4 -1
  8. package/packages/transact/src/multisig.js +17 -0
  9. package/packages/transact/src/multisig.js.map +1 -1
  10. package/packages/transact/src/multisig.mjs +17 -0
  11. package/packages/transact/src/multisig.mjs.map +1 -1
  12. package/packages/transact/src/signer.js +4 -1
  13. package/packages/transact/src/signer.js.map +1 -1
  14. package/packages/transact/src/signer.mjs +4 -1
  15. package/packages/transact/src/signer.mjs.map +1 -1
  16. package/packages/transact/src/transactions/signed-transaction-meta.js +6 -6
  17. package/packages/transact/src/transactions/signed-transaction-meta.js.map +1 -1
  18. package/packages/transact/src/transactions/signed-transaction-meta.mjs +6 -6
  19. package/packages/transact/src/transactions/signed-transaction-meta.mjs.map +1 -1
  20. package/packages/transact/src/transactions/signed-transaction.d.ts +4 -4
  21. package/packages/transact/src/transactions/signed-transaction.js.map +1 -1
  22. package/packages/transact/src/transactions/signed-transaction.mjs.map +1 -1
  23. package/testing/account.js +4 -2
  24. package/testing/account.js.map +1 -1
  25. package/testing/account.mjs +4 -2
  26. package/testing/account.mjs.map +1 -1
  27. package/transact/index.d.ts +3 -3
  28. package/transact/index.js +2 -1
  29. package/transact/index.mjs +2 -2
  30. package/types/account-manager.d.ts +6 -8
  31. package/types/account-manager.js +13 -3
  32. package/types/account-manager.js.map +1 -1
  33. package/types/account-manager.mjs +13 -3
  34. package/types/account-manager.mjs.map +1 -1
  35. package/types/algorand-client-transaction-creator.d.ts +26 -26
  36. package/types/algorand-client-transaction-sender.d.ts +26 -26
  37. package/types/app-client.d.ts +74 -74
  38. package/types/app-factory.d.ts +30 -30
  39. package/types/testing.d.ts +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"multisig.js","names":["getAddress","arrayEqual","msig: MultisigSignature","authAddress: Address | undefined","Address","newSubsigs: MultisigSubsignature[]","SIGNATURE_BYTE_LENGTH","ALGORAND_ADDRESS_BYTE_LENGTH","ALGORAND_CHECKSUM_BYTE_LENGTH","PUBLIC_KEY_BYTE_LENGTH","hash","multisigAddress: typeof addressFromMultisigPreImgAddrs","signedMsigTxns: SignedTransaction[]","decodeSignedTransaction","encodeSignedTransaction","subsignatures: MultisigSubsignature[]"],"sources":["../../../../packages/transact/src/multisig.ts"],"sourcesContent":["import {\n Address,\n ALGORAND_ADDRESS_BYTE_LENGTH,\n ALGORAND_CHECKSUM_BYTE_LENGTH,\n arrayEqual,\n getAddress,\n hash,\n PUBLIC_KEY_BYTE_LENGTH,\n SIGNATURE_BYTE_LENGTH,\n} from '@algorandfoundation/algokit-common'\nimport { AddressWithDelegatedLsigSigner, AddressWithTransactionSigner, TransactionSigner } from './signer'\nimport {\n decodeSignedTransaction,\n encodeSignedTransaction,\n MultisigSignature,\n MultisigSubsignature,\n SignedTransaction,\n} from './transactions/signed-transaction'\nimport { Transaction } from './transactions/transaction'\n\nconst toPublicKeys = (addrs: Array<string | Address>): Uint8Array[] => addrs.map((addr) => getAddress(addr).publicKey)\n\n/**\n * Applies a subsignature for a participant to a multisignature signature, replacing any existing signature.\n *\n * This method applies the signature to ALL instances of the given public key (to support weighted multisig).\n * Since ed25519 signatures are deterministic, there's only one valid signature for a given message and public key.\n */\nfunction applyMultisigSubsignature(\n multisigSignature: MultisigSignature,\n participant: Uint8Array,\n signature: Uint8Array,\n): MultisigSignature {\n let found = false\n const newSubsignatures = multisigSignature.subsigs.map((subsig) => {\n if (arrayEqual(subsig.publicKey, participant)) {\n found = true\n return { ...subsig, sig: signature } satisfies MultisigSubsignature\n }\n return subsig\n })\n\n if (!found) {\n throw new Error('Public key not found in multisig signature')\n }\n\n return {\n ...multisigSignature,\n subsigs: newSubsignatures,\n }\n}\n\n// Convert \"MultisigAddr\" UTF-8 to byte array\nconst MULTISIG_PREIMG2ADDR_PREFIX = new Uint8Array([77, 117, 108, 116, 105, 115, 105, 103, 65, 100, 100, 114])\n\nconst INVALID_MSIG_VERSION_ERROR_MSG = 'invalid multisig version'\nconst INVALID_MSIG_THRESHOLD_ERROR_MSG = 'bad multisig threshold'\nconst INVALID_MSIG_PK_ERROR_MSG = 'bad multisig public key - wrong length'\nconst UNEXPECTED_PK_LEN_ERROR_MSG = 'nacl public key length is not 32 bytes'\n\nconst MULTISIG_MERGE_LESSTHANTWO_ERROR_MSG = 'Not enough multisig transactions to merge. Need at least two'\nconst MULTISIG_MERGE_MISMATCH_ERROR_MSG = 'Cannot merge txs. txIDs differ'\nconst MULTISIG_MERGE_MISMATCH_AUTH_ADDR_MSG = 'Cannot merge txs. Auth addrs differ'\nconst MULTISIG_MERGE_WRONG_PREIMAGE_ERROR_MSG = 'Cannot merge txs. Multisig preimages differ'\nconst MULTISIG_MERGE_SIG_MISMATCH_ERROR_MSG = 'Cannot merge txs. subsigs are mismatched.'\nconst MULTISIG_SIGNATURE_LENGTH_ERROR_MSG = 'Cannot add multisig signature. Signature is not of the correct length.'\nconst MULTISIG_KEY_NOT_EXIST_ERROR_MSG = 'Key does not exist'\n\n/**\n * creates a raw, multisig transaction blob without any signatures.\n * @param txn - the actual transaction.\n * @param version - multisig version\n * @param threshold - multisig threshold\n * @param pks - ordered list of public keys in this multisig\n * @returns encoded multisig blob\n */\nfunction createMultisigTransaction(txn: Transaction, { version, threshold, addrs }: MultisigMetadata) {\n // construct the appendable multisigned transaction format\n const pks = toPublicKeys(addrs)\n const subsignatures = pks.map(\n (pk) =>\n ({\n publicKey: pk,\n sig: undefined,\n }) satisfies MultisigSubsignature,\n )\n\n const msig: MultisigSignature = {\n version,\n threshold,\n subsigs: subsignatures,\n }\n\n // if the address of this multisig is different from the transaction sender,\n // we need to add the auth-addr field\n const msigAddr = addressFromMultisigPreImg({\n version,\n threshold,\n publicKeys: pks,\n })\n let authAddress: Address | undefined\n if (!msigAddr.equals(txn.sender)) {\n authAddress = msigAddr\n }\n\n const signedTxn: SignedTransaction = {\n txn: txn,\n msig: msig,\n authAddress,\n }\n\n return signedTxn\n}\n\ninterface MultisigOptions {\n rawSig: Uint8Array\n myPk: Uint8Array\n}\n\ninterface MultisigMetadataWithPublicKeys extends Omit<MultisigMetadata, 'addrs'> {\n publicKeys: Uint8Array[]\n}\n\n/**\n * creates a multisig transaction blob with an included signature.\n * @param txn - the actual transaction to sign.\n * @param rawSig - a Uint8Array raw signature of that transaction\n * @param myPk - a public key that corresponds with rawSig\n * @param version - multisig version\n * @param threshold - multisig threshold\n * @param pks - ordered list of public keys in this multisig\n * @returns encoded multisig blob\n */\nfunction createMultisigTransactionWithSignature(\n txn: Transaction,\n { rawSig, myPk }: MultisigOptions,\n { version, threshold, publicKeys }: MultisigMetadataWithPublicKeys,\n): SignedTransaction {\n // Create an empty encoded multisig transaction\n const signedTxn = createMultisigTransaction(txn, {\n version,\n threshold,\n addrs: publicKeys.map((pk) => new Address(pk)),\n })\n\n let keyExist = false\n\n // append the multisig signature to the corresponding public key in the multisig blob\n const updatedSubsigs = signedTxn.msig!.subsigs.map((subsig) => {\n if (arrayEqual(subsig.publicKey, myPk)) {\n keyExist = true\n return { ...subsig, sig: rawSig }\n }\n return subsig\n })\n\n if (!keyExist) {\n throw new Error(MULTISIG_KEY_NOT_EXIST_ERROR_MSG)\n }\n\n const updatedSignedTxn: SignedTransaction = {\n ...signedTxn,\n msig: {\n ...signedTxn.msig!,\n subsigs: updatedSubsigs,\n },\n }\n\n return updatedSignedTxn\n}\n\n/**\n * takes a list of multisig transaction blobs, and merges them.\n * @param multisigTxnBlobs - a list of blobs representing encoded multisig txns\n * @returns typed array msg-pack encoded multisig txn\n */\nfunction mergeMultisigTransactions(multisigTxnBlobs: SignedTransaction[]): SignedTransaction {\n if (multisigTxnBlobs.length < 2) {\n throw new Error(MULTISIG_MERGE_LESSTHANTWO_ERROR_MSG)\n }\n const refSigTx = multisigTxnBlobs[0]\n if (!refSigTx.msig) {\n throw new Error('Invalid multisig transaction, multisig structure missing at index 0')\n }\n const refTxID = refSigTx.txn.txId()\n const refAuthAddr = refSigTx.authAddress\n const refPreImage = {\n version: refSigTx.msig.version,\n threshold: refSigTx.msig.threshold,\n publicKeys: refSigTx.msig.subsigs.map((subsig) => subsig.publicKey),\n }\n const refMsigAddr = addressFromMultisigPreImg(refPreImage)\n\n const newSubsigs: MultisigSubsignature[] = refSigTx.msig.subsigs.map((sig) => ({ ...sig }))\n for (let i = 1; i < multisigTxnBlobs.length; i++) {\n const unisig = multisigTxnBlobs[i]\n if (!unisig.msig) {\n throw new Error(`Invalid multisig transaction, multisig structure missing at index ${i}`)\n }\n\n if (unisig.txn.txId() !== refTxID) {\n throw new Error(MULTISIG_MERGE_MISMATCH_ERROR_MSG)\n }\n\n const authAddr = unisig.authAddress\n if (refAuthAddr !== authAddr) {\n throw new Error(MULTISIG_MERGE_MISMATCH_AUTH_ADDR_MSG)\n }\n\n // check multisig has same preimage as reference\n if (unisig.msig.subsigs.length !== refSigTx.msig.subsigs.length) {\n throw new Error(MULTISIG_MERGE_WRONG_PREIMAGE_ERROR_MSG)\n }\n const preimg: MultisigMetadataWithPublicKeys = {\n version: unisig.msig.version,\n threshold: unisig.msig.threshold,\n publicKeys: unisig.msig.subsigs.map((subsig) => subsig.publicKey),\n }\n const msgigAddr = addressFromMultisigPreImg(preimg)\n if (refMsigAddr.toString() !== msgigAddr.toString()) {\n throw new Error(MULTISIG_MERGE_WRONG_PREIMAGE_ERROR_MSG)\n }\n\n // now, we can merge\n unisig.msig.subsigs.forEach((uniSubsig, index) => {\n if (!uniSubsig.sig) return\n const current = newSubsigs[index]\n if (current.sig && !arrayEqual(uniSubsig.sig, current.sig)) {\n // mismatch\n throw new Error(MULTISIG_MERGE_SIG_MISMATCH_ERROR_MSG)\n }\n current.sig = uniSubsig.sig\n })\n }\n\n const msig: MultisigSignature = {\n version: refSigTx.msig.version,\n threshold: refSigTx.msig.threshold,\n subsigs: newSubsigs,\n }\n\n const signedTxn: SignedTransaction = {\n txn: refSigTx.txn,\n msig: msig,\n authAddress: refAuthAddr,\n }\n\n return signedTxn\n}\n\n/**\n * Partially signs this transaction with an external raw multisig signature and returns\n * a partially-signed multisig transaction, encoded with msgpack as a typed array.\n * @param transaction - The transaction to sign\n * @param metadata - multisig metadata\n * @param signerAddr - address of the signer\n * @param signature - raw multisig signature\n * @returns an encoded, partially signed multisig transaction.\n */\nfunction partialSignWithMultisigSignature(\n transaction: Transaction,\n metadata: MultisigMetadataWithPublicKeys,\n signerAddr: string | Address,\n signature: Uint8Array,\n) {\n if (signature.length != SIGNATURE_BYTE_LENGTH) {\n throw new Error(MULTISIG_SIGNATURE_LENGTH_ERROR_MSG)\n }\n const signerAddressObj = typeof signerAddr === 'string' ? Address.fromString(signerAddr) : signerAddr\n return createMultisigTransactionWithSignature(\n transaction,\n {\n rawSig: signature,\n myPk: signerAddressObj.publicKey,\n },\n metadata,\n )\n}\n\n/**\n * Takes a multisig transaction blob, and appends a given raw signature to it.\n * This makes it possible to compile a multisig signature using only raw signatures from external methods.\n * @param multisigTxnBlob - an encoded multisig txn. Supports non-payment txn types.\n * @param version - multisig version\n * @param threshold - multisig threshold\n * @param addrs - a list of Algorand addresses representing possible signers for this multisig. Order is important.\n * @param signerAddr - address of the signer\n * @param signature - raw multisig signature\n * @returns object containing txID, and blob representing encoded multisig txn\n */\nfunction appendSignRawMultisigSignature(\n multisigTxn: SignedTransaction,\n { version, threshold, addrs }: MultisigMetadata,\n signerAddr: string | Address,\n signature: Uint8Array,\n): SignedTransaction {\n const publicKeys = toPublicKeys(addrs)\n // obtain underlying txn, sign it, and merge it\n const partialSigned = partialSignWithMultisigSignature(multisigTxn.txn, { version, threshold, publicKeys }, signerAddr, signature)\n return mergeMultisigTransactions([multisigTxn, partialSigned])\n}\n\n/**\n * Takes multisig parameters and returns a 32 byte typed array public key,\n * representing an address that identifies the \"exact group, version, and public keys\" that are required for signing.\n * Hash(\"MultisigAddr\" || version uint8 || threshold uint8 || PK1 || PK2 || ...)\n * Encoding this output yields a human readable address.\n * @param version - multisig version\n * @param threshold - multisig threshold\n * @param pks - array of typed array public keys\n */\nfunction addressFromMultisigPreImg({\n version,\n threshold,\n publicKeys,\n}: Omit<MultisigMetadata, 'addrs'> & {\n publicKeys: Uint8Array[]\n}): Address {\n if (version > 255 || version < 0) {\n // ^ a tad redundant, but in case in the future version != 1, still check for uint8\n throw new Error(`${INVALID_MSIG_VERSION_ERROR_MSG}: ${version}`)\n }\n if (threshold === 0 || publicKeys.length === 0 || threshold > publicKeys.length || threshold > 255) {\n throw new Error(INVALID_MSIG_THRESHOLD_ERROR_MSG)\n }\n const pkLen = ALGORAND_ADDRESS_BYTE_LENGTH - ALGORAND_CHECKSUM_BYTE_LENGTH\n if (pkLen !== PUBLIC_KEY_BYTE_LENGTH) {\n throw new Error(UNEXPECTED_PK_LEN_ERROR_MSG)\n }\n const merged = new Uint8Array(MULTISIG_PREIMG2ADDR_PREFIX.length + 2 + pkLen * publicKeys.length)\n merged.set(MULTISIG_PREIMG2ADDR_PREFIX, 0)\n merged.set([version], MULTISIG_PREIMG2ADDR_PREFIX.length)\n merged.set([threshold], MULTISIG_PREIMG2ADDR_PREFIX.length + 1)\n for (let i = 0; i < publicKeys.length; i++) {\n if (publicKeys[i].length !== pkLen) {\n throw new Error(INVALID_MSIG_PK_ERROR_MSG)\n }\n merged.set(publicKeys[i], MULTISIG_PREIMG2ADDR_PREFIX.length + 2 + i * pkLen)\n }\n return new Address(Uint8Array.from(hash(merged)))\n}\n\n/**\n * Takes multisig parameters and returns a human readable Algorand address.\n * This is equivalent to fromMultisigPreImg, but interfaces with encoded addresses.\n * @param version - multisig version\n * @param threshold - multisig threshold\n * @param addrs - array of encoded addresses\n */\nfunction addressFromMultisigPreImgAddrs({ version, threshold, addrs }: MultisigMetadata): Address {\n return addressFromMultisigPreImg({\n version,\n threshold,\n publicKeys: toPublicKeys(addrs),\n })\n}\n\n/**\n * Takes multisig metadata (preimage) and returns the corresponding human readable Algorand address.\n * @param version - multisig version\n * @param threshold - multisig threshold\n * @param addrs - list of Algorand addresses\n */\nconst multisigAddress: typeof addressFromMultisigPreImgAddrs = addressFromMultisigPreImgAddrs\n\nexport interface MultisigMetadata {\n /**\n * Multisig version\n */\n version: number\n\n /**\n * Multisig threshold value. Authorization requires a subset of signatures,\n * equal to or greater than the threshold value.\n */\n threshold: number\n\n /**\n * A list of Algorand addresses representing possible signers for this multisig. Order is important.\n */\n addrs: Array<Address>\n}\n\n/** Account wrapper that supports partial or full multisig signing. */\nexport class MultisigAccount implements AddressWithTransactionSigner {\n _params: MultisigMetadata\n _subSigners: (AddressWithTransactionSigner & AddressWithDelegatedLsigSigner)[]\n _addr: Address\n _signer: TransactionSigner\n\n /** The parameters for the multisig account */\n get params(): Readonly<MultisigMetadata> {\n return this._params\n }\n\n /** The list of accounts that are present to sign transactions or lsigs */\n get subSigners() {\n return this._subSigners\n }\n\n /** The address of the multisig account */\n get addr(): Readonly<Address> {\n return this._addr\n }\n\n /** The transaction signer for the multisig account */\n get signer(): TransactionSigner {\n return this._signer\n }\n\n static fromSignature(signature: MultisigSignature): MultisigAccount {\n const params: MultisigMetadata = {\n version: signature.version,\n threshold: signature.threshold,\n addrs: signature.subsigs.map((subsig) => new Address(subsig.publicKey)),\n }\n\n return new MultisigAccount(params, [])\n }\n\n constructor(multisigParams: MultisigMetadata, subSigners: (AddressWithTransactionSigner & AddressWithDelegatedLsigSigner)[]) {\n this._params = multisigParams\n this._subSigners = subSigners\n this._addr = multisigAddress(multisigParams)\n this._signer = async (txns: Transaction[], indexesToSign: number[]): Promise<Uint8Array[]> => {\n const txnsToSign = txns.filter((_, index) => indexesToSign.includes(index))\n const signedMsigTxns: SignedTransaction[] = []\n\n for (const txn of txnsToSign) {\n let signedMsigTxn = createMultisigTransaction(txn, this._params)\n\n for (const subSigner of this.subSigners) {\n const stxn = (await subSigner.signer([txn], [0]))[0]\n const sig = decodeSignedTransaction(stxn).sig\n\n if (!sig) {\n throw new Error(\n `Signer for address ${subSigner.addr.toString()} did not produce a valid signature when signing ${txn.txId()} for multisig account ${this._addr.toString()}`,\n )\n }\n\n signedMsigTxn = appendSignRawMultisigSignature(signedMsigTxn, this._params, subSigner.addr, sig)\n }\n\n signedMsigTxns.push(signedMsigTxn)\n }\n\n return signedMsigTxns.map(encodeSignedTransaction)\n }\n }\n\n createMultisigTransaction(txn: Transaction): SignedTransaction {\n return createMultisigTransaction(txn, this._params)\n }\n\n createMultisigSignature(): MultisigSignature {\n const pks = toPublicKeys(this._params.addrs)\n const subsignatures: MultisigSubsignature[] = pks.map((pk) => ({\n publicKey: pk,\n signature: undefined,\n }))\n\n return {\n version: this._params.version,\n threshold: this._params.threshold,\n subsigs: subsignatures,\n }\n }\n\n applySignatureToTxn(txn: SignedTransaction, pubkey: Uint8Array, signature: Uint8Array): void {\n if (!txn.msig) {\n const createdTxn = this.createMultisigTransaction(txn.txn)\n txn.msig = createdTxn.msig\n }\n\n txn.msig = applyMultisigSubsignature(txn.msig!, pubkey, signature)\n }\n\n applySignature(msigSignature: MultisigSignature, pubkey: Uint8Array, signature: Uint8Array): MultisigSignature {\n if (msigSignature.version !== this._params.version || msigSignature.threshold !== this._params.threshold) {\n const thisParams = {\n version: this._params.version,\n threshold: this._params.threshold,\n participants: this._params.addrs.map((addr) => addr.toString()),\n }\n\n const givenParams = {\n version: msigSignature.version,\n threshold: msigSignature.threshold,\n participants: msigSignature.subsigs.map((subsig) => new Address(subsig.publicKey).toString()),\n }\n\n throw new Error(\n `Multisig signature parameters do not match expected multisig parameters. Multisig params: ${JSON.stringify(thisParams)}, signature: ${JSON.stringify(givenParams)}`,\n )\n }\n\n return applyMultisigSubsignature(msigSignature, pubkey, signature)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AK,QAAQ,MAAM,KAAK,SAAS,KAAK,UAAU,CAAC;IAChE;GAED,MAAM,cAAc;IAClB,SAAS,cAAc;IACvB,WAAW,cAAc;IACzB,cAAc,cAAc,QAAQ,KAAK,WAAW,IAAIX,wBAAQ,OAAO,UAAU,CAAC,UAAU,CAAC;IAC9F;AAED,SAAM,IAAI,MACR,6FAA6F,KAAK,UAAU,WAAW,CAAC,eAAe,KAAK,UAAU,YAAY,GACnK;;AAGH,SAAO,0BAA0B,eAAe,QAAQ,UAAU"}
1
+ {"version":3,"file":"multisig.js","names":["getAddress","arrayEqual","msig: MultisigSignature","authAddress: Address | undefined","Address","newSubsigs: MultisigSubsignature[]","SIGNATURE_BYTE_LENGTH","ALGORAND_ADDRESS_BYTE_LENGTH","ALGORAND_CHECKSUM_BYTE_LENGTH","PUBLIC_KEY_BYTE_LENGTH","hash","multisigAddress: typeof addressFromMultisigPreImgAddrs","signedMsigTxns: SignedTransaction[]","decodeSignedTransaction","encodeSignedTransaction","subsignatures: MultisigSubsignature[]"],"sources":["../../../../packages/transact/src/multisig.ts"],"sourcesContent":["import {\n Address,\n ALGORAND_ADDRESS_BYTE_LENGTH,\n ALGORAND_CHECKSUM_BYTE_LENGTH,\n arrayEqual,\n getAddress,\n hash,\n PUBLIC_KEY_BYTE_LENGTH,\n SIGNATURE_BYTE_LENGTH,\n} from '@algorandfoundation/algokit-common'\nimport { AddressWithDelegatedLsigSigner, AddressWithTransactionSigner, TransactionSigner } from './signer'\nimport {\n decodeSignedTransaction,\n encodeSignedTransaction,\n MultisigSignature,\n MultisigSubsignature,\n SignedTransaction,\n} from './transactions/signed-transaction'\nimport { Transaction } from './transactions/transaction'\nimport { DelegatedLsigSigner } from './logicsig'\n\nconst toPublicKeys = (addrs: Array<string | Address>): Uint8Array[] => addrs.map((addr) => getAddress(addr).publicKey)\n\n/**\n * Applies a subsignature for a participant to a multisignature signature, replacing any existing signature.\n *\n * This method applies the signature to ALL instances of the given public key (to support weighted multisig).\n * Since ed25519 signatures are deterministic, there's only one valid signature for a given message and public key.\n */\nfunction applyMultisigSubsignature(\n multisigSignature: MultisigSignature,\n participant: Uint8Array,\n signature: Uint8Array,\n): MultisigSignature {\n let found = false\n const newSubsignatures = multisigSignature.subsigs.map((subsig) => {\n if (arrayEqual(subsig.publicKey, participant)) {\n found = true\n return { ...subsig, sig: signature } satisfies MultisigSubsignature\n }\n return subsig\n })\n\n if (!found) {\n throw new Error('Public key not found in multisig signature')\n }\n\n return {\n ...multisigSignature,\n subsigs: newSubsignatures,\n }\n}\n\n// Convert \"MultisigAddr\" UTF-8 to byte array\nconst MULTISIG_PREIMG2ADDR_PREFIX = new Uint8Array([77, 117, 108, 116, 105, 115, 105, 103, 65, 100, 100, 114])\n\nconst INVALID_MSIG_VERSION_ERROR_MSG = 'invalid multisig version'\nconst INVALID_MSIG_THRESHOLD_ERROR_MSG = 'bad multisig threshold'\nconst INVALID_MSIG_PK_ERROR_MSG = 'bad multisig public key - wrong length'\nconst UNEXPECTED_PK_LEN_ERROR_MSG = 'nacl public key length is not 32 bytes'\n\nconst MULTISIG_MERGE_LESSTHANTWO_ERROR_MSG = 'Not enough multisig transactions to merge. Need at least two'\nconst MULTISIG_MERGE_MISMATCH_ERROR_MSG = 'Cannot merge txs. txIDs differ'\nconst MULTISIG_MERGE_MISMATCH_AUTH_ADDR_MSG = 'Cannot merge txs. Auth addrs differ'\nconst MULTISIG_MERGE_WRONG_PREIMAGE_ERROR_MSG = 'Cannot merge txs. Multisig preimages differ'\nconst MULTISIG_MERGE_SIG_MISMATCH_ERROR_MSG = 'Cannot merge txs. subsigs are mismatched.'\nconst MULTISIG_SIGNATURE_LENGTH_ERROR_MSG = 'Cannot add multisig signature. Signature is not of the correct length.'\nconst MULTISIG_KEY_NOT_EXIST_ERROR_MSG = 'Key does not exist'\n\n/**\n * creates a raw, multisig transaction blob without any signatures.\n * @param txn - the actual transaction.\n * @param version - multisig version\n * @param threshold - multisig threshold\n * @param pks - ordered list of public keys in this multisig\n * @returns encoded multisig blob\n */\nfunction createMultisigTransaction(txn: Transaction, { version, threshold, addrs }: MultisigMetadata) {\n // construct the appendable multisigned transaction format\n const pks = toPublicKeys(addrs)\n const subsignatures = pks.map(\n (pk) =>\n ({\n publicKey: pk,\n sig: undefined,\n }) satisfies MultisigSubsignature,\n )\n\n const msig: MultisigSignature = {\n version,\n threshold,\n subsigs: subsignatures,\n }\n\n // if the address of this multisig is different from the transaction sender,\n // we need to add the auth-addr field\n const msigAddr = addressFromMultisigPreImg({\n version,\n threshold,\n publicKeys: pks,\n })\n let authAddress: Address | undefined\n if (!msigAddr.equals(txn.sender)) {\n authAddress = msigAddr\n }\n\n const signedTxn: SignedTransaction = {\n txn: txn,\n msig: msig,\n authAddress,\n }\n\n return signedTxn\n}\n\ninterface MultisigOptions {\n rawSig: Uint8Array\n myPk: Uint8Array\n}\n\ninterface MultisigMetadataWithPublicKeys extends Omit<MultisigMetadata, 'addrs'> {\n publicKeys: Uint8Array[]\n}\n\n/**\n * creates a multisig transaction blob with an included signature.\n * @param txn - the actual transaction to sign.\n * @param rawSig - a Uint8Array raw signature of that transaction\n * @param myPk - a public key that corresponds with rawSig\n * @param version - multisig version\n * @param threshold - multisig threshold\n * @param pks - ordered list of public keys in this multisig\n * @returns encoded multisig blob\n */\nfunction createMultisigTransactionWithSignature(\n txn: Transaction,\n { rawSig, myPk }: MultisigOptions,\n { version, threshold, publicKeys }: MultisigMetadataWithPublicKeys,\n): SignedTransaction {\n // Create an empty encoded multisig transaction\n const signedTxn = createMultisigTransaction(txn, {\n version,\n threshold,\n addrs: publicKeys.map((pk) => new Address(pk)),\n })\n\n let keyExist = false\n\n // append the multisig signature to the corresponding public key in the multisig blob\n const updatedSubsigs = signedTxn.msig!.subsigs.map((subsig) => {\n if (arrayEqual(subsig.publicKey, myPk)) {\n keyExist = true\n return { ...subsig, sig: rawSig }\n }\n return subsig\n })\n\n if (!keyExist) {\n throw new Error(MULTISIG_KEY_NOT_EXIST_ERROR_MSG)\n }\n\n const updatedSignedTxn: SignedTransaction = {\n ...signedTxn,\n msig: {\n ...signedTxn.msig!,\n subsigs: updatedSubsigs,\n },\n }\n\n return updatedSignedTxn\n}\n\n/**\n * takes a list of multisig transaction blobs, and merges them.\n * @param multisigTxnBlobs - a list of blobs representing encoded multisig txns\n * @returns typed array msg-pack encoded multisig txn\n */\nfunction mergeMultisigTransactions(multisigTxnBlobs: SignedTransaction[]): SignedTransaction {\n if (multisigTxnBlobs.length < 2) {\n throw new Error(MULTISIG_MERGE_LESSTHANTWO_ERROR_MSG)\n }\n const refSigTx = multisigTxnBlobs[0]\n if (!refSigTx.msig) {\n throw new Error('Invalid multisig transaction, multisig structure missing at index 0')\n }\n const refTxID = refSigTx.txn.txId()\n const refAuthAddr = refSigTx.authAddress\n const refPreImage = {\n version: refSigTx.msig.version,\n threshold: refSigTx.msig.threshold,\n publicKeys: refSigTx.msig.subsigs.map((subsig) => subsig.publicKey),\n }\n const refMsigAddr = addressFromMultisigPreImg(refPreImage)\n\n const newSubsigs: MultisigSubsignature[] = refSigTx.msig.subsigs.map((sig) => ({ ...sig }))\n for (let i = 1; i < multisigTxnBlobs.length; i++) {\n const unisig = multisigTxnBlobs[i]\n if (!unisig.msig) {\n throw new Error(`Invalid multisig transaction, multisig structure missing at index ${i}`)\n }\n\n if (unisig.txn.txId() !== refTxID) {\n throw new Error(MULTISIG_MERGE_MISMATCH_ERROR_MSG)\n }\n\n const authAddr = unisig.authAddress\n if (refAuthAddr !== authAddr) {\n throw new Error(MULTISIG_MERGE_MISMATCH_AUTH_ADDR_MSG)\n }\n\n // check multisig has same preimage as reference\n if (unisig.msig.subsigs.length !== refSigTx.msig.subsigs.length) {\n throw new Error(MULTISIG_MERGE_WRONG_PREIMAGE_ERROR_MSG)\n }\n const preimg: MultisigMetadataWithPublicKeys = {\n version: unisig.msig.version,\n threshold: unisig.msig.threshold,\n publicKeys: unisig.msig.subsigs.map((subsig) => subsig.publicKey),\n }\n const msgigAddr = addressFromMultisigPreImg(preimg)\n if (refMsigAddr.toString() !== msgigAddr.toString()) {\n throw new Error(MULTISIG_MERGE_WRONG_PREIMAGE_ERROR_MSG)\n }\n\n // now, we can merge\n unisig.msig.subsigs.forEach((uniSubsig, index) => {\n if (!uniSubsig.sig) return\n const current = newSubsigs[index]\n if (current.sig && !arrayEqual(uniSubsig.sig, current.sig)) {\n // mismatch\n throw new Error(MULTISIG_MERGE_SIG_MISMATCH_ERROR_MSG)\n }\n current.sig = uniSubsig.sig\n })\n }\n\n const msig: MultisigSignature = {\n version: refSigTx.msig.version,\n threshold: refSigTx.msig.threshold,\n subsigs: newSubsigs,\n }\n\n const signedTxn: SignedTransaction = {\n txn: refSigTx.txn,\n msig: msig,\n authAddress: refAuthAddr,\n }\n\n return signedTxn\n}\n\n/**\n * Partially signs this transaction with an external raw multisig signature and returns\n * a partially-signed multisig transaction, encoded with msgpack as a typed array.\n * @param transaction - The transaction to sign\n * @param metadata - multisig metadata\n * @param signerAddr - address of the signer\n * @param signature - raw multisig signature\n * @returns an encoded, partially signed multisig transaction.\n */\nfunction partialSignWithMultisigSignature(\n transaction: Transaction,\n metadata: MultisigMetadataWithPublicKeys,\n signerAddr: string | Address,\n signature: Uint8Array,\n) {\n if (signature.length != SIGNATURE_BYTE_LENGTH) {\n throw new Error(MULTISIG_SIGNATURE_LENGTH_ERROR_MSG)\n }\n const signerAddressObj = typeof signerAddr === 'string' ? Address.fromString(signerAddr) : signerAddr\n return createMultisigTransactionWithSignature(\n transaction,\n {\n rawSig: signature,\n myPk: signerAddressObj.publicKey,\n },\n metadata,\n )\n}\n\n/**\n * Takes a multisig transaction blob, and appends a given raw signature to it.\n * This makes it possible to compile a multisig signature using only raw signatures from external methods.\n * @param multisigTxnBlob - an encoded multisig txn. Supports non-payment txn types.\n * @param version - multisig version\n * @param threshold - multisig threshold\n * @param addrs - a list of Algorand addresses representing possible signers for this multisig. Order is important.\n * @param signerAddr - address of the signer\n * @param signature - raw multisig signature\n * @returns object containing txID, and blob representing encoded multisig txn\n */\nfunction appendSignRawMultisigSignature(\n multisigTxn: SignedTransaction,\n { version, threshold, addrs }: MultisigMetadata,\n signerAddr: string | Address,\n signature: Uint8Array,\n): SignedTransaction {\n const publicKeys = toPublicKeys(addrs)\n // obtain underlying txn, sign it, and merge it\n const partialSigned = partialSignWithMultisigSignature(multisigTxn.txn, { version, threshold, publicKeys }, signerAddr, signature)\n return mergeMultisigTransactions([multisigTxn, partialSigned])\n}\n\n/**\n * Takes multisig parameters and returns a 32 byte typed array public key,\n * representing an address that identifies the \"exact group, version, and public keys\" that are required for signing.\n * Hash(\"MultisigAddr\" || version uint8 || threshold uint8 || PK1 || PK2 || ...)\n * Encoding this output yields a human readable address.\n * @param version - multisig version\n * @param threshold - multisig threshold\n * @param pks - array of typed array public keys\n */\nfunction addressFromMultisigPreImg({\n version,\n threshold,\n publicKeys,\n}: Omit<MultisigMetadata, 'addrs'> & {\n publicKeys: Uint8Array[]\n}): Address {\n if (version > 255 || version < 0) {\n // ^ a tad redundant, but in case in the future version != 1, still check for uint8\n throw new Error(`${INVALID_MSIG_VERSION_ERROR_MSG}: ${version}`)\n }\n if (threshold === 0 || publicKeys.length === 0 || threshold > publicKeys.length || threshold > 255) {\n throw new Error(INVALID_MSIG_THRESHOLD_ERROR_MSG)\n }\n const pkLen = ALGORAND_ADDRESS_BYTE_LENGTH - ALGORAND_CHECKSUM_BYTE_LENGTH\n if (pkLen !== PUBLIC_KEY_BYTE_LENGTH) {\n throw new Error(UNEXPECTED_PK_LEN_ERROR_MSG)\n }\n const merged = new Uint8Array(MULTISIG_PREIMG2ADDR_PREFIX.length + 2 + pkLen * publicKeys.length)\n merged.set(MULTISIG_PREIMG2ADDR_PREFIX, 0)\n merged.set([version], MULTISIG_PREIMG2ADDR_PREFIX.length)\n merged.set([threshold], MULTISIG_PREIMG2ADDR_PREFIX.length + 1)\n for (let i = 0; i < publicKeys.length; i++) {\n if (publicKeys[i].length !== pkLen) {\n throw new Error(INVALID_MSIG_PK_ERROR_MSG)\n }\n merged.set(publicKeys[i], MULTISIG_PREIMG2ADDR_PREFIX.length + 2 + i * pkLen)\n }\n return new Address(Uint8Array.from(hash(merged)))\n}\n\n/**\n * Takes multisig parameters and returns a human readable Algorand address.\n * This is equivalent to fromMultisigPreImg, but interfaces with encoded addresses.\n * @param version - multisig version\n * @param threshold - multisig threshold\n * @param addrs - array of encoded addresses\n */\nfunction addressFromMultisigPreImgAddrs({ version, threshold, addrs }: MultisigMetadata): Address {\n return addressFromMultisigPreImg({\n version,\n threshold,\n publicKeys: toPublicKeys(addrs),\n })\n}\n\n/**\n * Takes multisig metadata (preimage) and returns the corresponding human readable Algorand address.\n * @param version - multisig version\n * @param threshold - multisig threshold\n * @param addrs - list of Algorand addresses\n */\nconst multisigAddress: typeof addressFromMultisigPreImgAddrs = addressFromMultisigPreImgAddrs\n\nexport interface MultisigMetadata {\n /**\n * Multisig version\n */\n version: number\n\n /**\n * Multisig threshold value. Authorization requires a subset of signatures,\n * equal to or greater than the threshold value.\n */\n threshold: number\n\n /**\n * A list of Algorand addresses representing possible signers for this multisig. Order is important.\n */\n addrs: Array<Address>\n}\n\n/** Account wrapper that supports partial or full multisig signing. */\nexport class MultisigAccount implements AddressWithTransactionSigner, AddressWithDelegatedLsigSigner {\n _params: MultisigMetadata\n _subSigners: (AddressWithTransactionSigner & AddressWithDelegatedLsigSigner)[]\n _addr: Address\n _signer: TransactionSigner\n _lsigSigner: DelegatedLsigSigner\n\n /** The parameters for the multisig account */\n get params(): Readonly<MultisigMetadata> {\n return this._params\n }\n\n /** The list of accounts that are present to sign transactions or lsigs */\n get subSigners() {\n return this._subSigners\n }\n\n /** The address of the multisig account */\n get addr(): Readonly<Address> {\n return this._addr\n }\n\n /** The transaction signer for the multisig account */\n get signer(): TransactionSigner {\n return this._signer\n }\n\n get lsigSigner(): DelegatedLsigSigner {\n return this._lsigSigner\n }\n\n static fromSignature(signature: MultisigSignature): MultisigAccount {\n const params: MultisigMetadata = {\n version: signature.version,\n threshold: signature.threshold,\n addrs: signature.subsigs.map((subsig) => new Address(subsig.publicKey)),\n }\n\n return new MultisigAccount(params, [])\n }\n\n constructor(multisigParams: MultisigMetadata, subSigners: (AddressWithTransactionSigner & AddressWithDelegatedLsigSigner)[]) {\n this._params = multisigParams\n this._subSigners = subSigners\n this._addr = multisigAddress(multisigParams)\n this._signer = async (txns: Transaction[], indexesToSign: number[]): Promise<Uint8Array[]> => {\n const txnsToSign = txns.filter((_, index) => indexesToSign.includes(index))\n const signedMsigTxns: SignedTransaction[] = []\n\n for (const txn of txnsToSign) {\n let signedMsigTxn = createMultisigTransaction(txn, this._params)\n\n for (const subSigner of this.subSigners) {\n const stxn = (await subSigner.signer([txn], [0]))[0]\n const sig = decodeSignedTransaction(stxn).sig\n\n if (!sig) {\n throw new Error(\n `Signer for address ${subSigner.addr.toString()} did not produce a valid signature when signing ${txn.txId()} for multisig account ${this._addr.toString()}`,\n )\n }\n\n signedMsigTxn = appendSignRawMultisigSignature(signedMsigTxn, this._params, subSigner.addr, sig)\n }\n\n signedMsigTxns.push(signedMsigTxn)\n }\n\n return signedMsigTxns.map(encodeSignedTransaction)\n }\n\n this._lsigSigner = async (lsig, _) => {\n let lmsig = lsig.lmsig ?? this.createMultisigSignature()\n\n for (const addrWithSigner of this.subSigners) {\n const { lsigSigner, addr } = addrWithSigner\n const result = await lsigSigner(lsig, this)\n if (!('sig' in result) || !result.sig) {\n throw new Error(\n `Signer for address ${addr.toString()} did not produce a valid signature when signing logic sig for multisig account ${this._addr.toString()}`,\n )\n }\n\n lmsig = this.applySignature(lmsig, addr.publicKey, result.sig)\n }\n\n return { addr: this.addr, lmsig }\n }\n }\n\n createMultisigTransaction(txn: Transaction): SignedTransaction {\n return createMultisigTransaction(txn, this._params)\n }\n\n createMultisigSignature(): MultisigSignature {\n const pks = toPublicKeys(this._params.addrs)\n const subsignatures: MultisigSubsignature[] = pks.map((pk) => ({\n publicKey: pk,\n signature: undefined,\n }))\n\n return {\n version: this._params.version,\n threshold: this._params.threshold,\n subsigs: subsignatures,\n }\n }\n\n applySignatureToTxn(txn: SignedTransaction, pubkey: Uint8Array, signature: Uint8Array): void {\n if (!txn.msig) {\n const createdTxn = this.createMultisigTransaction(txn.txn)\n txn.msig = createdTxn.msig\n }\n\n txn.msig = applyMultisigSubsignature(txn.msig!, pubkey, signature)\n }\n\n applySignature(msigSignature: MultisigSignature, pubkey: Uint8Array, signature: Uint8Array): MultisigSignature {\n if (msigSignature.version !== this._params.version || msigSignature.threshold !== this._params.threshold) {\n const thisParams = {\n version: this._params.version,\n threshold: this._params.threshold,\n participants: this._params.addrs.map((addr) => addr.toString()),\n }\n\n const givenParams = {\n version: msigSignature.version,\n threshold: msigSignature.threshold,\n participants: msigSignature.subsigs.map((subsig) => new Address(subsig.publicKey).toString()),\n }\n\n throw new Error(\n `Multisig signature parameters do not match expected multisig parameters. Multisig params: ${JSON.stringify(thisParams)}, signature: ${JSON.stringify(givenParams)}`,\n )\n }\n\n return applyMultisigSubsignature(msigSignature, pubkey, signature)\n }\n}\n"],"mappings":";;;;;;;AAqBA,MAAM,gBAAgB,UAAiD,MAAM,KAAK,SAASA,2BAAW,KAAK,CAAC,UAAU;;;;;;;AAQtH,SAAS,0BACP,mBACA,aACA,WACmB;CACnB,IAAI,QAAQ;CACZ,MAAM,mBAAmB,kBAAkB,QAAQ,KAAK,WAAW;AACjE,MAAIC,yBAAW,OAAO,WAAW,YAAY,EAAE;AAC7C,WAAQ;AACR,UAAO;IAAE,GAAG;IAAQ,KAAK;IAAW;;AAEtC,SAAO;GACP;AAEF,KAAI,CAAC,MACH,OAAM,IAAI,MAAM,6CAA6C;AAG/D,QAAO;EACL,GAAG;EACH,SAAS;EACV;;AAIH,MAAM,8BAA8B,IAAI,WAAW;CAAC;CAAI;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAI;CAAK;CAAK;CAAI,CAAC;AAE9G,MAAM,iCAAiC;AACvC,MAAM,mCAAmC;AACzC,MAAM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c,QAAQ,KAAK,WAAW,IAAIX,wBAAQ,OAAO,UAAU,CAAC,UAAU,CAAC;IAC9F;AAED,SAAM,IAAI,MACR,6FAA6F,KAAK,UAAU,WAAW,CAAC,eAAe,KAAK,UAAU,YAAY,GACnK;;AAGH,SAAO,0BAA0B,eAAe,QAAQ,UAAU"}
@@ -254,6 +254,7 @@ var MultisigAccount = class MultisigAccount {
254
254
  _subSigners;
255
255
  _addr;
256
256
  _signer;
257
+ _lsigSigner;
257
258
  /** The parameters for the multisig account */
258
259
  get params() {
259
260
  return this._params;
@@ -270,6 +271,9 @@ var MultisigAccount = class MultisigAccount {
270
271
  get signer() {
271
272
  return this._signer;
272
273
  }
274
+ get lsigSigner() {
275
+ return this._lsigSigner;
276
+ }
273
277
  static fromSignature(signature) {
274
278
  return new MultisigAccount({
275
279
  version: signature.version,
@@ -296,6 +300,19 @@ var MultisigAccount = class MultisigAccount {
296
300
  }
297
301
  return signedMsigTxns.map(encodeSignedTransaction);
298
302
  };
303
+ this._lsigSigner = async (lsig, _) => {
304
+ let lmsig = lsig.lmsig ?? this.createMultisigSignature();
305
+ for (const addrWithSigner of this.subSigners) {
306
+ const { lsigSigner, addr } = addrWithSigner;
307
+ const result = await lsigSigner(lsig, this);
308
+ if (!("sig" in result) || !result.sig) throw new Error(`Signer for address ${addr.toString()} did not produce a valid signature when signing logic sig for multisig account ${this._addr.toString()}`);
309
+ lmsig = this.applySignature(lmsig, addr.publicKey, result.sig);
310
+ }
311
+ return {
312
+ addr: this.addr,
313
+ lmsig
314
+ };
315
+ };
299
316
  }
300
317
  createMultisigTransaction(txn) {
301
318
  return createMultisigTransaction(txn, this._params);
@@ -1 +1 @@
1
- {"version":3,"file":"multisig.mjs","names":["msig: MultisigSignature","authAddress: Address | undefined","newSubsigs: MultisigSubsignature[]","multisigAddress: typeof addressFromMultisigPreImgAddrs","signedMsigTxns: SignedTransaction[]","subsignatures: MultisigSubsignature[]"],"sources":["../../../../packages/transact/src/multisig.ts"],"sourcesContent":["import {\n Address,\n ALGORAND_ADDRESS_BYTE_LENGTH,\n ALGORAND_CHECKSUM_BYTE_LENGTH,\n arrayEqual,\n getAddress,\n hash,\n PUBLIC_KEY_BYTE_LENGTH,\n SIGNATURE_BYTE_LENGTH,\n} from '@algorandfoundation/algokit-common'\nimport { AddressWithDelegatedLsigSigner, AddressWithTransactionSigner, TransactionSigner } from './signer'\nimport {\n decodeSignedTransaction,\n encodeSignedTransaction,\n MultisigSignature,\n MultisigSubsignature,\n SignedTransaction,\n} from './transactions/signed-transaction'\nimport { Transaction } from './transactions/transaction'\n\nconst toPublicKeys = (addrs: Array<string | Address>): Uint8Array[] => addrs.map((addr) => getAddress(addr).publicKey)\n\n/**\n * Applies a subsignature for a participant to a multisignature signature, replacing any existing signature.\n *\n * This method applies the signature to ALL instances of the given public key (to support weighted multisig).\n * Since ed25519 signatures are deterministic, there's only one valid signature for a given message and public key.\n */\nfunction applyMultisigSubsignature(\n multisigSignature: MultisigSignature,\n participant: Uint8Array,\n signature: Uint8Array,\n): MultisigSignature {\n let found = false\n const newSubsignatures = multisigSignature.subsigs.map((subsig) => {\n if (arrayEqual(subsig.publicKey, participant)) {\n found = true\n return { ...subsig, sig: signature } satisfies MultisigSubsignature\n }\n return subsig\n })\n\n if (!found) {\n throw new Error('Public key not found in multisig signature')\n }\n\n return {\n ...multisigSignature,\n subsigs: newSubsignatures,\n }\n}\n\n// Convert \"MultisigAddr\" UTF-8 to byte array\nconst MULTISIG_PREIMG2ADDR_PREFIX = new Uint8Array([77, 117, 108, 116, 105, 115, 105, 103, 65, 100, 100, 114])\n\nconst INVALID_MSIG_VERSION_ERROR_MSG = 'invalid multisig version'\nconst INVALID_MSIG_THRESHOLD_ERROR_MSG = 'bad multisig threshold'\nconst INVALID_MSIG_PK_ERROR_MSG = 'bad multisig public key - wrong length'\nconst UNEXPECTED_PK_LEN_ERROR_MSG = 'nacl public key length is not 32 bytes'\n\nconst MULTISIG_MERGE_LESSTHANTWO_ERROR_MSG = 'Not enough multisig transactions to merge. Need at least two'\nconst MULTISIG_MERGE_MISMATCH_ERROR_MSG = 'Cannot merge txs. txIDs differ'\nconst MULTISIG_MERGE_MISMATCH_AUTH_ADDR_MSG = 'Cannot merge txs. Auth addrs differ'\nconst MULTISIG_MERGE_WRONG_PREIMAGE_ERROR_MSG = 'Cannot merge txs. Multisig preimages differ'\nconst MULTISIG_MERGE_SIG_MISMATCH_ERROR_MSG = 'Cannot merge txs. subsigs are mismatched.'\nconst MULTISIG_SIGNATURE_LENGTH_ERROR_MSG = 'Cannot add multisig signature. Signature is not of the correct length.'\nconst MULTISIG_KEY_NOT_EXIST_ERROR_MSG = 'Key does not exist'\n\n/**\n * creates a raw, multisig transaction blob without any signatures.\n * @param txn - the actual transaction.\n * @param version - multisig version\n * @param threshold - multisig threshold\n * @param pks - ordered list of public keys in this multisig\n * @returns encoded multisig blob\n */\nfunction createMultisigTransaction(txn: Transaction, { version, threshold, addrs }: MultisigMetadata) {\n // construct the appendable multisigned transaction format\n const pks = toPublicKeys(addrs)\n const subsignatures = pks.map(\n (pk) =>\n ({\n publicKey: pk,\n sig: undefined,\n }) satisfies MultisigSubsignature,\n )\n\n const msig: MultisigSignature = {\n version,\n threshold,\n subsigs: subsignatures,\n }\n\n // if the address of this multisig is different from the transaction sender,\n // we need to add the auth-addr field\n const msigAddr = addressFromMultisigPreImg({\n version,\n threshold,\n publicKeys: pks,\n })\n let authAddress: Address | undefined\n if (!msigAddr.equals(txn.sender)) {\n authAddress = msigAddr\n }\n\n const signedTxn: SignedTransaction = {\n txn: txn,\n msig: msig,\n authAddress,\n }\n\n return signedTxn\n}\n\ninterface MultisigOptions {\n rawSig: Uint8Array\n myPk: Uint8Array\n}\n\ninterface MultisigMetadataWithPublicKeys extends Omit<MultisigMetadata, 'addrs'> {\n publicKeys: Uint8Array[]\n}\n\n/**\n * creates a multisig transaction blob with an included signature.\n * @param txn - the actual transaction to sign.\n * @param rawSig - a Uint8Array raw signature of that transaction\n * @param myPk - a public key that corresponds with rawSig\n * @param version - multisig version\n * @param threshold - multisig threshold\n * @param pks - ordered list of public keys in this multisig\n * @returns encoded multisig blob\n */\nfunction createMultisigTransactionWithSignature(\n txn: Transaction,\n { rawSig, myPk }: MultisigOptions,\n { version, threshold, publicKeys }: MultisigMetadataWithPublicKeys,\n): SignedTransaction {\n // Create an empty encoded multisig transaction\n const signedTxn = createMultisigTransaction(txn, {\n version,\n threshold,\n addrs: publicKeys.map((pk) => new Address(pk)),\n })\n\n let keyExist = false\n\n // append the multisig signature to the corresponding public key in the multisig blob\n const updatedSubsigs = signedTxn.msig!.subsigs.map((subsig) => {\n if (arrayEqual(subsig.publicKey, myPk)) {\n keyExist = true\n return { ...subsig, sig: rawSig }\n }\n return subsig\n })\n\n if (!keyExist) {\n throw new Error(MULTISIG_KEY_NOT_EXIST_ERROR_MSG)\n }\n\n const updatedSignedTxn: SignedTransaction = {\n ...signedTxn,\n msig: {\n ...signedTxn.msig!,\n subsigs: updatedSubsigs,\n },\n }\n\n return updatedSignedTxn\n}\n\n/**\n * takes a list of multisig transaction blobs, and merges them.\n * @param multisigTxnBlobs - a list of blobs representing encoded multisig txns\n * @returns typed array msg-pack encoded multisig txn\n */\nfunction mergeMultisigTransactions(multisigTxnBlobs: SignedTransaction[]): SignedTransaction {\n if (multisigTxnBlobs.length < 2) {\n throw new Error(MULTISIG_MERGE_LESSTHANTWO_ERROR_MSG)\n }\n const refSigTx = multisigTxnBlobs[0]\n if (!refSigTx.msig) {\n throw new Error('Invalid multisig transaction, multisig structure missing at index 0')\n }\n const refTxID = refSigTx.txn.txId()\n const refAuthAddr = refSigTx.authAddress\n const refPreImage = {\n version: refSigTx.msig.version,\n threshold: refSigTx.msig.threshold,\n publicKeys: refSigTx.msig.subsigs.map((subsig) => subsig.publicKey),\n }\n const refMsigAddr = addressFromMultisigPreImg(refPreImage)\n\n const newSubsigs: MultisigSubsignature[] = refSigTx.msig.subsigs.map((sig) => ({ ...sig }))\n for (let i = 1; i < multisigTxnBlobs.length; i++) {\n const unisig = multisigTxnBlobs[i]\n if (!unisig.msig) {\n throw new Error(`Invalid multisig transaction, multisig structure missing at index ${i}`)\n }\n\n if (unisig.txn.txId() !== refTxID) {\n throw new Error(MULTISIG_MERGE_MISMATCH_ERROR_MSG)\n }\n\n const authAddr = unisig.authAddress\n if (refAuthAddr !== authAddr) {\n throw new Error(MULTISIG_MERGE_MISMATCH_AUTH_ADDR_MSG)\n }\n\n // check multisig has same preimage as reference\n if (unisig.msig.subsigs.length !== refSigTx.msig.subsigs.length) {\n throw new Error(MULTISIG_MERGE_WRONG_PREIMAGE_ERROR_MSG)\n }\n const preimg: MultisigMetadataWithPublicKeys = {\n version: unisig.msig.version,\n threshold: unisig.msig.threshold,\n publicKeys: unisig.msig.subsigs.map((subsig) => subsig.publicKey),\n }\n const msgigAddr = addressFromMultisigPreImg(preimg)\n if (refMsigAddr.toString() !== msgigAddr.toString()) {\n throw new Error(MULTISIG_MERGE_WRONG_PREIMAGE_ERROR_MSG)\n }\n\n // now, we can merge\n unisig.msig.subsigs.forEach((uniSubsig, index) => {\n if (!uniSubsig.sig) return\n const current = newSubsigs[index]\n if (current.sig && !arrayEqual(uniSubsig.sig, current.sig)) {\n // mismatch\n throw new Error(MULTISIG_MERGE_SIG_MISMATCH_ERROR_MSG)\n }\n current.sig = uniSubsig.sig\n })\n }\n\n const msig: MultisigSignature = {\n version: refSigTx.msig.version,\n threshold: refSigTx.msig.threshold,\n subsigs: newSubsigs,\n }\n\n const signedTxn: SignedTransaction = {\n txn: refSigTx.txn,\n msig: msig,\n authAddress: refAuthAddr,\n }\n\n return signedTxn\n}\n\n/**\n * Partially signs this transaction with an external raw multisig signature and returns\n * a partially-signed multisig transaction, encoded with msgpack as a typed array.\n * @param transaction - The transaction to sign\n * @param metadata - multisig metadata\n * @param signerAddr - address of the signer\n * @param signature - raw multisig signature\n * @returns an encoded, partially signed multisig transaction.\n */\nfunction partialSignWithMultisigSignature(\n transaction: Transaction,\n metadata: MultisigMetadataWithPublicKeys,\n signerAddr: string | Address,\n signature: Uint8Array,\n) {\n if (signature.length != SIGNATURE_BYTE_LENGTH) {\n throw new Error(MULTISIG_SIGNATURE_LENGTH_ERROR_MSG)\n }\n const signerAddressObj = typeof signerAddr === 'string' ? Address.fromString(signerAddr) : signerAddr\n return createMultisigTransactionWithSignature(\n transaction,\n {\n rawSig: signature,\n myPk: signerAddressObj.publicKey,\n },\n metadata,\n )\n}\n\n/**\n * Takes a multisig transaction blob, and appends a given raw signature to it.\n * This makes it possible to compile a multisig signature using only raw signatures from external methods.\n * @param multisigTxnBlob - an encoded multisig txn. Supports non-payment txn types.\n * @param version - multisig version\n * @param threshold - multisig threshold\n * @param addrs - a list of Algorand addresses representing possible signers for this multisig. Order is important.\n * @param signerAddr - address of the signer\n * @param signature - raw multisig signature\n * @returns object containing txID, and blob representing encoded multisig txn\n */\nfunction appendSignRawMultisigSignature(\n multisigTxn: SignedTransaction,\n { version, threshold, addrs }: MultisigMetadata,\n signerAddr: string | Address,\n signature: Uint8Array,\n): SignedTransaction {\n const publicKeys = toPublicKeys(addrs)\n // obtain underlying txn, sign it, and merge it\n const partialSigned = partialSignWithMultisigSignature(multisigTxn.txn, { version, threshold, publicKeys }, signerAddr, signature)\n return mergeMultisigTransactions([multisigTxn, partialSigned])\n}\n\n/**\n * Takes multisig parameters and returns a 32 byte typed array public key,\n * representing an address that identifies the \"exact group, version, and public keys\" that are required for signing.\n * Hash(\"MultisigAddr\" || version uint8 || threshold uint8 || PK1 || PK2 || ...)\n * Encoding this output yields a human readable address.\n * @param version - multisig version\n * @param threshold - multisig threshold\n * @param pks - array of typed array public keys\n */\nfunction addressFromMultisigPreImg({\n version,\n threshold,\n publicKeys,\n}: Omit<MultisigMetadata, 'addrs'> & {\n publicKeys: Uint8Array[]\n}): Address {\n if (version > 255 || version < 0) {\n // ^ a tad redundant, but in case in the future version != 1, still check for uint8\n throw new Error(`${INVALID_MSIG_VERSION_ERROR_MSG}: ${version}`)\n }\n if (threshold === 0 || publicKeys.length === 0 || threshold > publicKeys.length || threshold > 255) {\n throw new Error(INVALID_MSIG_THRESHOLD_ERROR_MSG)\n }\n const pkLen = ALGORAND_ADDRESS_BYTE_LENGTH - ALGORAND_CHECKSUM_BYTE_LENGTH\n if (pkLen !== PUBLIC_KEY_BYTE_LENGTH) {\n throw new Error(UNEXPECTED_PK_LEN_ERROR_MSG)\n }\n const merged = new Uint8Array(MULTISIG_PREIMG2ADDR_PREFIX.length + 2 + pkLen * publicKeys.length)\n merged.set(MULTISIG_PREIMG2ADDR_PREFIX, 0)\n merged.set([version], MULTISIG_PREIMG2ADDR_PREFIX.length)\n merged.set([threshold], MULTISIG_PREIMG2ADDR_PREFIX.length + 1)\n for (let i = 0; i < publicKeys.length; i++) {\n if (publicKeys[i].length !== pkLen) {\n throw new Error(INVALID_MSIG_PK_ERROR_MSG)\n }\n merged.set(publicKeys[i], MULTISIG_PREIMG2ADDR_PREFIX.length + 2 + i * pkLen)\n }\n return new Address(Uint8Array.from(hash(merged)))\n}\n\n/**\n * Takes multisig parameters and returns a human readable Algorand address.\n * This is equivalent to fromMultisigPreImg, but interfaces with encoded addresses.\n * @param version - multisig version\n * @param threshold - multisig threshold\n * @param addrs - array of encoded addresses\n */\nfunction addressFromMultisigPreImgAddrs({ version, threshold, addrs }: MultisigMetadata): Address {\n return addressFromMultisigPreImg({\n version,\n threshold,\n publicKeys: toPublicKeys(addrs),\n })\n}\n\n/**\n * Takes multisig metadata (preimage) and returns the corresponding human readable Algorand address.\n * @param version - multisig version\n * @param threshold - multisig threshold\n * @param addrs - list of Algorand addresses\n */\nconst multisigAddress: typeof addressFromMultisigPreImgAddrs = addressFromMultisigPreImgAddrs\n\nexport interface MultisigMetadata {\n /**\n * Multisig version\n */\n version: number\n\n /**\n * Multisig threshold value. Authorization requires a subset of signatures,\n * equal to or greater than the threshold value.\n */\n threshold: number\n\n /**\n * A list of Algorand addresses representing possible signers for this multisig. Order is important.\n */\n addrs: Array<Address>\n}\n\n/** Account wrapper that supports partial or full multisig signing. */\nexport class MultisigAccount implements AddressWithTransactionSigner {\n _params: MultisigMetadata\n _subSigners: (AddressWithTransactionSigner & AddressWithDelegatedLsigSigner)[]\n _addr: Address\n _signer: TransactionSigner\n\n /** The parameters for the multisig account */\n get params(): Readonly<MultisigMetadata> {\n return this._params\n }\n\n /** The list of accounts that are present to sign transactions or lsigs */\n get subSigners() {\n return this._subSigners\n }\n\n /** The address of the multisig account */\n get addr(): Readonly<Address> {\n return this._addr\n }\n\n /** The transaction signer for the multisig account */\n get signer(): TransactionSigner {\n return this._signer\n }\n\n static fromSignature(signature: MultisigSignature): MultisigAccount {\n const params: MultisigMetadata = {\n version: signature.version,\n threshold: signature.threshold,\n addrs: signature.subsigs.map((subsig) => new Address(subsig.publicKey)),\n }\n\n return new MultisigAccount(params, [])\n }\n\n constructor(multisigParams: MultisigMetadata, subSigners: (AddressWithTransactionSigner & AddressWithDelegatedLsigSigner)[]) {\n this._params = multisigParams\n this._subSigners = subSigners\n this._addr = multisigAddress(multisigParams)\n this._signer = async (txns: Transaction[], indexesToSign: number[]): Promise<Uint8Array[]> => {\n const txnsToSign = txns.filter((_, index) => indexesToSign.includes(index))\n const signedMsigTxns: SignedTransaction[] = []\n\n for (const txn of txnsToSign) {\n let signedMsigTxn = createMultisigTransaction(txn, this._params)\n\n for (const subSigner of this.subSigners) {\n const stxn = (await subSigner.signer([txn], [0]))[0]\n const sig = decodeSignedTransaction(stxn).sig\n\n if (!sig) {\n throw new Error(\n `Signer for address ${subSigner.addr.toString()} did not produce a valid signature when signing ${txn.txId()} for multisig account ${this._addr.toString()}`,\n )\n }\n\n signedMsigTxn = appendSignRawMultisigSignature(signedMsigTxn, this._params, subSigner.addr, sig)\n }\n\n signedMsigTxns.push(signedMsigTxn)\n }\n\n return signedMsigTxns.map(encodeSignedTransaction)\n }\n }\n\n createMultisigTransaction(txn: Transaction): SignedTransaction {\n return createMultisigTransaction(txn, this._params)\n }\n\n createMultisigSignature(): MultisigSignature {\n const pks = toPublicKeys(this._params.addrs)\n const subsignatures: MultisigSubsignature[] = pks.map((pk) => ({\n publicKey: pk,\n signature: undefined,\n }))\n\n return {\n version: this._params.version,\n threshold: this._params.threshold,\n subsigs: subsignatures,\n }\n }\n\n applySignatureToTxn(txn: SignedTransaction, pubkey: Uint8Array, signature: Uint8Array): void {\n if (!txn.msig) {\n const createdTxn = this.createMultisigTransaction(txn.txn)\n txn.msig = createdTxn.msig\n }\n\n txn.msig = applyMultisigSubsignature(txn.msig!, pubkey, signature)\n }\n\n applySignature(msigSignature: MultisigSignature, pubkey: Uint8Array, signature: Uint8Array): MultisigSignature {\n if (msigSignature.version !== this._params.version || msigSignature.threshold !== this._params.threshold) {\n const thisParams = {\n version: this._params.version,\n threshold: this._params.threshold,\n participants: this._params.addrs.map((addr) => addr.toString()),\n }\n\n const givenParams = {\n version: msigSignature.version,\n threshold: msigSignature.threshold,\n participants: msigSignature.subsigs.map((subsig) => new Address(subsig.publicKey).toString()),\n }\n\n throw new Error(\n `Multisig signature parameters do not match expected multisig parameters. Multisig params: ${JSON.stringify(thisParams)}, signature: ${JSON.stringify(givenParams)}`,\n )\n }\n\n return applyMultisigSubsignature(msigSignature, pubkey, signature)\n }\n}\n"],"mappings":";;;;;;;AAoBA,MAAM,gBAAgB,UAAiD,MAAM,KAAK,SAAS,WAAW,KAAK,CAAC,UAAU;;;;;;;AAQtH,SAAS,0BACP,mBACA,aACA,WACmB;CACnB,IAAI,QAAQ;CACZ,MAAM,mBAAmB,kBAAkB,QAAQ,KAAK,WAAW;AACjE,MAAI,WAAW,OAAO,WAAW,YAAY,EAAE;AAC7C,WAAQ;AACR,UAAO;IAAE,GAAG;IAAQ,KAAK;IAAW;;AAEtC,SAAO;GACP;AAEF,KAAI,CAAC,MACH,OAAM,IAAI,MAAM,6CAA6C;AAG/D,QAAO;EACL,GAAG;EACH,SAAS;EACV;;AAIH,MAAM,8BAA8B,IAAI,WAAW;CAAC;CAAI;CAAK;C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,qBAAgB,+BAA+B,eAAe,KAAK,SAAS,UAAU,MAAM,IAAI;;AAGlG,mBAAe,KAAK,cAAc;;AAGpC,UAAO,eAAe,IAAI,wBAAwB;;;CAItD,0BAA0B,KAAqC;AAC7D,SAAO,0BAA0B,KAAK,KAAK,QAAQ;;CAGrD,0BAA6C;EAE3C,MAAMC,gBADM,aAAa,KAAK,QAAQ,MAAM,CACM,KAAK,QAAQ;GAC7D,WAAW;GACX,WAAW;GACZ,EAAE;AAEH,SAAO;GACL,SAAS,KAAK,QAAQ;GACtB,WAAW,KAAK,QAAQ;GACxB,SAAS;GACV;;CAGH,oBAAoB,KAAwB,QAAoB,WAA6B;AAC3F,MAAI,CAAC,IAAI,KAEP,KAAI,OADe,KAAK,0BAA0B,IAAI,IAAI,CACpC;AAGxB,MAAI,OAAO,0BAA0B,IAAI,MAAO,QAAQ,UAAU;;CAGpE,eAAe,eAAkC,QAAoB,WAA0C;AAC7G,MAAI,cAAc,YAAY,KAAK,QAAQ,WAAW,cAAc,cAAc,KAAK,QAAQ,WAAW;GACxG,MAAM,aAAa;IACjB,SAAS,KAAK,QAAQ;IACtB,WAAW,KAAK,QAAQ;IACxB,cAAc,KAAK,QAAQ,MAAM,KAAK,SAAS,KAAK,UAAU,CAAC;IAChE;GAED,MAAM,cAAc;IAClB,SAAS,cAAc;IACvB,WAAW,cAAc;IACzB,cAAc,cAAc,QAAQ,KAAK,WAAW,IAAI,QAAQ,OAAO,UAAU,CAAC,UAAU,CAAC;IAC9F;AAED,SAAM,IAAI,MACR,6FAA6F,KAAK,UAAU,WAAW,CAAC,eAAe,KAAK,UAAU,YAAY,GACnK;;AAGH,SAAO,0BAA0B,eAAe,QAAQ,UAAU"}
1
+ {"version":3,"file":"multisig.mjs","names":["msig: MultisigSignature","authAddress: Address | undefined","newSubsigs: MultisigSubsignature[]","multisigAddress: typeof addressFromMultisigPreImgAddrs","signedMsigTxns: SignedTransaction[]","subsignatures: MultisigSubsignature[]"],"sources":["../../../../packages/transact/src/multisig.ts"],"sourcesContent":["import {\n Address,\n ALGORAND_ADDRESS_BYTE_LENGTH,\n ALGORAND_CHECKSUM_BYTE_LENGTH,\n arrayEqual,\n getAddress,\n hash,\n PUBLIC_KEY_BYTE_LENGTH,\n SIGNATURE_BYTE_LENGTH,\n} from '@algorandfoundation/algokit-common'\nimport { AddressWithDelegatedLsigSigner, AddressWithTransactionSigner, TransactionSigner } from './signer'\nimport {\n decodeSignedTransaction,\n encodeSignedTransaction,\n MultisigSignature,\n MultisigSubsignature,\n SignedTransaction,\n} from './transactions/signed-transaction'\nimport { Transaction } from './transactions/transaction'\nimport { DelegatedLsigSigner } from './logicsig'\n\nconst toPublicKeys = (addrs: Array<string | Address>): Uint8Array[] => addrs.map((addr) => getAddress(addr).publicKey)\n\n/**\n * Applies a subsignature for a participant to a multisignature signature, replacing any existing signature.\n *\n * This method applies the signature to ALL instances of the given public key (to support weighted multisig).\n * Since ed25519 signatures are deterministic, there's only one valid signature for a given message and public key.\n */\nfunction applyMultisigSubsignature(\n multisigSignature: MultisigSignature,\n participant: Uint8Array,\n signature: Uint8Array,\n): MultisigSignature {\n let found = false\n const newSubsignatures = multisigSignature.subsigs.map((subsig) => {\n if (arrayEqual(subsig.publicKey, participant)) {\n found = true\n return { ...subsig, sig: signature } satisfies MultisigSubsignature\n }\n return subsig\n })\n\n if (!found) {\n throw new Error('Public key not found in multisig signature')\n }\n\n return {\n ...multisigSignature,\n subsigs: newSubsignatures,\n }\n}\n\n// Convert \"MultisigAddr\" UTF-8 to byte array\nconst MULTISIG_PREIMG2ADDR_PREFIX = new Uint8Array([77, 117, 108, 116, 105, 115, 105, 103, 65, 100, 100, 114])\n\nconst INVALID_MSIG_VERSION_ERROR_MSG = 'invalid multisig version'\nconst INVALID_MSIG_THRESHOLD_ERROR_MSG = 'bad multisig threshold'\nconst INVALID_MSIG_PK_ERROR_MSG = 'bad multisig public key - wrong length'\nconst UNEXPECTED_PK_LEN_ERROR_MSG = 'nacl public key length is not 32 bytes'\n\nconst MULTISIG_MERGE_LESSTHANTWO_ERROR_MSG = 'Not enough multisig transactions to merge. Need at least two'\nconst MULTISIG_MERGE_MISMATCH_ERROR_MSG = 'Cannot merge txs. txIDs differ'\nconst MULTISIG_MERGE_MISMATCH_AUTH_ADDR_MSG = 'Cannot merge txs. Auth addrs differ'\nconst MULTISIG_MERGE_WRONG_PREIMAGE_ERROR_MSG = 'Cannot merge txs. Multisig preimages differ'\nconst MULTISIG_MERGE_SIG_MISMATCH_ERROR_MSG = 'Cannot merge txs. subsigs are mismatched.'\nconst MULTISIG_SIGNATURE_LENGTH_ERROR_MSG = 'Cannot add multisig signature. Signature is not of the correct length.'\nconst MULTISIG_KEY_NOT_EXIST_ERROR_MSG = 'Key does not exist'\n\n/**\n * creates a raw, multisig transaction blob without any signatures.\n * @param txn - the actual transaction.\n * @param version - multisig version\n * @param threshold - multisig threshold\n * @param pks - ordered list of public keys in this multisig\n * @returns encoded multisig blob\n */\nfunction createMultisigTransaction(txn: Transaction, { version, threshold, addrs }: MultisigMetadata) {\n // construct the appendable multisigned transaction format\n const pks = toPublicKeys(addrs)\n const subsignatures = pks.map(\n (pk) =>\n ({\n publicKey: pk,\n sig: undefined,\n }) satisfies MultisigSubsignature,\n )\n\n const msig: MultisigSignature = {\n version,\n threshold,\n subsigs: subsignatures,\n }\n\n // if the address of this multisig is different from the transaction sender,\n // we need to add the auth-addr field\n const msigAddr = addressFromMultisigPreImg({\n version,\n threshold,\n publicKeys: pks,\n })\n let authAddress: Address | undefined\n if (!msigAddr.equals(txn.sender)) {\n authAddress = msigAddr\n }\n\n const signedTxn: SignedTransaction = {\n txn: txn,\n msig: msig,\n authAddress,\n }\n\n return signedTxn\n}\n\ninterface MultisigOptions {\n rawSig: Uint8Array\n myPk: Uint8Array\n}\n\ninterface MultisigMetadataWithPublicKeys extends Omit<MultisigMetadata, 'addrs'> {\n publicKeys: Uint8Array[]\n}\n\n/**\n * creates a multisig transaction blob with an included signature.\n * @param txn - the actual transaction to sign.\n * @param rawSig - a Uint8Array raw signature of that transaction\n * @param myPk - a public key that corresponds with rawSig\n * @param version - multisig version\n * @param threshold - multisig threshold\n * @param pks - ordered list of public keys in this multisig\n * @returns encoded multisig blob\n */\nfunction createMultisigTransactionWithSignature(\n txn: Transaction,\n { rawSig, myPk }: MultisigOptions,\n { version, threshold, publicKeys }: MultisigMetadataWithPublicKeys,\n): SignedTransaction {\n // Create an empty encoded multisig transaction\n const signedTxn = createMultisigTransaction(txn, {\n version,\n threshold,\n addrs: publicKeys.map((pk) => new Address(pk)),\n })\n\n let keyExist = false\n\n // append the multisig signature to the corresponding public key in the multisig blob\n const updatedSubsigs = signedTxn.msig!.subsigs.map((subsig) => {\n if (arrayEqual(subsig.publicKey, myPk)) {\n keyExist = true\n return { ...subsig, sig: rawSig }\n }\n return subsig\n })\n\n if (!keyExist) {\n throw new Error(MULTISIG_KEY_NOT_EXIST_ERROR_MSG)\n }\n\n const updatedSignedTxn: SignedTransaction = {\n ...signedTxn,\n msig: {\n ...signedTxn.msig!,\n subsigs: updatedSubsigs,\n },\n }\n\n return updatedSignedTxn\n}\n\n/**\n * takes a list of multisig transaction blobs, and merges them.\n * @param multisigTxnBlobs - a list of blobs representing encoded multisig txns\n * @returns typed array msg-pack encoded multisig txn\n */\nfunction mergeMultisigTransactions(multisigTxnBlobs: SignedTransaction[]): SignedTransaction {\n if (multisigTxnBlobs.length < 2) {\n throw new Error(MULTISIG_MERGE_LESSTHANTWO_ERROR_MSG)\n }\n const refSigTx = multisigTxnBlobs[0]\n if (!refSigTx.msig) {\n throw new Error('Invalid multisig transaction, multisig structure missing at index 0')\n }\n const refTxID = refSigTx.txn.txId()\n const refAuthAddr = refSigTx.authAddress\n const refPreImage = {\n version: refSigTx.msig.version,\n threshold: refSigTx.msig.threshold,\n publicKeys: refSigTx.msig.subsigs.map((subsig) => subsig.publicKey),\n }\n const refMsigAddr = addressFromMultisigPreImg(refPreImage)\n\n const newSubsigs: MultisigSubsignature[] = refSigTx.msig.subsigs.map((sig) => ({ ...sig }))\n for (let i = 1; i < multisigTxnBlobs.length; i++) {\n const unisig = multisigTxnBlobs[i]\n if (!unisig.msig) {\n throw new Error(`Invalid multisig transaction, multisig structure missing at index ${i}`)\n }\n\n if (unisig.txn.txId() !== refTxID) {\n throw new Error(MULTISIG_MERGE_MISMATCH_ERROR_MSG)\n }\n\n const authAddr = unisig.authAddress\n if (refAuthAddr !== authAddr) {\n throw new Error(MULTISIG_MERGE_MISMATCH_AUTH_ADDR_MSG)\n }\n\n // check multisig has same preimage as reference\n if (unisig.msig.subsigs.length !== refSigTx.msig.subsigs.length) {\n throw new Error(MULTISIG_MERGE_WRONG_PREIMAGE_ERROR_MSG)\n }\n const preimg: MultisigMetadataWithPublicKeys = {\n version: unisig.msig.version,\n threshold: unisig.msig.threshold,\n publicKeys: unisig.msig.subsigs.map((subsig) => subsig.publicKey),\n }\n const msgigAddr = addressFromMultisigPreImg(preimg)\n if (refMsigAddr.toString() !== msgigAddr.toString()) {\n throw new Error(MULTISIG_MERGE_WRONG_PREIMAGE_ERROR_MSG)\n }\n\n // now, we can merge\n unisig.msig.subsigs.forEach((uniSubsig, index) => {\n if (!uniSubsig.sig) return\n const current = newSubsigs[index]\n if (current.sig && !arrayEqual(uniSubsig.sig, current.sig)) {\n // mismatch\n throw new Error(MULTISIG_MERGE_SIG_MISMATCH_ERROR_MSG)\n }\n current.sig = uniSubsig.sig\n })\n }\n\n const msig: MultisigSignature = {\n version: refSigTx.msig.version,\n threshold: refSigTx.msig.threshold,\n subsigs: newSubsigs,\n }\n\n const signedTxn: SignedTransaction = {\n txn: refSigTx.txn,\n msig: msig,\n authAddress: refAuthAddr,\n }\n\n return signedTxn\n}\n\n/**\n * Partially signs this transaction with an external raw multisig signature and returns\n * a partially-signed multisig transaction, encoded with msgpack as a typed array.\n * @param transaction - The transaction to sign\n * @param metadata - multisig metadata\n * @param signerAddr - address of the signer\n * @param signature - raw multisig signature\n * @returns an encoded, partially signed multisig transaction.\n */\nfunction partialSignWithMultisigSignature(\n transaction: Transaction,\n metadata: MultisigMetadataWithPublicKeys,\n signerAddr: string | Address,\n signature: Uint8Array,\n) {\n if (signature.length != SIGNATURE_BYTE_LENGTH) {\n throw new Error(MULTISIG_SIGNATURE_LENGTH_ERROR_MSG)\n }\n const signerAddressObj = typeof signerAddr === 'string' ? Address.fromString(signerAddr) : signerAddr\n return createMultisigTransactionWithSignature(\n transaction,\n {\n rawSig: signature,\n myPk: signerAddressObj.publicKey,\n },\n metadata,\n )\n}\n\n/**\n * Takes a multisig transaction blob, and appends a given raw signature to it.\n * This makes it possible to compile a multisig signature using only raw signatures from external methods.\n * @param multisigTxnBlob - an encoded multisig txn. Supports non-payment txn types.\n * @param version - multisig version\n * @param threshold - multisig threshold\n * @param addrs - a list of Algorand addresses representing possible signers for this multisig. Order is important.\n * @param signerAddr - address of the signer\n * @param signature - raw multisig signature\n * @returns object containing txID, and blob representing encoded multisig txn\n */\nfunction appendSignRawMultisigSignature(\n multisigTxn: SignedTransaction,\n { version, threshold, addrs }: MultisigMetadata,\n signerAddr: string | Address,\n signature: Uint8Array,\n): SignedTransaction {\n const publicKeys = toPublicKeys(addrs)\n // obtain underlying txn, sign it, and merge it\n const partialSigned = partialSignWithMultisigSignature(multisigTxn.txn, { version, threshold, publicKeys }, signerAddr, signature)\n return mergeMultisigTransactions([multisigTxn, partialSigned])\n}\n\n/**\n * Takes multisig parameters and returns a 32 byte typed array public key,\n * representing an address that identifies the \"exact group, version, and public keys\" that are required for signing.\n * Hash(\"MultisigAddr\" || version uint8 || threshold uint8 || PK1 || PK2 || ...)\n * Encoding this output yields a human readable address.\n * @param version - multisig version\n * @param threshold - multisig threshold\n * @param pks - array of typed array public keys\n */\nfunction addressFromMultisigPreImg({\n version,\n threshold,\n publicKeys,\n}: Omit<MultisigMetadata, 'addrs'> & {\n publicKeys: Uint8Array[]\n}): Address {\n if (version > 255 || version < 0) {\n // ^ a tad redundant, but in case in the future version != 1, still check for uint8\n throw new Error(`${INVALID_MSIG_VERSION_ERROR_MSG}: ${version}`)\n }\n if (threshold === 0 || publicKeys.length === 0 || threshold > publicKeys.length || threshold > 255) {\n throw new Error(INVALID_MSIG_THRESHOLD_ERROR_MSG)\n }\n const pkLen = ALGORAND_ADDRESS_BYTE_LENGTH - ALGORAND_CHECKSUM_BYTE_LENGTH\n if (pkLen !== PUBLIC_KEY_BYTE_LENGTH) {\n throw new Error(UNEXPECTED_PK_LEN_ERROR_MSG)\n }\n const merged = new Uint8Array(MULTISIG_PREIMG2ADDR_PREFIX.length + 2 + pkLen * publicKeys.length)\n merged.set(MULTISIG_PREIMG2ADDR_PREFIX, 0)\n merged.set([version], MULTISIG_PREIMG2ADDR_PREFIX.length)\n merged.set([threshold], MULTISIG_PREIMG2ADDR_PREFIX.length + 1)\n for (let i = 0; i < publicKeys.length; i++) {\n if (publicKeys[i].length !== pkLen) {\n throw new Error(INVALID_MSIG_PK_ERROR_MSG)\n }\n merged.set(publicKeys[i], MULTISIG_PREIMG2ADDR_PREFIX.length + 2 + i * pkLen)\n }\n return new Address(Uint8Array.from(hash(merged)))\n}\n\n/**\n * Takes multisig parameters and returns a human readable Algorand address.\n * This is equivalent to fromMultisigPreImg, but interfaces with encoded addresses.\n * @param version - multisig version\n * @param threshold - multisig threshold\n * @param addrs - array of encoded addresses\n */\nfunction addressFromMultisigPreImgAddrs({ version, threshold, addrs }: MultisigMetadata): Address {\n return addressFromMultisigPreImg({\n version,\n threshold,\n publicKeys: toPublicKeys(addrs),\n })\n}\n\n/**\n * Takes multisig metadata (preimage) and returns the corresponding human readable Algorand address.\n * @param version - multisig version\n * @param threshold - multisig threshold\n * @param addrs - list of Algorand addresses\n */\nconst multisigAddress: typeof addressFromMultisigPreImgAddrs = addressFromMultisigPreImgAddrs\n\nexport interface MultisigMetadata {\n /**\n * Multisig version\n */\n version: number\n\n /**\n * Multisig threshold value. Authorization requires a subset of signatures,\n * equal to or greater than the threshold value.\n */\n threshold: number\n\n /**\n * A list of Algorand addresses representing possible signers for this multisig. Order is important.\n */\n addrs: Array<Address>\n}\n\n/** Account wrapper that supports partial or full multisig signing. */\nexport class MultisigAccount implements AddressWithTransactionSigner, AddressWithDelegatedLsigSigner {\n _params: MultisigMetadata\n _subSigners: (AddressWithTransactionSigner & AddressWithDelegatedLsigSigner)[]\n _addr: Address\n _signer: TransactionSigner\n _lsigSigner: DelegatedLsigSigner\n\n /** The parameters for the multisig account */\n get params(): Readonly<MultisigMetadata> {\n return this._params\n }\n\n /** The list of accounts that are present to sign transactions or lsigs */\n get subSigners() {\n return this._subSigners\n }\n\n /** The address of the multisig account */\n get addr(): Readonly<Address> {\n return this._addr\n }\n\n /** The transaction signer for the multisig account */\n get signer(): TransactionSigner {\n return this._signer\n }\n\n get lsigSigner(): DelegatedLsigSigner {\n return this._lsigSigner\n }\n\n static fromSignature(signature: MultisigSignature): MultisigAccount {\n const params: MultisigMetadata = {\n version: signature.version,\n threshold: signature.threshold,\n addrs: signature.subsigs.map((subsig) => new Address(subsig.publicKey)),\n }\n\n return new MultisigAccount(params, [])\n }\n\n constructor(multisigParams: MultisigMetadata, subSigners: (AddressWithTransactionSigner & AddressWithDelegatedLsigSigner)[]) {\n this._params = multisigParams\n this._subSigners = subSigners\n this._addr = multisigAddress(multisigParams)\n this._signer = async (txns: Transaction[], indexesToSign: number[]): Promise<Uint8Array[]> => {\n const txnsToSign = txns.filter((_, index) => indexesToSign.includes(index))\n const signedMsigTxns: SignedTransaction[] = []\n\n for (const txn of txnsToSign) {\n let signedMsigTxn = createMultisigTransaction(txn, this._params)\n\n for (const subSigner of this.subSigners) {\n const stxn = (await subSigner.signer([txn], [0]))[0]\n const sig = decodeSignedTransaction(stxn).sig\n\n if (!sig) {\n throw new Error(\n `Signer for address ${subSigner.addr.toString()} did not produce a valid signature when signing ${txn.txId()} for multisig account ${this._addr.toString()}`,\n )\n }\n\n signedMsigTxn = appendSignRawMultisigSignature(signedMsigTxn, this._params, subSigner.addr, sig)\n }\n\n signedMsigTxns.push(signedMsigTxn)\n }\n\n return signedMsigTxns.map(encodeSignedTransaction)\n }\n\n this._lsigSigner = async (lsig, _) => {\n let lmsig = lsig.lmsig ?? this.createMultisigSignature()\n\n for (const addrWithSigner of this.subSigners) {\n const { lsigSigner, addr } = addrWithSigner\n const result = await lsigSigner(lsig, this)\n if (!('sig' in result) || !result.sig) {\n throw new Error(\n `Signer for address ${addr.toString()} did not produce a valid signature when signing logic sig for multisig account ${this._addr.toString()}`,\n )\n }\n\n lmsig = this.applySignature(lmsig, addr.publicKey, result.sig)\n }\n\n return { addr: this.addr, lmsig }\n }\n }\n\n createMultisigTransaction(txn: Transaction): SignedTransaction {\n return createMultisigTransaction(txn, this._params)\n }\n\n createMultisigSignature(): MultisigSignature {\n const pks = toPublicKeys(this._params.addrs)\n const subsignatures: MultisigSubsignature[] = pks.map((pk) => ({\n publicKey: pk,\n signature: undefined,\n }))\n\n return {\n version: this._params.version,\n threshold: this._params.threshold,\n subsigs: subsignatures,\n }\n }\n\n applySignatureToTxn(txn: SignedTransaction, pubkey: Uint8Array, signature: Uint8Array): void {\n if (!txn.msig) {\n const createdTxn = this.createMultisigTransaction(txn.txn)\n txn.msig = createdTxn.msig\n }\n\n txn.msig = applyMultisigSubsignature(txn.msig!, pubkey, signature)\n }\n\n applySignature(msigSignature: MultisigSignature, pubkey: Uint8Array, signature: Uint8Array): MultisigSignature {\n if (msigSignature.version !== this._params.version || msigSignature.threshold !== this._params.threshold) {\n const thisParams = {\n version: this._params.version,\n threshold: this._params.threshold,\n participants: this._params.addrs.map((addr) => addr.toString()),\n }\n\n const givenParams = {\n version: msigSignature.version,\n threshold: msigSignature.threshold,\n participants: msigSignature.subsigs.map((subsig) => new Address(subsig.publicKey).toString()),\n }\n\n throw new Error(\n `Multisig signature parameters do not match expected multisig parameters. Multisig params: ${JSON.stringify(thisParams)}, signature: ${JSON.stringify(givenParams)}`,\n )\n }\n\n return applyMultisigSubsignature(msigSignature, pubkey, signature)\n }\n}\n"],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O;GACL,SAAS,KAAK,QAAQ;GACtB,WAAW,KAAK,QAAQ;GACxB,SAAS;GACV;;CAGH,oBAAoB,KAAwB,QAAoB,WAA6B;AAC3F,MAAI,CAAC,IAAI,KAEP,KAAI,OADe,KAAK,0BAA0B,IAAI,IAAI,CACpC;AAGxB,MAAI,OAAO,0BAA0B,IAAI,MAAO,QAAQ,UAAU;;CAGpE,eAAe,eAAkC,QAAoB,WAA0C;AAC7G,MAAI,cAAc,YAAY,KAAK,QAAQ,WAAW,cAAc,cAAc,KAAK,QAAQ,WAAW;GACxG,MAAM,aAAa;IACjB,SAAS,KAAK,QAAQ;IACtB,WAAW,KAAK,QAAQ;IACxB,cAAc,KAAK,QAAQ,MAAM,KAAK,SAAS,KAAK,UAAU,CAAC;IAChE;GAED,MAAM,cAAc;IAClB,SAAS,cAAc;IACvB,WAAW,cAAc;IACzB,cAAc,cAAc,QAAQ,KAAK,WAAW,IAAI,QAAQ,OAAO,UAAU,CAAC,UAAU,CAAC;IAC9F;AAED,SAAM,IAAI,MACR,6FAA6F,KAAK,UAAU,WAAW,CAAC,eAAe,KAAK,UAAU,YAAY,GACnK;;AAGH,SAAO,0BAA0B,eAAe,QAAQ,UAAU"}
@@ -31,7 +31,10 @@ function generateAddressWithSigners(args) {
31
31
  return stxns.map(require_signed_transaction.encodeSignedTransaction);
32
32
  };
33
33
  const lsigSigner = async (lsig, msig) => {
34
- return await rawEd25519Signer(lsig.bytesToSignForDelegation(msig));
34
+ return {
35
+ sig: await rawEd25519Signer(lsig.bytesToSignForDelegation(msig)),
36
+ addr: sendingAddress
37
+ };
35
38
  };
36
39
  const programDataSigner = async (data, lsig) => {
37
40
  return await rawEd25519Signer(lsig.programDataToSign(data));
@@ -1 +1 @@
1
- {"version":3,"file":"signer.js","names":["Address","signer: TransactionSigner","stxns: SignedTransaction[]","stxn: SignedTransaction","encodeTransaction","encodeSignedTransaction","lsigSigner: DelegatedLsigSigner","programDataSigner: ProgramDataSigner","mxBytesSigner: MxBytesSigner","concatArrays","unsigned: Uint8Array[]"],"sources":["../../../../packages/transact/src/signer.ts"],"sourcesContent":["import { Address, Addressable, concatArrays, Expand, ReadableAddress } from '@algorandfoundation/algokit-common'\nimport { encodeTransaction, Transaction } from './transactions/transaction'\nimport { DelegatedLsigSigner, ProgramDataSigner } from './logicsig'\nimport { encodeSignedTransaction, SignedTransaction } from './transactions/signed-transaction'\n\n/** Function for signing a group of transactions */\nexport type TransactionSigner = (txnGroup: Transaction[], indexesToSign: number[]) => Promise<Uint8Array[]>\n\n/** A transaction signer attached to an address */\nexport interface AddressWithTransactionSigner extends Addressable {\n signer: TransactionSigner\n}\n\n/** An address that can be used to send transactions that may or may not have a signer */\nexport type SendingAddress = ReadableAddress | AddressWithTransactionSigner\n\n/** A delegated logic signature signer attached to an address */\nexport interface AddressWithDelegatedLsigSigner extends Addressable {\n lsigSigner: DelegatedLsigSigner\n}\n\nexport interface AddressWithProgramDataSigner extends Addressable {\n programDataSigner: ProgramDataSigner\n}\n\nexport type MxBytesSigner = (bytesToSign: Uint8Array) => Promise<Uint8Array>\n\nexport interface AddressWithMxBytesSigner extends Addressable {\n mxBytesSigner: MxBytesSigner\n}\n\nexport type AddressWithSigners = Expand<\n Addressable & AddressWithTransactionSigner & AddressWithDelegatedLsigSigner & AddressWithProgramDataSigner & AddressWithMxBytesSigner\n>\n\nconst SIGN_BYTES_PREFIX = Uint8Array.from([77, 88]) // \"MX\"\n\n/**\n * Generate type-safe domain-separated signer callbacks given an ed25519 pubkey and a signing callback\n * @param args - The arguments for generating signers\n * @param args.ed25519Pubkey - The ed25519 public key used for signing\n * @param args.sendingAddress - The address that will be used as the sender of transactions. If not provided, defaults to the address derived from the ed25519 public key. This is useful when signing for a rekeyed account where the sending address differs from the auth address.\n * @param args.rawEd25519Signer - A callback function that signs raw bytes using the ed25519 private key\n * @returns An object containing the sending address and various signer functions\n */\nexport function generateAddressWithSigners(args: {\n ed25519Pubkey: Uint8Array\n sendingAddress?: Address\n rawEd25519Signer: (bytesToSign: Uint8Array) => Promise<Uint8Array>\n}): AddressWithSigners {\n const { ed25519Pubkey, rawEd25519Signer } = args\n const authAddr = new Address(ed25519Pubkey)\n const sendingAddress = args.sendingAddress ?? authAddr\n\n const signer: TransactionSigner = async (txnGroup: Transaction[], indexesToSign: number[]) => {\n const stxns: SignedTransaction[] = []\n for (const index of indexesToSign) {\n const txn = txnGroup[index]\n const bytesToSign = encodeTransaction(txn)\n const signature = await rawEd25519Signer(bytesToSign)\n const stxn: SignedTransaction = {\n txn,\n sig: signature,\n }\n\n if (!txn.sender.equals(sendingAddress)) {\n stxn.authAddress = authAddr\n }\n\n stxns.push(stxn)\n }\n\n return stxns.map(encodeSignedTransaction)\n }\n\n const lsigSigner: DelegatedLsigSigner = async (lsig, msig) => {\n const bytesToSign = lsig.bytesToSignForDelegation(msig)\n return await rawEd25519Signer(bytesToSign)\n }\n\n const programDataSigner: ProgramDataSigner = async (data, lsig) => {\n const bytesToSign = lsig.programDataToSign(data)\n return await rawEd25519Signer(bytesToSign)\n }\n\n const mxBytesSigner: MxBytesSigner = async (bytes: Uint8Array) => {\n const bytesToSign = concatArrays(SIGN_BYTES_PREFIX, bytes)\n return await rawEd25519Signer(bytesToSign)\n }\n\n return { addr: sendingAddress, signer, lsigSigner, programDataSigner, mxBytesSigner }\n}\n\n/**\n * Create a makeEmptyTransactionSigner that does not specify any signer or\n * signing capabilities. This should only be used to simulate transactions.\n */\nexport function makeEmptyTransactionSigner(): TransactionSigner {\n return (txnGroup: Transaction[], indexesToSign: number[]) => {\n const unsigned: Uint8Array[] = []\n\n for (const index of indexesToSign) {\n const stxn: SignedTransaction = {\n txn: txnGroup[index],\n sig: new Uint8Array(64).fill(0),\n }\n unsigned.push(encodeSignedTransaction(stxn))\n }\n\n return Promise.resolve(unsigned)\n }\n}\n"],"mappings":";;;;;;AAmCA,MAAM,oBAAoB,WAAW,KAAK,CAAC,IAAI,GAAG,CAAC;;;;;;;;;AAUnD,SAAgB,2BAA2B,MAIpB;CACrB,MAAM,EAAE,eAAe,qBAAqB;CAC5C,MAAM,WAAW,IAAIA,wBAAQ,cAAc;CAC3C,MAAM,iBAAiB,KAAK,kBAAkB;CAE9C,MAAMC,SAA4B,OAAO,UAAyB,kBAA4B;EAC5F,MAAMC,QAA6B,EAAE;AACrC,OAAK,MAAM,SAAS,eAAe;GACjC,MAAM,MAAM,SAAS;GAGrB,MAAMC,OAA0B;IAC9B;IACA,KAHgB,MAAM,iBADJC,sCAAkB,IAAI,CACW;IAIpD;AAED,OAAI,CAAC,IAAI,OAAO,OAAO,eAAe,CACpC,MAAK,cAAc;AAGrB,SAAM,KAAK,KAAK;;AAGlB,SAAO,MAAM,IAAIC,mDAAwB;;CAG3C,MAAMC,aAAkC,OAAO,MAAM,SAAS;AAE5D,SAAO,MAAM,iBADO,KAAK,yBAAyB,KAAK,CACb;;CAG5C,MAAMC,oBAAuC,OAAO,MAAM,SAAS;AAEjE,SAAO,MAAM,iBADO,KAAK,kBAAkB,KAAK,CACN;;CAG5C,MAAMC,gBAA+B,OAAO,UAAsB;AAEhE,SAAO,MAAM,iBADOC,2BAAa,mBAAmB,MAAM,CAChB;;AAG5C,QAAO;EAAE,MAAM;EAAgB;EAAQ;EAAY;EAAmB;EAAe;;;;;;AAOvF,SAAgB,6BAAgD;AAC9D,SAAQ,UAAyB,kBAA4B;EAC3D,MAAMC,WAAyB,EAAE;AAEjC,OAAK,MAAM,SAAS,eAAe;GACjC,MAAMP,OAA0B;IAC9B,KAAK,SAAS;IACd,KAAK,IAAI,WAAW,GAAG,CAAC,KAAK,EAAE;IAChC;AACD,YAAS,KAAKE,mDAAwB,KAAK,CAAC;;AAG9C,SAAO,QAAQ,QAAQ,SAAS"}
1
+ {"version":3,"file":"signer.js","names":["Address","signer: TransactionSigner","stxns: SignedTransaction[]","stxn: SignedTransaction","encodeTransaction","encodeSignedTransaction","lsigSigner: DelegatedLsigSigner","programDataSigner: ProgramDataSigner","mxBytesSigner: MxBytesSigner","concatArrays","unsigned: Uint8Array[]"],"sources":["../../../../packages/transact/src/signer.ts"],"sourcesContent":["import { Address, Addressable, concatArrays, Expand, ReadableAddress } from '@algorandfoundation/algokit-common'\nimport { encodeTransaction, Transaction } from './transactions/transaction'\nimport { DelegatedLsigSigner, ProgramDataSigner } from './logicsig'\nimport { encodeSignedTransaction, SignedTransaction } from './transactions/signed-transaction'\n\n/** Function for signing a group of transactions */\nexport type TransactionSigner = (txnGroup: Transaction[], indexesToSign: number[]) => Promise<Uint8Array[]>\n\n/** A transaction signer attached to an address */\nexport interface AddressWithTransactionSigner extends Addressable {\n signer: TransactionSigner\n}\n\n/** An address that can be used to send transactions that may or may not have a signer */\nexport type SendingAddress = ReadableAddress | AddressWithTransactionSigner\n\n/** A delegated logic signature signer attached to an address */\nexport interface AddressWithDelegatedLsigSigner extends Addressable {\n lsigSigner: DelegatedLsigSigner\n}\n\nexport interface AddressWithProgramDataSigner extends Addressable {\n programDataSigner: ProgramDataSigner\n}\n\nexport type MxBytesSigner = (bytesToSign: Uint8Array) => Promise<Uint8Array>\n\nexport interface AddressWithMxBytesSigner extends Addressable {\n mxBytesSigner: MxBytesSigner\n}\n\nexport type AddressWithSigners = Expand<\n Addressable & AddressWithTransactionSigner & AddressWithDelegatedLsigSigner & AddressWithProgramDataSigner & AddressWithMxBytesSigner\n>\n\nconst SIGN_BYTES_PREFIX = Uint8Array.from([77, 88]) // \"MX\"\n\n/**\n * Generate type-safe domain-separated signer callbacks given an ed25519 pubkey and a signing callback\n * @param args - The arguments for generating signers\n * @param args.ed25519Pubkey - The ed25519 public key used for signing\n * @param args.sendingAddress - The address that will be used as the sender of transactions. If not provided, defaults to the address derived from the ed25519 public key. This is useful when signing for a rekeyed account where the sending address differs from the auth address.\n * @param args.rawEd25519Signer - A callback function that signs raw bytes using the ed25519 private key\n * @returns An object containing the sending address and various signer functions\n */\nexport function generateAddressWithSigners(args: {\n ed25519Pubkey: Uint8Array\n sendingAddress?: Address\n rawEd25519Signer: (bytesToSign: Uint8Array) => Promise<Uint8Array>\n}): AddressWithSigners {\n const { ed25519Pubkey, rawEd25519Signer } = args\n const authAddr = new Address(ed25519Pubkey)\n const sendingAddress = args.sendingAddress ?? authAddr\n\n const signer: TransactionSigner = async (txnGroup: Transaction[], indexesToSign: number[]) => {\n const stxns: SignedTransaction[] = []\n for (const index of indexesToSign) {\n const txn = txnGroup[index]\n const bytesToSign = encodeTransaction(txn)\n const signature = await rawEd25519Signer(bytesToSign)\n const stxn: SignedTransaction = {\n txn,\n sig: signature,\n }\n\n if (!txn.sender.equals(sendingAddress)) {\n stxn.authAddress = authAddr\n }\n\n stxns.push(stxn)\n }\n\n return stxns.map(encodeSignedTransaction)\n }\n\n const lsigSigner: DelegatedLsigSigner = async (lsig, msig) => {\n const bytesToSign = lsig.bytesToSignForDelegation(msig)\n const sig = await rawEd25519Signer(bytesToSign)\n return { sig, addr: sendingAddress }\n }\n\n const programDataSigner: ProgramDataSigner = async (data, lsig) => {\n const bytesToSign = lsig.programDataToSign(data)\n return await rawEd25519Signer(bytesToSign)\n }\n\n const mxBytesSigner: MxBytesSigner = async (bytes: Uint8Array) => {\n const bytesToSign = concatArrays(SIGN_BYTES_PREFIX, bytes)\n return await rawEd25519Signer(bytesToSign)\n }\n\n return { addr: sendingAddress, signer, lsigSigner, programDataSigner, mxBytesSigner }\n}\n\n/**\n * Create a makeEmptyTransactionSigner that does not specify any signer or\n * signing capabilities. This should only be used to simulate transactions.\n */\nexport function makeEmptyTransactionSigner(): TransactionSigner {\n return (txnGroup: Transaction[], indexesToSign: number[]) => {\n const unsigned: Uint8Array[] = []\n\n for (const index of indexesToSign) {\n const stxn: SignedTransaction = {\n txn: txnGroup[index],\n sig: new Uint8Array(64).fill(0),\n }\n unsigned.push(encodeSignedTransaction(stxn))\n }\n\n return Promise.resolve(unsigned)\n }\n}\n"],"mappings":";;;;;;AAmCA,MAAM,oBAAoB,WAAW,KAAK,CAAC,IAAI,GAAG,CAAC;;;;;;;;;AAUnD,SAAgB,2BAA2B,MAIpB;CACrB,MAAM,EAAE,eAAe,qBAAqB;CAC5C,MAAM,WAAW,IAAIA,wBAAQ,cAAc;CAC3C,MAAM,iBAAiB,KAAK,kBAAkB;CAE9C,MAAMC,SAA4B,OAAO,UAAyB,kBAA4B;EAC5F,MAAMC,QAA6B,EAAE;AACrC,OAAK,MAAM,SAAS,eAAe;GACjC,MAAM,MAAM,SAAS;GAGrB,MAAMC,OAA0B;IAC9B;IACA,KAHgB,MAAM,iBADJC,sCAAkB,IAAI,CACW;IAIpD;AAED,OAAI,CAAC,IAAI,OAAO,OAAO,eAAe,CACpC,MAAK,cAAc;AAGrB,SAAM,KAAK,KAAK;;AAGlB,SAAO,MAAM,IAAIC,mDAAwB;;CAG3C,MAAMC,aAAkC,OAAO,MAAM,SAAS;AAG5D,SAAO;GAAE,KADG,MAAM,iBADE,KAAK,yBAAyB,KAAK,CACR;GACjC,MAAM;GAAgB;;CAGtC,MAAMC,oBAAuC,OAAO,MAAM,SAAS;AAEjE,SAAO,MAAM,iBADO,KAAK,kBAAkB,KAAK,CACN;;CAG5C,MAAMC,gBAA+B,OAAO,UAAsB;AAEhE,SAAO,MAAM,iBADOC,2BAAa,mBAAmB,MAAM,CAChB;;AAG5C,QAAO;EAAE,MAAM;EAAgB;EAAQ;EAAY;EAAmB;EAAe;;;;;;AAOvF,SAAgB,6BAAgD;AAC9D,SAAQ,UAAyB,kBAA4B;EAC3D,MAAMC,WAAyB,EAAE;AAEjC,OAAK,MAAM,SAAS,eAAe;GACjC,MAAMP,OAA0B;IAC9B,KAAK,SAAS;IACd,KAAK,IAAI,WAAW,GAAG,CAAC,KAAK,EAAE;IAChC;AACD,YAAS,KAAKE,mDAAwB,KAAK,CAAC;;AAG9C,SAAO,QAAQ,QAAQ,SAAS"}
@@ -31,7 +31,10 @@ function generateAddressWithSigners(args) {
31
31
  return stxns.map(encodeSignedTransaction);
32
32
  };
33
33
  const lsigSigner = async (lsig, msig) => {
34
- return await rawEd25519Signer(lsig.bytesToSignForDelegation(msig));
34
+ return {
35
+ sig: await rawEd25519Signer(lsig.bytesToSignForDelegation(msig)),
36
+ addr: sendingAddress
37
+ };
35
38
  };
36
39
  const programDataSigner = async (data, lsig) => {
37
40
  return await rawEd25519Signer(lsig.programDataToSign(data));
@@ -1 +1 @@
1
- {"version":3,"file":"signer.mjs","names":["signer: TransactionSigner","stxns: SignedTransaction[]","stxn: SignedTransaction","lsigSigner: DelegatedLsigSigner","programDataSigner: ProgramDataSigner","mxBytesSigner: MxBytesSigner","unsigned: Uint8Array[]"],"sources":["../../../../packages/transact/src/signer.ts"],"sourcesContent":["import { Address, Addressable, concatArrays, Expand, ReadableAddress } from '@algorandfoundation/algokit-common'\nimport { encodeTransaction, Transaction } from './transactions/transaction'\nimport { DelegatedLsigSigner, ProgramDataSigner } from './logicsig'\nimport { encodeSignedTransaction, SignedTransaction } from './transactions/signed-transaction'\n\n/** Function for signing a group of transactions */\nexport type TransactionSigner = (txnGroup: Transaction[], indexesToSign: number[]) => Promise<Uint8Array[]>\n\n/** A transaction signer attached to an address */\nexport interface AddressWithTransactionSigner extends Addressable {\n signer: TransactionSigner\n}\n\n/** An address that can be used to send transactions that may or may not have a signer */\nexport type SendingAddress = ReadableAddress | AddressWithTransactionSigner\n\n/** A delegated logic signature signer attached to an address */\nexport interface AddressWithDelegatedLsigSigner extends Addressable {\n lsigSigner: DelegatedLsigSigner\n}\n\nexport interface AddressWithProgramDataSigner extends Addressable {\n programDataSigner: ProgramDataSigner\n}\n\nexport type MxBytesSigner = (bytesToSign: Uint8Array) => Promise<Uint8Array>\n\nexport interface AddressWithMxBytesSigner extends Addressable {\n mxBytesSigner: MxBytesSigner\n}\n\nexport type AddressWithSigners = Expand<\n Addressable & AddressWithTransactionSigner & AddressWithDelegatedLsigSigner & AddressWithProgramDataSigner & AddressWithMxBytesSigner\n>\n\nconst SIGN_BYTES_PREFIX = Uint8Array.from([77, 88]) // \"MX\"\n\n/**\n * Generate type-safe domain-separated signer callbacks given an ed25519 pubkey and a signing callback\n * @param args - The arguments for generating signers\n * @param args.ed25519Pubkey - The ed25519 public key used for signing\n * @param args.sendingAddress - The address that will be used as the sender of transactions. If not provided, defaults to the address derived from the ed25519 public key. This is useful when signing for a rekeyed account where the sending address differs from the auth address.\n * @param args.rawEd25519Signer - A callback function that signs raw bytes using the ed25519 private key\n * @returns An object containing the sending address and various signer functions\n */\nexport function generateAddressWithSigners(args: {\n ed25519Pubkey: Uint8Array\n sendingAddress?: Address\n rawEd25519Signer: (bytesToSign: Uint8Array) => Promise<Uint8Array>\n}): AddressWithSigners {\n const { ed25519Pubkey, rawEd25519Signer } = args\n const authAddr = new Address(ed25519Pubkey)\n const sendingAddress = args.sendingAddress ?? authAddr\n\n const signer: TransactionSigner = async (txnGroup: Transaction[], indexesToSign: number[]) => {\n const stxns: SignedTransaction[] = []\n for (const index of indexesToSign) {\n const txn = txnGroup[index]\n const bytesToSign = encodeTransaction(txn)\n const signature = await rawEd25519Signer(bytesToSign)\n const stxn: SignedTransaction = {\n txn,\n sig: signature,\n }\n\n if (!txn.sender.equals(sendingAddress)) {\n stxn.authAddress = authAddr\n }\n\n stxns.push(stxn)\n }\n\n return stxns.map(encodeSignedTransaction)\n }\n\n const lsigSigner: DelegatedLsigSigner = async (lsig, msig) => {\n const bytesToSign = lsig.bytesToSignForDelegation(msig)\n return await rawEd25519Signer(bytesToSign)\n }\n\n const programDataSigner: ProgramDataSigner = async (data, lsig) => {\n const bytesToSign = lsig.programDataToSign(data)\n return await rawEd25519Signer(bytesToSign)\n }\n\n const mxBytesSigner: MxBytesSigner = async (bytes: Uint8Array) => {\n const bytesToSign = concatArrays(SIGN_BYTES_PREFIX, bytes)\n return await rawEd25519Signer(bytesToSign)\n }\n\n return { addr: sendingAddress, signer, lsigSigner, programDataSigner, mxBytesSigner }\n}\n\n/**\n * Create a makeEmptyTransactionSigner that does not specify any signer or\n * signing capabilities. This should only be used to simulate transactions.\n */\nexport function makeEmptyTransactionSigner(): TransactionSigner {\n return (txnGroup: Transaction[], indexesToSign: number[]) => {\n const unsigned: Uint8Array[] = []\n\n for (const index of indexesToSign) {\n const stxn: SignedTransaction = {\n txn: txnGroup[index],\n sig: new Uint8Array(64).fill(0),\n }\n unsigned.push(encodeSignedTransaction(stxn))\n }\n\n return Promise.resolve(unsigned)\n }\n}\n"],"mappings":";;;;;;AAmCA,MAAM,oBAAoB,WAAW,KAAK,CAAC,IAAI,GAAG,CAAC;;;;;;;;;AAUnD,SAAgB,2BAA2B,MAIpB;CACrB,MAAM,EAAE,eAAe,qBAAqB;CAC5C,MAAM,WAAW,IAAI,QAAQ,cAAc;CAC3C,MAAM,iBAAiB,KAAK,kBAAkB;CAE9C,MAAMA,SAA4B,OAAO,UAAyB,kBAA4B;EAC5F,MAAMC,QAA6B,EAAE;AACrC,OAAK,MAAM,SAAS,eAAe;GACjC,MAAM,MAAM,SAAS;GAGrB,MAAMC,OAA0B;IAC9B;IACA,KAHgB,MAAM,iBADJ,kBAAkB,IAAI,CACW;IAIpD;AAED,OAAI,CAAC,IAAI,OAAO,OAAO,eAAe,CACpC,MAAK,cAAc;AAGrB,SAAM,KAAK,KAAK;;AAGlB,SAAO,MAAM,IAAI,wBAAwB;;CAG3C,MAAMC,aAAkC,OAAO,MAAM,SAAS;AAE5D,SAAO,MAAM,iBADO,KAAK,yBAAyB,KAAK,CACb;;CAG5C,MAAMC,oBAAuC,OAAO,MAAM,SAAS;AAEjE,SAAO,MAAM,iBADO,KAAK,kBAAkB,KAAK,CACN;;CAG5C,MAAMC,gBAA+B,OAAO,UAAsB;AAEhE,SAAO,MAAM,iBADO,aAAa,mBAAmB,MAAM,CAChB;;AAG5C,QAAO;EAAE,MAAM;EAAgB;EAAQ;EAAY;EAAmB;EAAe;;;;;;AAOvF,SAAgB,6BAAgD;AAC9D,SAAQ,UAAyB,kBAA4B;EAC3D,MAAMC,WAAyB,EAAE;AAEjC,OAAK,MAAM,SAAS,eAAe;GACjC,MAAMJ,OAA0B;IAC9B,KAAK,SAAS;IACd,KAAK,IAAI,WAAW,GAAG,CAAC,KAAK,EAAE;IAChC;AACD,YAAS,KAAK,wBAAwB,KAAK,CAAC;;AAG9C,SAAO,QAAQ,QAAQ,SAAS"}
1
+ {"version":3,"file":"signer.mjs","names":["signer: TransactionSigner","stxns: SignedTransaction[]","stxn: SignedTransaction","lsigSigner: DelegatedLsigSigner","programDataSigner: ProgramDataSigner","mxBytesSigner: MxBytesSigner","unsigned: Uint8Array[]"],"sources":["../../../../packages/transact/src/signer.ts"],"sourcesContent":["import { Address, Addressable, concatArrays, Expand, ReadableAddress } from '@algorandfoundation/algokit-common'\nimport { encodeTransaction, Transaction } from './transactions/transaction'\nimport { DelegatedLsigSigner, ProgramDataSigner } from './logicsig'\nimport { encodeSignedTransaction, SignedTransaction } from './transactions/signed-transaction'\n\n/** Function for signing a group of transactions */\nexport type TransactionSigner = (txnGroup: Transaction[], indexesToSign: number[]) => Promise<Uint8Array[]>\n\n/** A transaction signer attached to an address */\nexport interface AddressWithTransactionSigner extends Addressable {\n signer: TransactionSigner\n}\n\n/** An address that can be used to send transactions that may or may not have a signer */\nexport type SendingAddress = ReadableAddress | AddressWithTransactionSigner\n\n/** A delegated logic signature signer attached to an address */\nexport interface AddressWithDelegatedLsigSigner extends Addressable {\n lsigSigner: DelegatedLsigSigner\n}\n\nexport interface AddressWithProgramDataSigner extends Addressable {\n programDataSigner: ProgramDataSigner\n}\n\nexport type MxBytesSigner = (bytesToSign: Uint8Array) => Promise<Uint8Array>\n\nexport interface AddressWithMxBytesSigner extends Addressable {\n mxBytesSigner: MxBytesSigner\n}\n\nexport type AddressWithSigners = Expand<\n Addressable & AddressWithTransactionSigner & AddressWithDelegatedLsigSigner & AddressWithProgramDataSigner & AddressWithMxBytesSigner\n>\n\nconst SIGN_BYTES_PREFIX = Uint8Array.from([77, 88]) // \"MX\"\n\n/**\n * Generate type-safe domain-separated signer callbacks given an ed25519 pubkey and a signing callback\n * @param args - The arguments for generating signers\n * @param args.ed25519Pubkey - The ed25519 public key used for signing\n * @param args.sendingAddress - The address that will be used as the sender of transactions. If not provided, defaults to the address derived from the ed25519 public key. This is useful when signing for a rekeyed account where the sending address differs from the auth address.\n * @param args.rawEd25519Signer - A callback function that signs raw bytes using the ed25519 private key\n * @returns An object containing the sending address and various signer functions\n */\nexport function generateAddressWithSigners(args: {\n ed25519Pubkey: Uint8Array\n sendingAddress?: Address\n rawEd25519Signer: (bytesToSign: Uint8Array) => Promise<Uint8Array>\n}): AddressWithSigners {\n const { ed25519Pubkey, rawEd25519Signer } = args\n const authAddr = new Address(ed25519Pubkey)\n const sendingAddress = args.sendingAddress ?? authAddr\n\n const signer: TransactionSigner = async (txnGroup: Transaction[], indexesToSign: number[]) => {\n const stxns: SignedTransaction[] = []\n for (const index of indexesToSign) {\n const txn = txnGroup[index]\n const bytesToSign = encodeTransaction(txn)\n const signature = await rawEd25519Signer(bytesToSign)\n const stxn: SignedTransaction = {\n txn,\n sig: signature,\n }\n\n if (!txn.sender.equals(sendingAddress)) {\n stxn.authAddress = authAddr\n }\n\n stxns.push(stxn)\n }\n\n return stxns.map(encodeSignedTransaction)\n }\n\n const lsigSigner: DelegatedLsigSigner = async (lsig, msig) => {\n const bytesToSign = lsig.bytesToSignForDelegation(msig)\n const sig = await rawEd25519Signer(bytesToSign)\n return { sig, addr: sendingAddress }\n }\n\n const programDataSigner: ProgramDataSigner = async (data, lsig) => {\n const bytesToSign = lsig.programDataToSign(data)\n return await rawEd25519Signer(bytesToSign)\n }\n\n const mxBytesSigner: MxBytesSigner = async (bytes: Uint8Array) => {\n const bytesToSign = concatArrays(SIGN_BYTES_PREFIX, bytes)\n return await rawEd25519Signer(bytesToSign)\n }\n\n return { addr: sendingAddress, signer, lsigSigner, programDataSigner, mxBytesSigner }\n}\n\n/**\n * Create a makeEmptyTransactionSigner that does not specify any signer or\n * signing capabilities. This should only be used to simulate transactions.\n */\nexport function makeEmptyTransactionSigner(): TransactionSigner {\n return (txnGroup: Transaction[], indexesToSign: number[]) => {\n const unsigned: Uint8Array[] = []\n\n for (const index of indexesToSign) {\n const stxn: SignedTransaction = {\n txn: txnGroup[index],\n sig: new Uint8Array(64).fill(0),\n }\n unsigned.push(encodeSignedTransaction(stxn))\n }\n\n return Promise.resolve(unsigned)\n }\n}\n"],"mappings":";;;;;;AAmCA,MAAM,oBAAoB,WAAW,KAAK,CAAC,IAAI,GAAG,CAAC;;;;;;;;;AAUnD,SAAgB,2BAA2B,MAIpB;CACrB,MAAM,EAAE,eAAe,qBAAqB;CAC5C,MAAM,WAAW,IAAI,QAAQ,cAAc;CAC3C,MAAM,iBAAiB,KAAK,kBAAkB;CAE9C,MAAMA,SAA4B,OAAO,UAAyB,kBAA4B;EAC5F,MAAMC,QAA6B,EAAE;AACrC,OAAK,MAAM,SAAS,eAAe;GACjC,MAAM,MAAM,SAAS;GAGrB,MAAMC,OAA0B;IAC9B;IACA,KAHgB,MAAM,iBADJ,kBAAkB,IAAI,CACW;IAIpD;AAED,OAAI,CAAC,IAAI,OAAO,OAAO,eAAe,CACpC,MAAK,cAAc;AAGrB,SAAM,KAAK,KAAK;;AAGlB,SAAO,MAAM,IAAI,wBAAwB;;CAG3C,MAAMC,aAAkC,OAAO,MAAM,SAAS;AAG5D,SAAO;GAAE,KADG,MAAM,iBADE,KAAK,yBAAyB,KAAK,CACR;GACjC,MAAM;GAAgB;;CAGtC,MAAMC,oBAAuC,OAAO,MAAM,SAAS;AAEjE,SAAO,MAAM,iBADO,KAAK,kBAAkB,KAAK,CACN;;CAG5C,MAAMC,gBAA+B,OAAO,UAAsB;AAEhE,SAAO,MAAM,iBADO,aAAa,mBAAmB,MAAM,CAChB;;AAG5C,QAAO;EAAE,MAAM;EAAgB;EAAQ;EAAY;EAAmB;EAAe;;;;;;AAOvF,SAAgB,6BAAgD;AAC9D,SAAQ,UAAyB,kBAA4B;EAC3D,MAAMC,WAAyB,EAAE;AAEjC,OAAK,MAAM,SAAS,eAAe;GACjC,MAAMJ,OAA0B;IAC9B,KAAK,SAAS;IACd,KAAK,IAAI,WAAW,GAAG,CAAC,KAAK,EAAE;IAChC;AACD,YAAS,KAAK,wBAAwB,KAAK,CAAC;;AAG9C,SAAO,QAAQ,QAAQ,SAAS"}
@@ -45,7 +45,7 @@ const MultisigSignatureMeta = {
45
45
  }
46
46
  ]
47
47
  };
48
- const LogicSignatureMeta = {
48
+ const LogicSigSignatureMeta = {
49
49
  name: "LogicSignature",
50
50
  kind: "object",
51
51
  fields: [
@@ -81,8 +81,8 @@ const LogicSignatureMeta = {
81
81
  }
82
82
  ]
83
83
  };
84
- const multiSignatureCodec = new require_object_model.ObjectModelCodec(MultisigSignatureMeta);
85
- const logicSignatureCodec = new require_object_model.ObjectModelCodec(LogicSignatureMeta);
84
+ const multisigSignatureCodec = new require_object_model.ObjectModelCodec(MultisigSignatureMeta);
85
+ const logicSigSignatureCodec = new require_object_model.ObjectModelCodec(LogicSigSignatureMeta);
86
86
  /**
87
87
  * Metadata for SignedTransaction
88
88
  */
@@ -106,13 +106,13 @@ const SignedTransactionMeta = {
106
106
  name: "msig",
107
107
  wireKey: "msig",
108
108
  optional: true,
109
- codec: multiSignatureCodec
109
+ codec: multisigSignatureCodec
110
110
  },
111
111
  {
112
112
  name: "lsig",
113
113
  wireKey: "lsig",
114
114
  optional: true,
115
- codec: logicSignatureCodec
115
+ codec: logicSigSignatureCodec
116
116
  },
117
117
  {
118
118
  name: "authAddress",
@@ -126,6 +126,6 @@ const signedTransactionCodec = new require_object_model.ObjectModelCodec(SignedT
126
126
 
127
127
  //#endregion
128
128
  exports.SignedTransactionMeta = SignedTransactionMeta;
129
- exports.logicSignatureCodec = logicSignatureCodec;
129
+ exports.logicSigSignatureCodec = logicSigSignatureCodec;
130
130
  exports.signedTransactionCodec = signedTransactionCodec;
131
131
  //# sourceMappingURL=signed-transaction-meta.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"signed-transaction-meta.js","names":["MultisigSignatureMeta: ObjectModelMetadata<MultisigSignature>","numberCodec","ArrayCodec","ObjectModelCodec","fixedBytes32Codec","fixedBytes64Codec","LogicSignatureMeta: ObjectModelMetadata<LogicSignature>","bytesCodec","bytesArrayCodec","SignedTransactionMeta: ObjectModelMetadata<SignedTransaction>","transactionCodec","addressCodec"],"sources":["../../../../../packages/transact/src/transactions/signed-transaction-meta.ts"],"sourcesContent":["import type { ObjectModelMetadata } from '@algorandfoundation/algokit-common'\nimport {\n ArrayCodec,\n ObjectModelCodec,\n addressCodec,\n bytesArrayCodec,\n bytesCodec,\n fixedBytes32Codec,\n fixedBytes64Codec,\n numberCodec,\n} from '@algorandfoundation/algokit-common'\nimport { LogicSignature, MultisigSignature, MultisigSubsignature, SignedTransaction } from './signed-transaction'\nimport { transactionCodec } from './transaction'\n\nconst MultisigSubsignatureMeta: ObjectModelMetadata<MultisigSubsignature> = {\n name: 'MultisigSubsignature',\n kind: 'object',\n fields: [\n { name: 'publicKey', wireKey: 'pk', optional: false, codec: fixedBytes32Codec },\n { name: 'sig', wireKey: 's', optional: true, codec: fixedBytes64Codec },\n ],\n}\n\nconst MultisigSignatureMeta: ObjectModelMetadata<MultisigSignature> = {\n name: 'MultisigSignature',\n kind: 'object',\n fields: [\n { name: 'version', wireKey: 'v', optional: false, codec: numberCodec },\n { name: 'threshold', wireKey: 'thr', optional: false, codec: numberCodec },\n {\n name: 'subsigs',\n wireKey: 'subsig',\n optional: false,\n codec: new ArrayCodec(new ObjectModelCodec(MultisigSubsignatureMeta)),\n },\n ],\n}\n\nconst LogicSignatureMeta: ObjectModelMetadata<LogicSignature> = {\n name: 'LogicSignature',\n kind: 'object',\n fields: [\n { name: 'logic', wireKey: 'l', optional: false, codec: bytesCodec },\n { name: 'args', wireKey: 'arg', optional: true, codec: bytesArrayCodec },\n { name: 'sig', wireKey: 'sig', optional: true, codec: fixedBytes64Codec },\n {\n name: 'msig',\n wireKey: 'msig',\n optional: true,\n codec: new ObjectModelCodec(MultisigSignatureMeta),\n },\n {\n name: 'lmsig',\n wireKey: 'lmsig',\n optional: true,\n codec: new ObjectModelCodec(MultisigSignatureMeta),\n },\n ],\n}\n\nexport const multiSignatureCodec = new ObjectModelCodec<MultisigSignature>(MultisigSignatureMeta)\nexport const logicSignatureCodec = new ObjectModelCodec<LogicSignature>(LogicSignatureMeta)\n\n/**\n * Metadata for SignedTransaction\n */\nexport const SignedTransactionMeta: ObjectModelMetadata<SignedTransaction> = {\n name: 'SignedTransaction',\n kind: 'object',\n fields: [\n {\n name: 'txn',\n wireKey: 'txn',\n optional: false,\n codec: transactionCodec,\n },\n { name: 'sig', wireKey: 'sig', optional: true, codec: fixedBytes64Codec },\n {\n name: 'msig',\n wireKey: 'msig',\n optional: true,\n codec: multiSignatureCodec,\n },\n {\n name: 'lsig',\n wireKey: 'lsig',\n optional: true,\n codec: logicSignatureCodec,\n },\n { name: 'authAddress', wireKey: 'sgnr', optional: true, codec: addressCodec },\n ],\n}\n\nexport const signedTransactionCodec = new ObjectModelCodec<SignedTransaction>(SignedTransactionMeta)\n"],"mappings":";;;;;;;;;AAuBA,MAAMA,wBAAgE;CACpE,MAAM;CACN,MAAM;CACN,QAAQ;EACN;GAAE,MAAM;GAAW,SAAS;GAAK,UAAU;GAAO,OAAOC;GAAa;EACtE;GAAE,MAAM;GAAa,SAAS;GAAO,UAAU;GAAO,OAAOA;GAAa;EAC1E;GACE,MAAM;GACN,SAAS;GACT,UAAU;GACV,OAAO,IAAIC,yBAAW,IAAIC,sCAnB4C;IAC1E,MAAM;IACN,MAAM;IACN,QAAQ,CACN;KAAE,MAAM;KAAa,SAAS;KAAM,UAAU;KAAO,OAAOC;KAAmB,EAC/E;KAAE,MAAM;KAAO,SAAS;KAAK,UAAU;KAAM,OAAOC;KAAmB,CACxE;IACF,CAYyE,CAAC;GACtE;EACF;CACF;AAED,MAAMC,qBAA0D;CAC9D,MAAM;CACN,MAAM;CACN,QAAQ;EACN;GAAE,MAAM;GAAS,SAAS;GAAK,UAAU;GAAO,OAAOC;GAAY;EACnE;GAAE,MAAM;GAAQ,SAAS;GAAO,UAAU;GAAM,OAAOC;GAAiB;EACxE;GAAE,MAAM;GAAO,SAAS;GAAO,UAAU;GAAM,OAAOH;GAAmB;EACzE;GACE,MAAM;GACN,SAAS;GACT,UAAU;GACV,OAAO,IAAIF,sCAAiB,sBAAsB;GACnD;EACD;GACE,MAAM;GACN,SAAS;GACT,UAAU;GACV,OAAO,IAAIA,sCAAiB,sBAAsB;GACnD;EACF;CACF;AAED,MAAa,sBAAsB,IAAIA,sCAAoC,sBAAsB;AACjG,MAAa,sBAAsB,IAAIA,sCAAiC,mBAAmB;;;;AAK3F,MAAaM,wBAAgE;CAC3E,MAAM;CACN,MAAM;CACN,QAAQ;EACN;GACE,MAAM;GACN,SAAS;GACT,UAAU;GACV,OAAOC;GACR;EACD;GAAE,MAAM;GAAO,SAAS;GAAO,UAAU;GAAM,OAAOL;GAAmB;EACzE;GACE,MAAM;GACN,SAAS;GACT,UAAU;GACV,OAAO;GACR;EACD;GACE,MAAM;GACN,SAAS;GACT,UAAU;GACV,OAAO;GACR;EACD;GAAE,MAAM;GAAe,SAAS;GAAQ,UAAU;GAAM,OAAOM;GAAc;EAC9E;CACF;AAED,MAAa,yBAAyB,IAAIR,sCAAoC,sBAAsB"}
1
+ {"version":3,"file":"signed-transaction-meta.js","names":["MultisigSignatureMeta: ObjectModelMetadata<MultisigSignature>","numberCodec","ArrayCodec","ObjectModelCodec","fixedBytes32Codec","fixedBytes64Codec","LogicSigSignatureMeta: ObjectModelMetadata<LogicSigSignature>","bytesCodec","bytesArrayCodec","SignedTransactionMeta: ObjectModelMetadata<SignedTransaction>","transactionCodec","addressCodec"],"sources":["../../../../../packages/transact/src/transactions/signed-transaction-meta.ts"],"sourcesContent":["import type { ObjectModelMetadata } from '@algorandfoundation/algokit-common'\nimport {\n ArrayCodec,\n ObjectModelCodec,\n addressCodec,\n bytesArrayCodec,\n bytesCodec,\n fixedBytes32Codec,\n fixedBytes64Codec,\n numberCodec,\n} from '@algorandfoundation/algokit-common'\nimport { LogicSigSignature, MultisigSignature, MultisigSubsignature, SignedTransaction } from './signed-transaction'\nimport { transactionCodec } from './transaction'\n\nconst MultisigSubsignatureMeta: ObjectModelMetadata<MultisigSubsignature> = {\n name: 'MultisigSubsignature',\n kind: 'object',\n fields: [\n { name: 'publicKey', wireKey: 'pk', optional: false, codec: fixedBytes32Codec },\n { name: 'sig', wireKey: 's', optional: true, codec: fixedBytes64Codec },\n ],\n}\n\nconst MultisigSignatureMeta: ObjectModelMetadata<MultisigSignature> = {\n name: 'MultisigSignature',\n kind: 'object',\n fields: [\n { name: 'version', wireKey: 'v', optional: false, codec: numberCodec },\n { name: 'threshold', wireKey: 'thr', optional: false, codec: numberCodec },\n {\n name: 'subsigs',\n wireKey: 'subsig',\n optional: false,\n codec: new ArrayCodec(new ObjectModelCodec(MultisigSubsignatureMeta)),\n },\n ],\n}\n\nconst LogicSigSignatureMeta: ObjectModelMetadata<LogicSigSignature> = {\n name: 'LogicSignature',\n kind: 'object',\n fields: [\n { name: 'logic', wireKey: 'l', optional: false, codec: bytesCodec },\n { name: 'args', wireKey: 'arg', optional: true, codec: bytesArrayCodec },\n { name: 'sig', wireKey: 'sig', optional: true, codec: fixedBytes64Codec },\n {\n name: 'msig',\n wireKey: 'msig',\n optional: true,\n codec: new ObjectModelCodec(MultisigSignatureMeta),\n },\n {\n name: 'lmsig',\n wireKey: 'lmsig',\n optional: true,\n codec: new ObjectModelCodec(MultisigSignatureMeta),\n },\n ],\n}\n\nexport const multisigSignatureCodec = new ObjectModelCodec<MultisigSignature>(MultisigSignatureMeta)\nexport const logicSigSignatureCodec = new ObjectModelCodec<LogicSigSignature>(LogicSigSignatureMeta)\n\n/**\n * Metadata for SignedTransaction\n */\nexport const SignedTransactionMeta: ObjectModelMetadata<SignedTransaction> = {\n name: 'SignedTransaction',\n kind: 'object',\n fields: [\n {\n name: 'txn',\n wireKey: 'txn',\n optional: false,\n codec: transactionCodec,\n },\n { name: 'sig', wireKey: 'sig', optional: true, codec: fixedBytes64Codec },\n {\n name: 'msig',\n wireKey: 'msig',\n optional: true,\n codec: multisigSignatureCodec,\n },\n {\n name: 'lsig',\n wireKey: 'lsig',\n optional: true,\n codec: logicSigSignatureCodec,\n },\n { name: 'authAddress', wireKey: 'sgnr', optional: true, codec: addressCodec },\n ],\n}\n\nexport const signedTransactionCodec = new ObjectModelCodec<SignedTransaction>(SignedTransactionMeta)\n"],"mappings":";;;;;;;;;AAuBA,MAAMA,wBAAgE;CACpE,MAAM;CACN,MAAM;CACN,QAAQ;EACN;GAAE,MAAM;GAAW,SAAS;GAAK,UAAU;GAAO,OAAOC;GAAa;EACtE;GAAE,MAAM;GAAa,SAAS;GAAO,UAAU;GAAO,OAAOA;GAAa;EAC1E;GACE,MAAM;GACN,SAAS;GACT,UAAU;GACV,OAAO,IAAIC,yBAAW,IAAIC,sCAnB4C;IAC1E,MAAM;IACN,MAAM;IACN,QAAQ,CACN;KAAE,MAAM;KAAa,SAAS;KAAM,UAAU;KAAO,OAAOC;KAAmB,EAC/E;KAAE,MAAM;KAAO,SAAS;KAAK,UAAU;KAAM,OAAOC;KAAmB,CACxE;IACF,CAYyE,CAAC;GACtE;EACF;CACF;AAED,MAAMC,wBAAgE;CACpE,MAAM;CACN,MAAM;CACN,QAAQ;EACN;GAAE,MAAM;GAAS,SAAS;GAAK,UAAU;GAAO,OAAOC;GAAY;EACnE;GAAE,MAAM;GAAQ,SAAS;GAAO,UAAU;GAAM,OAAOC;GAAiB;EACxE;GAAE,MAAM;GAAO,SAAS;GAAO,UAAU;GAAM,OAAOH;GAAmB;EACzE;GACE,MAAM;GACN,SAAS;GACT,UAAU;GACV,OAAO,IAAIF,sCAAiB,sBAAsB;GACnD;EACD;GACE,MAAM;GACN,SAAS;GACT,UAAU;GACV,OAAO,IAAIA,sCAAiB,sBAAsB;GACnD;EACF;CACF;AAED,MAAa,yBAAyB,IAAIA,sCAAoC,sBAAsB;AACpG,MAAa,yBAAyB,IAAIA,sCAAoC,sBAAsB;;;;AAKpG,MAAaM,wBAAgE;CAC3E,MAAM;CACN,MAAM;CACN,QAAQ;EACN;GACE,MAAM;GACN,SAAS;GACT,UAAU;GACV,OAAOC;GACR;EACD;GAAE,MAAM;GAAO,SAAS;GAAO,UAAU;GAAM,OAAOL;GAAmB;EACzE;GACE,MAAM;GACN,SAAS;GACT,UAAU;GACV,OAAO;GACR;EACD;GACE,MAAM;GACN,SAAS;GACT,UAAU;GACV,OAAO;GACR;EACD;GAAE,MAAM;GAAe,SAAS;GAAQ,UAAU;GAAM,OAAOM;GAAc;EAC9E;CACF;AAED,MAAa,yBAAyB,IAAIR,sCAAoC,sBAAsB"}
@@ -45,7 +45,7 @@ const MultisigSignatureMeta = {
45
45
  }
46
46
  ]
47
47
  };
48
- const LogicSignatureMeta = {
48
+ const LogicSigSignatureMeta = {
49
49
  name: "LogicSignature",
50
50
  kind: "object",
51
51
  fields: [
@@ -81,8 +81,8 @@ const LogicSignatureMeta = {
81
81
  }
82
82
  ]
83
83
  };
84
- const multiSignatureCodec = new ObjectModelCodec(MultisigSignatureMeta);
85
- const logicSignatureCodec = new ObjectModelCodec(LogicSignatureMeta);
84
+ const multisigSignatureCodec = new ObjectModelCodec(MultisigSignatureMeta);
85
+ const logicSigSignatureCodec = new ObjectModelCodec(LogicSigSignatureMeta);
86
86
  /**
87
87
  * Metadata for SignedTransaction
88
88
  */
@@ -106,13 +106,13 @@ const SignedTransactionMeta = {
106
106
  name: "msig",
107
107
  wireKey: "msig",
108
108
  optional: true,
109
- codec: multiSignatureCodec
109
+ codec: multisigSignatureCodec
110
110
  },
111
111
  {
112
112
  name: "lsig",
113
113
  wireKey: "lsig",
114
114
  optional: true,
115
- codec: logicSignatureCodec
115
+ codec: logicSigSignatureCodec
116
116
  },
117
117
  {
118
118
  name: "authAddress",
@@ -125,5 +125,5 @@ const SignedTransactionMeta = {
125
125
  const signedTransactionCodec = new ObjectModelCodec(SignedTransactionMeta);
126
126
 
127
127
  //#endregion
128
- export { SignedTransactionMeta, logicSignatureCodec, signedTransactionCodec };
128
+ export { SignedTransactionMeta, logicSigSignatureCodec, signedTransactionCodec };
129
129
  //# sourceMappingURL=signed-transaction-meta.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"signed-transaction-meta.mjs","names":["MultisigSignatureMeta: ObjectModelMetadata<MultisigSignature>","LogicSignatureMeta: ObjectModelMetadata<LogicSignature>","SignedTransactionMeta: ObjectModelMetadata<SignedTransaction>"],"sources":["../../../../../packages/transact/src/transactions/signed-transaction-meta.ts"],"sourcesContent":["import type { ObjectModelMetadata } from '@algorandfoundation/algokit-common'\nimport {\n ArrayCodec,\n ObjectModelCodec,\n addressCodec,\n bytesArrayCodec,\n bytesCodec,\n fixedBytes32Codec,\n fixedBytes64Codec,\n numberCodec,\n} from '@algorandfoundation/algokit-common'\nimport { LogicSignature, MultisigSignature, MultisigSubsignature, SignedTransaction } from './signed-transaction'\nimport { transactionCodec } from './transaction'\n\nconst MultisigSubsignatureMeta: ObjectModelMetadata<MultisigSubsignature> = {\n name: 'MultisigSubsignature',\n kind: 'object',\n fields: [\n { name: 'publicKey', wireKey: 'pk', optional: false, codec: fixedBytes32Codec },\n { name: 'sig', wireKey: 's', optional: true, codec: fixedBytes64Codec },\n ],\n}\n\nconst MultisigSignatureMeta: ObjectModelMetadata<MultisigSignature> = {\n name: 'MultisigSignature',\n kind: 'object',\n fields: [\n { name: 'version', wireKey: 'v', optional: false, codec: numberCodec },\n { name: 'threshold', wireKey: 'thr', optional: false, codec: numberCodec },\n {\n name: 'subsigs',\n wireKey: 'subsig',\n optional: false,\n codec: new ArrayCodec(new ObjectModelCodec(MultisigSubsignatureMeta)),\n },\n ],\n}\n\nconst LogicSignatureMeta: ObjectModelMetadata<LogicSignature> = {\n name: 'LogicSignature',\n kind: 'object',\n fields: [\n { name: 'logic', wireKey: 'l', optional: false, codec: bytesCodec },\n { name: 'args', wireKey: 'arg', optional: true, codec: bytesArrayCodec },\n { name: 'sig', wireKey: 'sig', optional: true, codec: fixedBytes64Codec },\n {\n name: 'msig',\n wireKey: 'msig',\n optional: true,\n codec: new ObjectModelCodec(MultisigSignatureMeta),\n },\n {\n name: 'lmsig',\n wireKey: 'lmsig',\n optional: true,\n codec: new ObjectModelCodec(MultisigSignatureMeta),\n },\n ],\n}\n\nexport const multiSignatureCodec = new ObjectModelCodec<MultisigSignature>(MultisigSignatureMeta)\nexport const logicSignatureCodec = new ObjectModelCodec<LogicSignature>(LogicSignatureMeta)\n\n/**\n * Metadata for SignedTransaction\n */\nexport const SignedTransactionMeta: ObjectModelMetadata<SignedTransaction> = {\n name: 'SignedTransaction',\n kind: 'object',\n fields: [\n {\n name: 'txn',\n wireKey: 'txn',\n optional: false,\n codec: transactionCodec,\n },\n { name: 'sig', wireKey: 'sig', optional: true, codec: fixedBytes64Codec },\n {\n name: 'msig',\n wireKey: 'msig',\n optional: true,\n codec: multiSignatureCodec,\n },\n {\n name: 'lsig',\n wireKey: 'lsig',\n optional: true,\n codec: logicSignatureCodec,\n },\n { name: 'authAddress', wireKey: 'sgnr', optional: true, codec: addressCodec },\n ],\n}\n\nexport const signedTransactionCodec = new ObjectModelCodec<SignedTransaction>(SignedTransactionMeta)\n"],"mappings":";;;;;;;;;AAuBA,MAAMA,wBAAgE;CACpE,MAAM;CACN,MAAM;CACN,QAAQ;EACN;GAAE,MAAM;GAAW,SAAS;GAAK,UAAU;GAAO,OAAO;GAAa;EACtE;GAAE,MAAM;GAAa,SAAS;GAAO,UAAU;GAAO,OAAO;GAAa;EAC1E;GACE,MAAM;GACN,SAAS;GACT,UAAU;GACV,OAAO,IAAI,WAAW,IAAI,iBAnB4C;IAC1E,MAAM;IACN,MAAM;IACN,QAAQ,CACN;KAAE,MAAM;KAAa,SAAS;KAAM,UAAU;KAAO,OAAO;KAAmB,EAC/E;KAAE,MAAM;KAAO,SAAS;KAAK,UAAU;KAAM,OAAO;KAAmB,CACxE;IACF,CAYyE,CAAC;GACtE;EACF;CACF;AAED,MAAMC,qBAA0D;CAC9D,MAAM;CACN,MAAM;CACN,QAAQ;EACN;GAAE,MAAM;GAAS,SAAS;GAAK,UAAU;GAAO,OAAO;GAAY;EACnE;GAAE,MAAM;GAAQ,SAAS;GAAO,UAAU;GAAM,OAAO;GAAiB;EACxE;GAAE,MAAM;GAAO,SAAS;GAAO,UAAU;GAAM,OAAO;GAAmB;EACzE;GACE,MAAM;GACN,SAAS;GACT,UAAU;GACV,OAAO,IAAI,iBAAiB,sBAAsB;GACnD;EACD;GACE,MAAM;GACN,SAAS;GACT,UAAU;GACV,OAAO,IAAI,iBAAiB,sBAAsB;GACnD;EACF;CACF;AAED,MAAa,sBAAsB,IAAI,iBAAoC,sBAAsB;AACjG,MAAa,sBAAsB,IAAI,iBAAiC,mBAAmB;;;;AAK3F,MAAaC,wBAAgE;CAC3E,MAAM;CACN,MAAM;CACN,QAAQ;EACN;GACE,MAAM;GACN,SAAS;GACT,UAAU;GACV,OAAO;GACR;EACD;GAAE,MAAM;GAAO,SAAS;GAAO,UAAU;GAAM,OAAO;GAAmB;EACzE;GACE,MAAM;GACN,SAAS;GACT,UAAU;GACV,OAAO;GACR;EACD;GACE,MAAM;GACN,SAAS;GACT,UAAU;GACV,OAAO;GACR;EACD;GAAE,MAAM;GAAe,SAAS;GAAQ,UAAU;GAAM,OAAO;GAAc;EAC9E;CACF;AAED,MAAa,yBAAyB,IAAI,iBAAoC,sBAAsB"}
1
+ {"version":3,"file":"signed-transaction-meta.mjs","names":["MultisigSignatureMeta: ObjectModelMetadata<MultisigSignature>","LogicSigSignatureMeta: ObjectModelMetadata<LogicSigSignature>","SignedTransactionMeta: ObjectModelMetadata<SignedTransaction>"],"sources":["../../../../../packages/transact/src/transactions/signed-transaction-meta.ts"],"sourcesContent":["import type { ObjectModelMetadata } from '@algorandfoundation/algokit-common'\nimport {\n ArrayCodec,\n ObjectModelCodec,\n addressCodec,\n bytesArrayCodec,\n bytesCodec,\n fixedBytes32Codec,\n fixedBytes64Codec,\n numberCodec,\n} from '@algorandfoundation/algokit-common'\nimport { LogicSigSignature, MultisigSignature, MultisigSubsignature, SignedTransaction } from './signed-transaction'\nimport { transactionCodec } from './transaction'\n\nconst MultisigSubsignatureMeta: ObjectModelMetadata<MultisigSubsignature> = {\n name: 'MultisigSubsignature',\n kind: 'object',\n fields: [\n { name: 'publicKey', wireKey: 'pk', optional: false, codec: fixedBytes32Codec },\n { name: 'sig', wireKey: 's', optional: true, codec: fixedBytes64Codec },\n ],\n}\n\nconst MultisigSignatureMeta: ObjectModelMetadata<MultisigSignature> = {\n name: 'MultisigSignature',\n kind: 'object',\n fields: [\n { name: 'version', wireKey: 'v', optional: false, codec: numberCodec },\n { name: 'threshold', wireKey: 'thr', optional: false, codec: numberCodec },\n {\n name: 'subsigs',\n wireKey: 'subsig',\n optional: false,\n codec: new ArrayCodec(new ObjectModelCodec(MultisigSubsignatureMeta)),\n },\n ],\n}\n\nconst LogicSigSignatureMeta: ObjectModelMetadata<LogicSigSignature> = {\n name: 'LogicSignature',\n kind: 'object',\n fields: [\n { name: 'logic', wireKey: 'l', optional: false, codec: bytesCodec },\n { name: 'args', wireKey: 'arg', optional: true, codec: bytesArrayCodec },\n { name: 'sig', wireKey: 'sig', optional: true, codec: fixedBytes64Codec },\n {\n name: 'msig',\n wireKey: 'msig',\n optional: true,\n codec: new ObjectModelCodec(MultisigSignatureMeta),\n },\n {\n name: 'lmsig',\n wireKey: 'lmsig',\n optional: true,\n codec: new ObjectModelCodec(MultisigSignatureMeta),\n },\n ],\n}\n\nexport const multisigSignatureCodec = new ObjectModelCodec<MultisigSignature>(MultisigSignatureMeta)\nexport const logicSigSignatureCodec = new ObjectModelCodec<LogicSigSignature>(LogicSigSignatureMeta)\n\n/**\n * Metadata for SignedTransaction\n */\nexport const SignedTransactionMeta: ObjectModelMetadata<SignedTransaction> = {\n name: 'SignedTransaction',\n kind: 'object',\n fields: [\n {\n name: 'txn',\n wireKey: 'txn',\n optional: false,\n codec: transactionCodec,\n },\n { name: 'sig', wireKey: 'sig', optional: true, codec: fixedBytes64Codec },\n {\n name: 'msig',\n wireKey: 'msig',\n optional: true,\n codec: multisigSignatureCodec,\n },\n {\n name: 'lsig',\n wireKey: 'lsig',\n optional: true,\n codec: logicSigSignatureCodec,\n },\n { name: 'authAddress', wireKey: 'sgnr', optional: true, codec: addressCodec },\n ],\n}\n\nexport const signedTransactionCodec = new ObjectModelCodec<SignedTransaction>(SignedTransactionMeta)\n"],"mappings":";;;;;;;;;AAuBA,MAAMA,wBAAgE;CACpE,MAAM;CACN,MAAM;CACN,QAAQ;EACN;GAAE,MAAM;GAAW,SAAS;GAAK,UAAU;GAAO,OAAO;GAAa;EACtE;GAAE,MAAM;GAAa,SAAS;GAAO,UAAU;GAAO,OAAO;GAAa;EAC1E;GACE,MAAM;GACN,SAAS;GACT,UAAU;GACV,OAAO,IAAI,WAAW,IAAI,iBAnB4C;IAC1E,MAAM;IACN,MAAM;IACN,QAAQ,CACN;KAAE,MAAM;KAAa,SAAS;KAAM,UAAU;KAAO,OAAO;KAAmB,EAC/E;KAAE,MAAM;KAAO,SAAS;KAAK,UAAU;KAAM,OAAO;KAAmB,CACxE;IACF,CAYyE,CAAC;GACtE;EACF;CACF;AAED,MAAMC,wBAAgE;CACpE,MAAM;CACN,MAAM;CACN,QAAQ;EACN;GAAE,MAAM;GAAS,SAAS;GAAK,UAAU;GAAO,OAAO;GAAY;EACnE;GAAE,MAAM;GAAQ,SAAS;GAAO,UAAU;GAAM,OAAO;GAAiB;EACxE;GAAE,MAAM;GAAO,SAAS;GAAO,UAAU;GAAM,OAAO;GAAmB;EACzE;GACE,MAAM;GACN,SAAS;GACT,UAAU;GACV,OAAO,IAAI,iBAAiB,sBAAsB;GACnD;EACD;GACE,MAAM;GACN,SAAS;GACT,UAAU;GACV,OAAO,IAAI,iBAAiB,sBAAsB;GACnD;EACF;CACF;AAED,MAAa,yBAAyB,IAAI,iBAAoC,sBAAsB;AACpG,MAAa,yBAAyB,IAAI,iBAAoC,sBAAsB;;;;AAKpG,MAAaC,wBAAgE;CAC3E,MAAM;CACN,MAAM;CACN,QAAQ;EACN;GACE,MAAM;GACN,SAAS;GACT,UAAU;GACV,OAAO;GACR;EACD;GAAE,MAAM;GAAO,SAAS;GAAO,UAAU;GAAM,OAAO;GAAmB;EACzE;GACE,MAAM;GACN,SAAS;GACT,UAAU;GACV,OAAO;GACR;EACD;GACE,MAAM;GACN,SAAS;GACT,UAAU;GACV,OAAO;GACR;EACD;GAAE,MAAM;GAAe,SAAS;GAAQ,UAAU;GAAM,OAAO;GAAc;EAC9E;CACF;AAED,MAAa,yBAAyB,IAAI,iBAAoC,sBAAsB"}
@@ -22,7 +22,7 @@ type SignedTransaction = {
22
22
  /**
23
23
  * Optional logic signature for the transaction.
24
24
  */
25
- lsig?: LogicSignature;
25
+ lsig?: LogicSigSignature;
26
26
  /**
27
27
  * Optional auth address applicable if the transaction sender is a rekeyed account.
28
28
  */
@@ -65,9 +65,9 @@ type MultisigSignature = {
65
65
  subsigs: Array<MultisigSubsignature>;
66
66
  };
67
67
  /**
68
- * Logic signature structure
68
+ * LogicSig signature structure
69
69
  */
70
- type LogicSignature = {
70
+ type LogicSigSignature = {
71
71
  /**
72
72
  * Logic signature program
73
73
  */
@@ -126,5 +126,5 @@ declare function decodeSignedTransactions(encodedSignedTransactions: Uint8Array[
126
126
  */
127
127
  declare function validateSignedTransaction(signedTransaction: SignedTransaction): void;
128
128
  //#endregion
129
- export { LogicSignature, MultisigSignature, MultisigSubsignature, SignedTransaction, decodeSignedTransaction, decodeSignedTransactions, encodeSignedTransaction, encodeSignedTransactions, validateSignedTransaction };
129
+ export { LogicSigSignature, MultisigSignature, MultisigSubsignature, SignedTransaction, decodeSignedTransaction, decodeSignedTransactions, encodeSignedTransaction, encodeSignedTransactions, validateSignedTransaction };
130
130
  //# sourceMappingURL=signed-transaction.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"signed-transaction.js","names":["encodeMsgpack","signedTransactionCodec","decodeMsgpack"],"sources":["../../../../../packages/transact/src/transactions/signed-transaction.ts"],"sourcesContent":["import type { Address } from '@algorandfoundation/algokit-common'\nimport { decodeMsgpack, encodeMsgpack } from '@algorandfoundation/algokit-common'\nimport { signedTransactionCodec } from './signed-transaction-meta'\nimport { Transaction, validateTransaction } from './transaction'\n\n/**\n * Represents a signed Algorand transaction\n */\nexport type SignedTransaction = {\n /**\n * The transaction that has been signed.\n */\n txn: Transaction\n\n /**\n * Optional Ed25519 signature authorizing the transaction.\n */\n sig?: Uint8Array\n\n /**\n * Optional multisignature signature for the transaction.\n */\n msig?: MultisigSignature\n\n /**\n * Optional logic signature for the transaction.\n */\n lsig?: LogicSignature\n\n /**\n * Optional auth address applicable if the transaction sender is a rekeyed account.\n */\n authAddress?: Address\n}\n\n/**\n * Represents a single subsignature in a multisignature transaction.\n *\n * Each subsignature contains the public key of a participant and an optional signature.\n */\nexport type MultisigSubsignature = {\n /**\n * Public key of a keypair account participant that is sub-signing a multisignature transaction.\n */\n publicKey: Uint8Array\n\n /**\n * Optional Ed25519 signature for the transaction.\n */\n sig?: Uint8Array\n}\n\n/**\n * Represents an Algorand multisignature signature.\n *\n * A multisignature signature is defined by a version, a threshold, and a list of participating addresses.\n * The version indicates the multisig protocol version, while the threshold specifies the minimum number of signatures required to authorize a transaction.\n * While technically this accepts `Address` types, it is expected that these will be the addresses of Ed25519 public keys.\n */\nexport type MultisigSignature = {\n /**\n * Multisig version.\n */\n version: number\n\n /**\n * Minimum number of signatures required.\n */\n threshold: number\n\n /**\n * Array of subsignatures\n */\n subsigs: Array<MultisigSubsignature>\n}\n\n/**\n * Logic signature structure\n */\nexport type LogicSignature = {\n /**\n * Logic signature program\n */\n logic: Uint8Array\n\n /**\n * Logic signature arguments\n */\n args?: Uint8Array[]\n\n /**\n * Signature for delegated logic sig\n */\n sig?: Uint8Array\n\n /**\n * Legacy multisig for delegated logic sig\n */\n msig?: MultisigSignature\n\n /**\n * Multisig for delegated logic sig\n */\n lmsig?: MultisigSignature\n}\n\n/**\n * Encode signed transactions to MsgPack for sending on the network.\n *\n * This method performs canonical encoding. No domain separation prefix is applicable.\n *\n * @param signedTransaction - The signed transaction to encode\n * @returns The MsgPack encoded bytes or an error if encoding fails.\n */\nexport function encodeSignedTransaction(signedTransaction: SignedTransaction): Uint8Array {\n const encodingData = signedTransactionCodec.encode(signedTransaction, 'msgpack')\n return encodeMsgpack(encodingData)\n}\n\n/**\n * Encode signed transactions to MsgPack for sending on the network.\n *\n * This method performs canonical encoding. No domain separation prefix is applicable.\n *\n * @param signedTransactions - A collection of signed transactions to encode\n * @returns A collection of MsgPack encoded bytes or an error if encoding fails.\n */\nexport function encodeSignedTransactions(signedTransactions: SignedTransaction[]): Uint8Array[] {\n return signedTransactions.map((st) => encodeSignedTransaction(st))\n}\n\n/**\n * Decodes MsgPack bytes into a signed transaction.\n *\n * @param encodedSignedTransaction - The MsgPack encoded signed transaction bytes\n * @returns The decoded SignedTransaction or an error if decoding fails.\n */\nexport function decodeSignedTransaction(encodedSignedTransaction: Uint8Array): SignedTransaction {\n const decodedData = decodeMsgpack(encodedSignedTransaction)\n return signedTransactionCodec.decode(decodedData, 'msgpack')\n}\n\n/**\n * Decodes a collection of MsgPack bytes into a signed transaction collection.\n *\n * @param encodedSignedTransactions - A collection of MsgPack encoded bytes, each representing a signed transaction.\n * @returns A collection of decoded signed transactions or an error if decoding fails.\n */\nexport function decodeSignedTransactions(encodedSignedTransactions: Uint8Array[]): SignedTransaction[] {\n return encodedSignedTransactions.map((est) => decodeSignedTransaction(est))\n}\n\n/**\n * Validate a signed transaction structure\n */\nexport function validateSignedTransaction(signedTransaction: SignedTransaction): void {\n validateTransaction(signedTransaction.txn)\n\n // Validate that only one signature type is set\n const sigTypes = [signedTransaction.sig, signedTransaction.msig, signedTransaction.lsig]\n const setSigCount = sigTypes.filter((sig) => sig !== undefined).length\n\n if (setSigCount > 1) {\n throw new Error(`Only one signature type can be set, found ${setSigCount}`)\n }\n\n // Validate signature lengths\n if (signedTransaction.sig && signedTransaction.sig.length !== 64) {\n throw new Error('Signature must be 64 bytes')\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAkHA,SAAgB,wBAAwB,mBAAkD;AAExF,QAAOA,8BADcC,uDAAuB,OAAO,mBAAmB,UAAU,CAC9C;;;;;;;;;;AAWpC,SAAgB,yBAAyB,oBAAuD;AAC9F,QAAO,mBAAmB,KAAK,OAAO,wBAAwB,GAAG,CAAC;;;;;;;;AASpE,SAAgB,wBAAwB,0BAAyD;CAC/F,MAAM,cAAcC,8BAAc,yBAAyB;AAC3D,QAAOD,uDAAuB,OAAO,aAAa,UAAU;;;;;;;;AAS9D,SAAgB,yBAAyB,2BAA8D;AACrG,QAAO,0BAA0B,KAAK,QAAQ,wBAAwB,IAAI,CAAC;;;;;AAM7E,SAAgB,0BAA0B,mBAA4C;AACpF,yCAAoB,kBAAkB,IAAI;CAI1C,MAAM,cADW;EAAC,kBAAkB;EAAK,kBAAkB;EAAM,kBAAkB;EAAK,CAC3D,QAAQ,QAAQ,QAAQ,OAAU,CAAC;AAEhE,KAAI,cAAc,EAChB,OAAM,IAAI,MAAM,6CAA6C,cAAc;AAI7E,KAAI,kBAAkB,OAAO,kBAAkB,IAAI,WAAW,GAC5D,OAAM,IAAI,MAAM,6BAA6B"}
1
+ {"version":3,"file":"signed-transaction.js","names":["encodeMsgpack","signedTransactionCodec","decodeMsgpack"],"sources":["../../../../../packages/transact/src/transactions/signed-transaction.ts"],"sourcesContent":["import type { Address } from '@algorandfoundation/algokit-common'\nimport { decodeMsgpack, encodeMsgpack } from '@algorandfoundation/algokit-common'\nimport { signedTransactionCodec } from './signed-transaction-meta'\nimport { Transaction, validateTransaction } from './transaction'\n\n/**\n * Represents a signed Algorand transaction\n */\nexport type SignedTransaction = {\n /**\n * The transaction that has been signed.\n */\n txn: Transaction\n\n /**\n * Optional Ed25519 signature authorizing the transaction.\n */\n sig?: Uint8Array\n\n /**\n * Optional multisignature signature for the transaction.\n */\n msig?: MultisigSignature\n\n /**\n * Optional logic signature for the transaction.\n */\n lsig?: LogicSigSignature\n\n /**\n * Optional auth address applicable if the transaction sender is a rekeyed account.\n */\n authAddress?: Address\n}\n\n/**\n * Represents a single subsignature in a multisignature transaction.\n *\n * Each subsignature contains the public key of a participant and an optional signature.\n */\nexport type MultisigSubsignature = {\n /**\n * Public key of a keypair account participant that is sub-signing a multisignature transaction.\n */\n publicKey: Uint8Array\n\n /**\n * Optional Ed25519 signature for the transaction.\n */\n sig?: Uint8Array\n}\n\n/**\n * Represents an Algorand multisignature signature.\n *\n * A multisignature signature is defined by a version, a threshold, and a list of participating addresses.\n * The version indicates the multisig protocol version, while the threshold specifies the minimum number of signatures required to authorize a transaction.\n * While technically this accepts `Address` types, it is expected that these will be the addresses of Ed25519 public keys.\n */\nexport type MultisigSignature = {\n /**\n * Multisig version.\n */\n version: number\n\n /**\n * Minimum number of signatures required.\n */\n threshold: number\n\n /**\n * Array of subsignatures\n */\n subsigs: Array<MultisigSubsignature>\n}\n\n/**\n * LogicSig signature structure\n */\nexport type LogicSigSignature = {\n /**\n * Logic signature program\n */\n logic: Uint8Array\n\n /**\n * Logic signature arguments\n */\n args?: Uint8Array[]\n\n /**\n * Signature for delegated logic sig\n */\n sig?: Uint8Array\n\n /**\n * Legacy multisig for delegated logic sig\n */\n msig?: MultisigSignature\n\n /**\n * Multisig for delegated logic sig\n */\n lmsig?: MultisigSignature\n}\n\n/**\n * Encode signed transactions to MsgPack for sending on the network.\n *\n * This method performs canonical encoding. No domain separation prefix is applicable.\n *\n * @param signedTransaction - The signed transaction to encode\n * @returns The MsgPack encoded bytes or an error if encoding fails.\n */\nexport function encodeSignedTransaction(signedTransaction: SignedTransaction): Uint8Array {\n const encodingData = signedTransactionCodec.encode(signedTransaction, 'msgpack')\n return encodeMsgpack(encodingData)\n}\n\n/**\n * Encode signed transactions to MsgPack for sending on the network.\n *\n * This method performs canonical encoding. No domain separation prefix is applicable.\n *\n * @param signedTransactions - A collection of signed transactions to encode\n * @returns A collection of MsgPack encoded bytes or an error if encoding fails.\n */\nexport function encodeSignedTransactions(signedTransactions: SignedTransaction[]): Uint8Array[] {\n return signedTransactions.map((st) => encodeSignedTransaction(st))\n}\n\n/**\n * Decodes MsgPack bytes into a signed transaction.\n *\n * @param encodedSignedTransaction - The MsgPack encoded signed transaction bytes\n * @returns The decoded SignedTransaction or an error if decoding fails.\n */\nexport function decodeSignedTransaction(encodedSignedTransaction: Uint8Array): SignedTransaction {\n const decodedData = decodeMsgpack(encodedSignedTransaction)\n return signedTransactionCodec.decode(decodedData, 'msgpack')\n}\n\n/**\n * Decodes a collection of MsgPack bytes into a signed transaction collection.\n *\n * @param encodedSignedTransactions - A collection of MsgPack encoded bytes, each representing a signed transaction.\n * @returns A collection of decoded signed transactions or an error if decoding fails.\n */\nexport function decodeSignedTransactions(encodedSignedTransactions: Uint8Array[]): SignedTransaction[] {\n return encodedSignedTransactions.map((est) => decodeSignedTransaction(est))\n}\n\n/**\n * Validate a signed transaction structure\n */\nexport function validateSignedTransaction(signedTransaction: SignedTransaction): void {\n validateTransaction(signedTransaction.txn)\n\n // Validate that only one signature type is set\n const sigTypes = [signedTransaction.sig, signedTransaction.msig, signedTransaction.lsig]\n const setSigCount = sigTypes.filter((sig) => sig !== undefined).length\n\n if (setSigCount > 1) {\n throw new Error(`Only one signature type can be set, found ${setSigCount}`)\n }\n\n // Validate signature lengths\n if (signedTransaction.sig && signedTransaction.sig.length !== 64) {\n throw new Error('Signature must be 64 bytes')\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAkHA,SAAgB,wBAAwB,mBAAkD;AAExF,QAAOA,8BADcC,uDAAuB,OAAO,mBAAmB,UAAU,CAC9C;;;;;;;;;;AAWpC,SAAgB,yBAAyB,oBAAuD;AAC9F,QAAO,mBAAmB,KAAK,OAAO,wBAAwB,GAAG,CAAC;;;;;;;;AASpE,SAAgB,wBAAwB,0BAAyD;CAC/F,MAAM,cAAcC,8BAAc,yBAAyB;AAC3D,QAAOD,uDAAuB,OAAO,aAAa,UAAU;;;;;;;;AAS9D,SAAgB,yBAAyB,2BAA8D;AACrG,QAAO,0BAA0B,KAAK,QAAQ,wBAAwB,IAAI,CAAC;;;;;AAM7E,SAAgB,0BAA0B,mBAA4C;AACpF,yCAAoB,kBAAkB,IAAI;CAI1C,MAAM,cADW;EAAC,kBAAkB;EAAK,kBAAkB;EAAM,kBAAkB;EAAK,CAC3D,QAAQ,QAAQ,QAAQ,OAAU,CAAC;AAEhE,KAAI,cAAc,EAChB,OAAM,IAAI,MAAM,6CAA6C,cAAc;AAI7E,KAAI,kBAAkB,OAAO,kBAAkB,IAAI,WAAW,GAC5D,OAAM,IAAI,MAAM,6BAA6B"}
@@ -1 +1 @@
1
- {"version":3,"file":"signed-transaction.mjs","names":[],"sources":["../../../../../packages/transact/src/transactions/signed-transaction.ts"],"sourcesContent":["import type { Address } from '@algorandfoundation/algokit-common'\nimport { decodeMsgpack, encodeMsgpack } from '@algorandfoundation/algokit-common'\nimport { signedTransactionCodec } from './signed-transaction-meta'\nimport { Transaction, validateTransaction } from './transaction'\n\n/**\n * Represents a signed Algorand transaction\n */\nexport type SignedTransaction = {\n /**\n * The transaction that has been signed.\n */\n txn: Transaction\n\n /**\n * Optional Ed25519 signature authorizing the transaction.\n */\n sig?: Uint8Array\n\n /**\n * Optional multisignature signature for the transaction.\n */\n msig?: MultisigSignature\n\n /**\n * Optional logic signature for the transaction.\n */\n lsig?: LogicSignature\n\n /**\n * Optional auth address applicable if the transaction sender is a rekeyed account.\n */\n authAddress?: Address\n}\n\n/**\n * Represents a single subsignature in a multisignature transaction.\n *\n * Each subsignature contains the public key of a participant and an optional signature.\n */\nexport type MultisigSubsignature = {\n /**\n * Public key of a keypair account participant that is sub-signing a multisignature transaction.\n */\n publicKey: Uint8Array\n\n /**\n * Optional Ed25519 signature for the transaction.\n */\n sig?: Uint8Array\n}\n\n/**\n * Represents an Algorand multisignature signature.\n *\n * A multisignature signature is defined by a version, a threshold, and a list of participating addresses.\n * The version indicates the multisig protocol version, while the threshold specifies the minimum number of signatures required to authorize a transaction.\n * While technically this accepts `Address` types, it is expected that these will be the addresses of Ed25519 public keys.\n */\nexport type MultisigSignature = {\n /**\n * Multisig version.\n */\n version: number\n\n /**\n * Minimum number of signatures required.\n */\n threshold: number\n\n /**\n * Array of subsignatures\n */\n subsigs: Array<MultisigSubsignature>\n}\n\n/**\n * Logic signature structure\n */\nexport type LogicSignature = {\n /**\n * Logic signature program\n */\n logic: Uint8Array\n\n /**\n * Logic signature arguments\n */\n args?: Uint8Array[]\n\n /**\n * Signature for delegated logic sig\n */\n sig?: Uint8Array\n\n /**\n * Legacy multisig for delegated logic sig\n */\n msig?: MultisigSignature\n\n /**\n * Multisig for delegated logic sig\n */\n lmsig?: MultisigSignature\n}\n\n/**\n * Encode signed transactions to MsgPack for sending on the network.\n *\n * This method performs canonical encoding. No domain separation prefix is applicable.\n *\n * @param signedTransaction - The signed transaction to encode\n * @returns The MsgPack encoded bytes or an error if encoding fails.\n */\nexport function encodeSignedTransaction(signedTransaction: SignedTransaction): Uint8Array {\n const encodingData = signedTransactionCodec.encode(signedTransaction, 'msgpack')\n return encodeMsgpack(encodingData)\n}\n\n/**\n * Encode signed transactions to MsgPack for sending on the network.\n *\n * This method performs canonical encoding. No domain separation prefix is applicable.\n *\n * @param signedTransactions - A collection of signed transactions to encode\n * @returns A collection of MsgPack encoded bytes or an error if encoding fails.\n */\nexport function encodeSignedTransactions(signedTransactions: SignedTransaction[]): Uint8Array[] {\n return signedTransactions.map((st) => encodeSignedTransaction(st))\n}\n\n/**\n * Decodes MsgPack bytes into a signed transaction.\n *\n * @param encodedSignedTransaction - The MsgPack encoded signed transaction bytes\n * @returns The decoded SignedTransaction or an error if decoding fails.\n */\nexport function decodeSignedTransaction(encodedSignedTransaction: Uint8Array): SignedTransaction {\n const decodedData = decodeMsgpack(encodedSignedTransaction)\n return signedTransactionCodec.decode(decodedData, 'msgpack')\n}\n\n/**\n * Decodes a collection of MsgPack bytes into a signed transaction collection.\n *\n * @param encodedSignedTransactions - A collection of MsgPack encoded bytes, each representing a signed transaction.\n * @returns A collection of decoded signed transactions or an error if decoding fails.\n */\nexport function decodeSignedTransactions(encodedSignedTransactions: Uint8Array[]): SignedTransaction[] {\n return encodedSignedTransactions.map((est) => decodeSignedTransaction(est))\n}\n\n/**\n * Validate a signed transaction structure\n */\nexport function validateSignedTransaction(signedTransaction: SignedTransaction): void {\n validateTransaction(signedTransaction.txn)\n\n // Validate that only one signature type is set\n const sigTypes = [signedTransaction.sig, signedTransaction.msig, signedTransaction.lsig]\n const setSigCount = sigTypes.filter((sig) => sig !== undefined).length\n\n if (setSigCount > 1) {\n throw new Error(`Only one signature type can be set, found ${setSigCount}`)\n }\n\n // Validate signature lengths\n if (signedTransaction.sig && signedTransaction.sig.length !== 64) {\n throw new Error('Signature must be 64 bytes')\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAkHA,SAAgB,wBAAwB,mBAAkD;AAExF,QAAO,cADc,uBAAuB,OAAO,mBAAmB,UAAU,CAC9C;;;;;;;;;;AAWpC,SAAgB,yBAAyB,oBAAuD;AAC9F,QAAO,mBAAmB,KAAK,OAAO,wBAAwB,GAAG,CAAC;;;;;;;;AASpE,SAAgB,wBAAwB,0BAAyD;CAC/F,MAAM,cAAc,cAAc,yBAAyB;AAC3D,QAAO,uBAAuB,OAAO,aAAa,UAAU;;;;;;;;AAS9D,SAAgB,yBAAyB,2BAA8D;AACrG,QAAO,0BAA0B,KAAK,QAAQ,wBAAwB,IAAI,CAAC;;;;;AAM7E,SAAgB,0BAA0B,mBAA4C;AACpF,qBAAoB,kBAAkB,IAAI;CAI1C,MAAM,cADW;EAAC,kBAAkB;EAAK,kBAAkB;EAAM,kBAAkB;EAAK,CAC3D,QAAQ,QAAQ,QAAQ,OAAU,CAAC;AAEhE,KAAI,cAAc,EAChB,OAAM,IAAI,MAAM,6CAA6C,cAAc;AAI7E,KAAI,kBAAkB,OAAO,kBAAkB,IAAI,WAAW,GAC5D,OAAM,IAAI,MAAM,6BAA6B"}
1
+ {"version":3,"file":"signed-transaction.mjs","names":[],"sources":["../../../../../packages/transact/src/transactions/signed-transaction.ts"],"sourcesContent":["import type { Address } from '@algorandfoundation/algokit-common'\nimport { decodeMsgpack, encodeMsgpack } from '@algorandfoundation/algokit-common'\nimport { signedTransactionCodec } from './signed-transaction-meta'\nimport { Transaction, validateTransaction } from './transaction'\n\n/**\n * Represents a signed Algorand transaction\n */\nexport type SignedTransaction = {\n /**\n * The transaction that has been signed.\n */\n txn: Transaction\n\n /**\n * Optional Ed25519 signature authorizing the transaction.\n */\n sig?: Uint8Array\n\n /**\n * Optional multisignature signature for the transaction.\n */\n msig?: MultisigSignature\n\n /**\n * Optional logic signature for the transaction.\n */\n lsig?: LogicSigSignature\n\n /**\n * Optional auth address applicable if the transaction sender is a rekeyed account.\n */\n authAddress?: Address\n}\n\n/**\n * Represents a single subsignature in a multisignature transaction.\n *\n * Each subsignature contains the public key of a participant and an optional signature.\n */\nexport type MultisigSubsignature = {\n /**\n * Public key of a keypair account participant that is sub-signing a multisignature transaction.\n */\n publicKey: Uint8Array\n\n /**\n * Optional Ed25519 signature for the transaction.\n */\n sig?: Uint8Array\n}\n\n/**\n * Represents an Algorand multisignature signature.\n *\n * A multisignature signature is defined by a version, a threshold, and a list of participating addresses.\n * The version indicates the multisig protocol version, while the threshold specifies the minimum number of signatures required to authorize a transaction.\n * While technically this accepts `Address` types, it is expected that these will be the addresses of Ed25519 public keys.\n */\nexport type MultisigSignature = {\n /**\n * Multisig version.\n */\n version: number\n\n /**\n * Minimum number of signatures required.\n */\n threshold: number\n\n /**\n * Array of subsignatures\n */\n subsigs: Array<MultisigSubsignature>\n}\n\n/**\n * LogicSig signature structure\n */\nexport type LogicSigSignature = {\n /**\n * Logic signature program\n */\n logic: Uint8Array\n\n /**\n * Logic signature arguments\n */\n args?: Uint8Array[]\n\n /**\n * Signature for delegated logic sig\n */\n sig?: Uint8Array\n\n /**\n * Legacy multisig for delegated logic sig\n */\n msig?: MultisigSignature\n\n /**\n * Multisig for delegated logic sig\n */\n lmsig?: MultisigSignature\n}\n\n/**\n * Encode signed transactions to MsgPack for sending on the network.\n *\n * This method performs canonical encoding. No domain separation prefix is applicable.\n *\n * @param signedTransaction - The signed transaction to encode\n * @returns The MsgPack encoded bytes or an error if encoding fails.\n */\nexport function encodeSignedTransaction(signedTransaction: SignedTransaction): Uint8Array {\n const encodingData = signedTransactionCodec.encode(signedTransaction, 'msgpack')\n return encodeMsgpack(encodingData)\n}\n\n/**\n * Encode signed transactions to MsgPack for sending on the network.\n *\n * This method performs canonical encoding. No domain separation prefix is applicable.\n *\n * @param signedTransactions - A collection of signed transactions to encode\n * @returns A collection of MsgPack encoded bytes or an error if encoding fails.\n */\nexport function encodeSignedTransactions(signedTransactions: SignedTransaction[]): Uint8Array[] {\n return signedTransactions.map((st) => encodeSignedTransaction(st))\n}\n\n/**\n * Decodes MsgPack bytes into a signed transaction.\n *\n * @param encodedSignedTransaction - The MsgPack encoded signed transaction bytes\n * @returns The decoded SignedTransaction or an error if decoding fails.\n */\nexport function decodeSignedTransaction(encodedSignedTransaction: Uint8Array): SignedTransaction {\n const decodedData = decodeMsgpack(encodedSignedTransaction)\n return signedTransactionCodec.decode(decodedData, 'msgpack')\n}\n\n/**\n * Decodes a collection of MsgPack bytes into a signed transaction collection.\n *\n * @param encodedSignedTransactions - A collection of MsgPack encoded bytes, each representing a signed transaction.\n * @returns A collection of decoded signed transactions or an error if decoding fails.\n */\nexport function decodeSignedTransactions(encodedSignedTransactions: Uint8Array[]): SignedTransaction[] {\n return encodedSignedTransactions.map((est) => decodeSignedTransaction(est))\n}\n\n/**\n * Validate a signed transaction structure\n */\nexport function validateSignedTransaction(signedTransaction: SignedTransaction): void {\n validateTransaction(signedTransaction.txn)\n\n // Validate that only one signature type is set\n const sigTypes = [signedTransaction.sig, signedTransaction.msig, signedTransaction.lsig]\n const setSigCount = sigTypes.filter((sig) => sig !== undefined).length\n\n if (setSigCount > 1) {\n throw new Error(`Only one signature type can be set, found ${setSigCount}`)\n }\n\n // Validate signature lengths\n if (signedTransaction.sig && signedTransaction.sig.length !== 64) {\n throw new Error('Signature must be 64 bytes')\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAkHA,SAAgB,wBAAwB,mBAAkD;AAExF,QAAO,cADc,uBAAuB,OAAO,mBAAmB,UAAU,CAC9C;;;;;;;;;;AAWpC,SAAgB,yBAAyB,oBAAuD;AAC9F,QAAO,mBAAmB,KAAK,OAAO,wBAAwB,GAAG,CAAC;;;;;;;;AASpE,SAAgB,wBAAwB,0BAAyD;CAC/F,MAAM,cAAc,cAAc,yBAAyB;AAC3D,QAAO,uBAAuB,OAAO,aAAa,UAAU;;;;;;;;AAS9D,SAAgB,yBAAyB,2BAA8D;AACrG,QAAO,0BAA0B,KAAK,QAAQ,wBAAwB,IAAI,CAAC;;;;;AAM7E,SAAgB,0BAA0B,mBAA4C;AACpF,qBAAoB,kBAAkB,IAAI;CAI1C,MAAM,cADW;EAAC,kBAAkB;EAAK,kBAAkB;EAAM,kBAAkB;EAAK,CAC3D,QAAQ,QAAQ,QAAQ,OAAU,CAAC;AAEhE,KAAI,cAAc,EAChB,OAAM,IAAI,MAAM,6CAA6C,cAAc;AAI7E,KAAI,kBAAkB,OAAO,kBAAkB,IAAI,WAAW,GAC5D,OAAM,IAAI,MAAM,6BAA6B"}