algosdk 3.6.0 → 3.7.0-beta.1

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 (109) hide show
  1. package/dist/browser/algosdk.min.js +1 -1
  2. package/dist/browser/algosdk.min.js.map +1 -1
  3. package/dist/cjs/client/v2/algod/algod.js +0 -18
  4. package/dist/cjs/client/v2/algod/algod.js.map +1 -1
  5. package/dist/cjs/client/v2/algod/models/types.js +2 -434
  6. package/dist/cjs/client/v2/algod/models/types.js.map +1 -1
  7. package/dist/cjs/ed25519-signer.js +76 -0
  8. package/dist/cjs/ed25519-signer.js.map +1 -0
  9. package/dist/cjs/encoding/address.js +61 -1
  10. package/dist/cjs/encoding/address.js.map +1 -1
  11. package/dist/cjs/falcon-signer.js +17 -0
  12. package/dist/cjs/falcon-signer.js.map +1 -0
  13. package/dist/cjs/logicsig.js +201 -16
  14. package/dist/cjs/logicsig.js.map +1 -1
  15. package/dist/cjs/main.js +32 -63
  16. package/dist/cjs/main.js.map +1 -1
  17. package/dist/cjs/mnemonic/mnemonic.js +26 -1
  18. package/dist/cjs/mnemonic/mnemonic.js.map +1 -1
  19. package/dist/cjs/multisigSigning.js +78 -1
  20. package/dist/cjs/multisigSigning.js.map +1 -1
  21. package/dist/cjs/pq-signer.js +54 -0
  22. package/dist/cjs/pq-signer.js.map +1 -0
  23. package/dist/cjs/signedTransaction.js +15 -1
  24. package/dist/cjs/signedTransaction.js.map +1 -1
  25. package/dist/cjs/signer.js.map +1 -1
  26. package/dist/cjs/signing.js +94 -7
  27. package/dist/cjs/signing.js.map +1 -1
  28. package/dist/cjs/transaction.js +9 -1
  29. package/dist/cjs/transaction.js.map +1 -1
  30. package/dist/cjs/types/transactions/encoded.js +51 -1
  31. package/dist/cjs/types/transactions/encoded.js.map +1 -1
  32. package/dist/cjs/utils/ed25519-check.js +69 -0
  33. package/dist/cjs/utils/ed25519-check.js.map +1 -0
  34. package/dist/esm/client/v2/algod/algod.js +0 -18
  35. package/dist/esm/client/v2/algod/algod.js.map +1 -1
  36. package/dist/esm/client/v2/algod/models/types.js +0 -427
  37. package/dist/esm/client/v2/algod/models/types.js.map +1 -1
  38. package/dist/esm/ed25519-signer.js +72 -0
  39. package/dist/esm/ed25519-signer.js.map +1 -0
  40. package/dist/esm/encoding/address.js +58 -0
  41. package/dist/esm/encoding/address.js.map +1 -1
  42. package/dist/esm/falcon-signer.js +13 -0
  43. package/dist/esm/falcon-signer.js.map +1 -0
  44. package/dist/esm/logicsig.js +200 -15
  45. package/dist/esm/logicsig.js.map +1 -1
  46. package/dist/esm/main.js +8 -56
  47. package/dist/esm/main.js.map +1 -1
  48. package/dist/esm/mnemonic/mnemonic.js +25 -1
  49. package/dist/esm/mnemonic/mnemonic.js.map +1 -1
  50. package/dist/esm/multisigSigning.js +75 -0
  51. package/dist/esm/multisigSigning.js.map +1 -1
  52. package/dist/esm/pq-signer.js +50 -0
  53. package/dist/esm/pq-signer.js.map +1 -0
  54. package/dist/esm/signedTransaction.js +16 -2
  55. package/dist/esm/signedTransaction.js.map +1 -1
  56. package/dist/esm/signer.js.map +1 -1
  57. package/dist/esm/signing.js +91 -8
  58. package/dist/esm/signing.js.map +1 -1
  59. package/dist/esm/transaction.js +9 -1
  60. package/dist/esm/transaction.js.map +1 -1
  61. package/dist/esm/types/transactions/encoded.js +49 -1
  62. package/dist/esm/types/transactions/encoded.js.map +1 -1
  63. package/dist/esm/utils/ed25519-check.js +65 -0
  64. package/dist/esm/utils/ed25519-check.js.map +1 -0
  65. package/dist/types/client/v2/algod/algod.d.ts +0 -16
  66. package/dist/types/client/v2/algod/models/types.d.ts +0 -217
  67. package/dist/types/ed25519-signer.d.ts +7 -0
  68. package/dist/types/encoding/address.d.ts +37 -0
  69. package/dist/types/falcon-signer.d.ts +11 -0
  70. package/dist/types/logicsig.d.ts +72 -1
  71. package/dist/types/main.d.ts +8 -44
  72. package/dist/types/mnemonic/mnemonic.d.ts +13 -0
  73. package/dist/types/multisigSigning.d.ts +49 -0
  74. package/dist/types/pq-signer.d.ts +8 -0
  75. package/dist/types/signedTransaction.d.ts +7 -2
  76. package/dist/types/signer.d.ts +38 -0
  77. package/dist/types/signing.d.ts +45 -0
  78. package/dist/types/transaction.d.ts +9 -0
  79. package/dist/types/types/transactions/encoded.d.ts +27 -0
  80. package/dist/types/utils/ed25519-check.d.ts +10 -0
  81. package/package.json +2 -1
  82. package/src/client/v2/algod/algod.ts +0 -19
  83. package/src/client/v2/algod/models/types.ts +0 -700
  84. package/src/ed25519-signer.ts +125 -0
  85. package/src/encoding/address.ts +80 -0
  86. package/src/falcon-signer.ts +30 -0
  87. package/src/logicsig.ts +258 -16
  88. package/src/main.ts +30 -60
  89. package/src/mnemonic/mnemonic.ts +34 -1
  90. package/src/multisigSigning.ts +111 -0
  91. package/src/pq-signer.ts +90 -0
  92. package/src/signedTransaction.ts +24 -0
  93. package/src/signer.ts +53 -0
  94. package/src/signing.ts +109 -8
  95. package/src/transaction.ts +9 -1
  96. package/src/types/transactions/encoded.ts +88 -0
  97. package/src/utils/ed25519-check.ts +67 -0
  98. package/dist/cjs/client/v2/algod/dryrun.js +0 -34
  99. package/dist/cjs/client/v2/algod/dryrun.js.map +0 -1
  100. package/dist/cjs/dryrun.js +0 -214
  101. package/dist/cjs/dryrun.js.map +0 -1
  102. package/dist/esm/client/v2/algod/dryrun.js +0 -28
  103. package/dist/esm/client/v2/algod/dryrun.js.map +0 -1
  104. package/dist/esm/dryrun.js +0 -208
  105. package/dist/esm/dryrun.js.map +0 -1
  106. package/dist/types/client/v2/algod/dryrun.d.ts +0 -11
  107. package/dist/types/dryrun.d.ts +0 -28
  108. package/src/client/v2/algod/dryrun.ts +0 -38
  109. package/src/dryrun.ts +0 -292
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addressWithSignersFromRawEd25519Signer = void 0;
4
+ const address_js_1 = require("./encoding/address.js");
5
+ const encoding_js_1 = require("./encoding/encoding.js");
6
+ const logicsig_js_1 = require("./logicsig.js");
7
+ const multisig_js_1 = require("./multisig.js");
8
+ const signedTransaction_js_1 = require("./signedTransaction.js");
9
+ const signing_js_1 = require("./signing.js");
10
+ const utils_js_1 = require("./utils/utils.js");
11
+ function addressWithSignersFromRawEd25519Signer(ed25519SigningKey, sendingAddress = new address_js_1.Address(ed25519SigningKey.ed25519PublicKey)) {
12
+ const authAddress = new address_js_1.Address(ed25519SigningKey.ed25519PublicKey);
13
+ const { ed25519Signer: rawSigner } = ed25519SigningKey;
14
+ const txnSigner = async (txnGroup, indexesToSign) => {
15
+ const stxns = [];
16
+ for (const index of indexesToSign) {
17
+ const txn = txnGroup[index];
18
+ // eslint-disable-next-line no-await-in-loop
19
+ const sig = await rawSigner(txn.bytesToSign());
20
+ const stxn = new signedTransaction_js_1.SignedTransaction({
21
+ txn,
22
+ sig,
23
+ sgnr: txn.sender.equals(authAddress) ? undefined : authAddress,
24
+ });
25
+ stxns.push(stxn);
26
+ }
27
+ return stxns.map((stxn) => (0, encoding_js_1.encodeMsgpack)(stxn));
28
+ };
29
+ const delegatedLsigSigner = async (lsig, msig) => {
30
+ if (msig) {
31
+ const pks = (0, multisig_js_1.pksFromAddresses)(msig.addrs);
32
+ const multisigAddr = (0, multisig_js_1.addressFromMultisigPreImg)({
33
+ version: msig.version,
34
+ threshold: msig.threshold,
35
+ pks,
36
+ });
37
+ const toBeSigned = (0, utils_js_1.concatArrays)(logicsig_js_1.MSIG_PROGRAM_TAG, multisigAddr.publicKey, lsig.logic);
38
+ const subsigs = pks.map((pk) => ({ pk }));
39
+ const ourSubsig = subsigs.find((subsig) => (0, utils_js_1.arrayEqual)(subsig.pk, authAddress.publicKey));
40
+ if (ourSubsig === undefined) {
41
+ throw Error(`DelegatedLsigSigner could not find ${authAddress} as a signer in the multisig`);
42
+ }
43
+ const sig = await rawSigner(toBeSigned);
44
+ ourSubsig.s = sig;
45
+ return {
46
+ address: authAddress,
47
+ lmsig: {
48
+ v: msig.version,
49
+ thr: msig.threshold,
50
+ subsig: subsigs,
51
+ },
52
+ };
53
+ }
54
+ const toBeSigned = (0, utils_js_1.concatArrays)(logicsig_js_1.PROGRAM_TAG, lsig.logic);
55
+ const sig = await rawSigner(toBeSigned);
56
+ return { address: authAddress, sig };
57
+ };
58
+ const mxBytesSigner = async (bytes) => {
59
+ const bytesToSign = (0, utils_js_1.concatArrays)(signing_js_1.SIGN_BYTES_PREFIX, bytes);
60
+ return rawSigner(bytesToSign);
61
+ };
62
+ const programDataSigner = async (data, lsig) => {
63
+ const parts = (0, utils_js_1.concatArrays)(lsig.address().publicKey, data);
64
+ const toBeSigned = (0, utils_js_1.concatArrays)(logicsig_js_1.SIGN_PROGRAM_DATA_PREFIX, parts);
65
+ return rawSigner(toBeSigned);
66
+ };
67
+ return {
68
+ address: sendingAddress,
69
+ programDataSigner,
70
+ txnSigner,
71
+ delegatedLsigSigner,
72
+ mxBytesSigner,
73
+ };
74
+ }
75
+ exports.addressWithSignersFromRawEd25519Signer = addressWithSignersFromRawEd25519Signer;
76
+ //# sourceMappingURL=ed25519-signer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ed25519-signer.js","sourceRoot":"","sources":["../../src/ed25519-signer.ts"],"names":[],"mappings":";;;AAAA,sDAAgD;AAChD,wDAAuD;AACvD,+CAIuB;AACvB,+CAA4E;AAC5E,iEAA2D;AAW3D,6CAAiD;AAMjD,+CAA4D;AAO5D,SAAgB,sCAAsC,CACpD,iBAAoC,EACpC,iBAA0B,IAAI,oBAAO,CAAC,iBAAiB,CAAC,gBAAgB,CAAC;IAKzE,MAAM,WAAW,GAAG,IAAI,oBAAO,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,CAAC;IACpE,MAAM,EAAE,aAAa,EAAE,SAAS,EAAE,GAAG,iBAAiB,CAAC;IAEvD,MAAM,SAAS,GAAsB,KAAK,EACxC,QAAuB,EACvB,aAAuB,EACvB,EAAE;QACF,MAAM,KAAK,GAAwB,E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,OAAO,EAAE,cAAc;QACvB,iBAAiB;QACjB,SAAS;QACT,mBAAmB;QACnB,aAAa;KACd,CAAC;AACJ,CAAC;AA5FD,wFA4FC"}
@@ -26,18 +26,33 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.getApplicationAddress = exports.encodeAddress = exports.isValidAddress = exports.decodeAddress = exports.Address = exports.CHECKSUM_ADDRESS_ERROR_MSG = exports.MALFORMED_ADDRESS_ERROR_MSG = exports.ALGORAND_ZERO_ADDRESS_STRING = exports.ALGORAND_ADDRESS_LENGTH = exports.ALGORAND_CHECKSUM_BYTE_LENGTH = exports.ALGORAND_ADDRESS_BYTE_LENGTH = void 0;
29
+ exports.addressFromPQSig = exports.addressFromPQKey = exports.getApplicationAddress = exports.encodeAddress = exports.isValidAddress = exports.decodeAddress = exports.Address = exports.PQ_SALT_MAX = exports.PQ_SCHEME_SIZE = exports.CHECKSUM_ADDRESS_ERROR_MSG = exports.MALFORMED_ADDRESS_ERROR_MSG = exports.ALGORAND_ZERO_ADDRESS_STRING = exports.ALGORAND_ADDRESS_LENGTH = exports.ALGORAND_CHECKSUM_BYTE_LENGTH = exports.ALGORAND_ADDRESS_BYTE_LENGTH = void 0;
30
30
  const hi_base32_1 = __importDefault(require("hi-base32"));
31
31
  const nacl = __importStar(require("../nacl/naclWrappers.js"));
32
32
  const utils = __importStar(require("../utils/utils.js"));
33
33
  const uint64_js_1 = require("./uint64.js");
34
34
  const binarydata_js_1 = require("./binarydata.js");
35
+ const ed25519_check_js_1 = require("../utils/ed25519-check.js");
35
36
  exports.ALGORAND_ADDRESS_BYTE_LENGTH = 36;
36
37
  exports.ALGORAND_CHECKSUM_BYTE_LENGTH = 4;
37
38
  exports.ALGORAND_ADDRESS_LENGTH = 58;
38
39
  exports.ALGORAND_ZERO_ADDRESS_STRING = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ';
39
40
  exports.MALFORMED_ADDRESS_ERROR_MSG = 'address seems to be malformed';
40
41
  exports.CHECKSUM_ADDRESS_ERROR_MSG = 'wrong checksum for address';
42
+ /**
43
+ * The domain-separation prefix prepended to a post-quantum address preimage
44
+ * before hashing. Matches go-algorand's protocol.PostQuantumAddress HashID.
45
+ */
46
+ const PQ_ADDRESS_PREFIX = new TextEncoder().encode('PQA');
47
+ /**
48
+ * The required byte length of a post-quantum signature scheme identifier.
49
+ */
50
+ exports.PQ_SCHEME_SIZE = 2;
51
+ /**
52
+ * The largest value a post-quantum address salt may take. The salt occupies a
53
+ * single byte of the address preimage.
54
+ */
55
+ exports.PQ_SALT_MAX = 0xff;
41
56
  function checksumFromPublicKey(pk) {
42
57
  return Uint8Array.from(nacl
43
58
  .genericHash(pk)
@@ -158,4 +173,49 @@ function getApplicationAddress(appID) {
158
173
  return new Address(Uint8Array.from(hash));
159
174
  }
160
175
  exports.getApplicationAddress = getApplicationAddress;
176
+ /**
177
+ * Derive a post-quantum (PQ) account address together with the canonical salt
178
+ * used to derive it.
179
+ *
180
+ * @param schemeBytes - The 2-byte ASCII PQ scheme identifier (e.g. "f1" for Falcon-1024).
181
+ * @param key - The scheme's canonical public key.
182
+ * @returns The derived Address and the canonical 1-byte salt.
183
+ */
184
+ function addressFromPQKey(schemeBytes, key) {
185
+ if (schemeBytes.length !== exports.PQ_SCHEME_SIZE)
186
+ throw new Error(`invalid PQ scheme length: expected ${exports.PQ_SCHEME_SIZE} bytes, got ${schemeBytes.length}`);
187
+ // Rejection-sample the lowest salt that yields a PQ-compliant (non-Ed25519)
188
+ // address. The probability of exhausting the range is ~2^-256.
189
+ for (let salt = 0; salt <= exports.PQ_SALT_MAX; salt++) {
190
+ const toBeHashed = utils.concatArrays(PQ_ADDRESS_PREFIX, schemeBytes, Uint8Array.of(salt), key);
191
+ const publicKey = Uint8Array.from(nacl.genericHash(toBeHashed));
192
+ if (!(0, ed25519_check_js_1.couldBeCurvePoint)(publicKey)) {
193
+ return { address: new Address(publicKey), salt };
194
+ }
195
+ }
196
+ throw new Error('no canonical salt exists for this PQ public key and scheme');
197
+ }
198
+ exports.addressFromPQKey = addressFromPQKey;
199
+ /**
200
+ * Derive the account address that a post-quantum signature authorizes.
201
+ *
202
+ * Unlike an Ed25519 signature, a PQ signature carries the scheme, salt and
203
+ * public key of the signing account, so the address it authorizes is fully
204
+ * determined by the signature and does not have to be supplied out of band.
205
+ *
206
+ * This also validates the signature's self-consistency: the salt must be the
207
+ * canonical one for the given scheme and public key, which is what the network
208
+ * requires.
209
+ *
210
+ * @param pqsig - The post-quantum signature to derive the address from.
211
+ * @returns The address of the account the signature authorizes.
212
+ */
213
+ function addressFromPQSig(pqsig) {
214
+ const { address, salt } = addressFromPQKey(pqsig.sch, pqsig.pk);
215
+ if (salt !== pqsig.slt) {
216
+ throw new Error(`invalid PQ signature salt: expected the canonical salt ${salt}, got ${pqsig.slt}`);
217
+ }
218
+ return address;
219
+ }
220
+ exports.addressFromPQSig = addressFromPQSig;
161
221
  //# sourceMappingURL=address.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"address.js","sourceRoot":"","sources":["../../../src/encoding/address.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAA+B;AAC/B,8DAAgD;AAChD,yDAA2C;AAC3C,2CAA2C;AAC3C,mDAA6C;AAEhC,QAAA,4BAA4B,GAAG,EAAE,CAAC;AAClC,QAAA,6BAA6B,GAAG,CAAC,CAAC;AAClC,QAAA,uBAAuB,GAAG,EAAE,CAAC;AAC7B,QAAA,4BAA4B,GACvC,4DAA4D,CAAC;AAElD,QAAA,2BAA2B,GAAG,+BAA+B,CAAC;AAC9D,QAAA,0BAA0B,GAAG,4BAA4B,CAAC;AAEvE,SAAS,qBAAqB,CAAC,EAAc;IAC3C,OAAO,UAAU,CAAC,IAAI,CACpB,IAAI;SACD,WAAW,CAAC,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AAK,sBAAc;QACvC,MAAM,IAAI,KAAK,CACb,sCAAsC,sBAAc,eAAe,WAAW,CAAC,MAAM,EAAE,CACxF,CAAC;IAEJ,4EAA4E;IAC5E,+DAA+D;IAC/D,KAAK,IAAI,IAAI,GAAG,CAAC,EAAE,IAAI,IAAI,mBAAW,EAAE,IAAI,EAAE,EAAE,CAAC;QAC/C,MAAM,UAAU,GAAG,KAAK,CAAC,YAAY,CACnC,iBAAiB,EACjB,WAAW,EACX,UAAU,CAAC,EAAE,CAAC,IAAI,CAAC,EACnB,GAAG,CACJ,CAAC;QACF,MAAM,SAAS,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC;QAChE,IAAI,CAAC,IAAA,oCAAiB,EAAC,SAAS,CAAC,EAAE,CAAC;YAClC,OAAO,EAAE,OAAO,EAAE,IAAI,OAAO,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,CAAC;QACnD,CAAC;IACH,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAC;AAChF,CAAC;AAzBD,4CAyBC;AAED;;;;;;;;;;;;;GAaG;AACH,SAAgB,gBAAgB,CAAC,KAAmB;IAClD,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,gBAAgB,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC;IAChE,IAAI,IAAI,KAAK,KAAK,CAAC,GAAG,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CACb,0DAA0D,IAAI,SAAS,KAAK,CAAC,GAAG,EAAE,CACnF,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AARD,4CAQC"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addressWithSignersFromRawFalcon1024Signer = exports.FALCON_1024_SCHEME = void 0;
4
+ const pq_signer_js_1 = require("./pq-signer.js");
5
+ /**
6
+ * The 2-byte ASCII identifier of the Falcon-1024 post-quantum signature scheme.
7
+ */
8
+ exports.FALCON_1024_SCHEME = new TextEncoder().encode('f1');
9
+ function addressWithSignersFromRawFalcon1024Signer(falconSigningKey, sendingAddress) {
10
+ return (0, pq_signer_js_1.addressWithSignersFromRawPQSigner)({
11
+ pqScheme: exports.FALCON_1024_SCHEME,
12
+ pqPublicKey: falconSigningKey.falcon1024PublicKey,
13
+ pqSigner: falconSigningKey.falcon1024Signer,
14
+ }, sendingAddress);
15
+ }
16
+ exports.addressWithSignersFromRawFalcon1024Signer = addressWithSignersFromRawFalcon1024Signer;
17
+ //# sourceMappingURL=falcon-signer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"falcon-signer.js","sourceRoot":"","sources":["../../src/falcon-signer.ts"],"names":[],"mappings":";;;AAKA,iDAAmE;AAEnE;;GAEG;AACU,QAAA,kBAAkB,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAOjE,SAAgB,yCAAyC,CACvD,gBAAsC,EACtC,cAAwB;IAExB,OAAO,IAAA,gDAAiC,EACtC;QACE,QAAQ,EAAE,0BAAkB;QAC5B,WAAW,EAAE,gBAAgB,CAAC,mBAAmB;QACjD,QAAQ,EAAE,gBAAgB,CAAC,gBAAgB;KAC5C,EACD,cAAc,CACf,CAAC;AACJ,CAAC;AAZD,8FAYC"}
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.tealSignFromProgram = exports.verifyTealSign = exports.tealSign = exports.logicSigFromByte = exports.LogicSigAccount = exports.LogicSig = exports.sanityCheckProgram = void 0;
26
+ exports.tealSignFromProgram = exports.verifyTealSign = exports.tealSign = exports.SIGN_PROGRAM_DATA_PREFIX = exports.logicSigFromByte = exports.LogicSigAccount = exports.LogicSig = exports.MSIG_PROGRAM_TAG = exports.PQ_PROGRAM_TAG = exports.PROGRAM_TAG = exports.sanityCheckProgram = void 0;
27
27
  const nacl = __importStar(require("./nacl/naclWrappers.js"));
28
28
  const address_js_1 = require("./encoding/address.js");
29
29
  const encoding = __importStar(require("./encoding/encoding.js"));
@@ -56,8 +56,9 @@ function sanityCheckProgram(program) {
56
56
  }
57
57
  }
58
58
  exports.sanityCheckProgram = sanityCheckProgram;
59
- const programTag = new TextEncoder().encode('Program');
60
- const multisigProgramTag = new TextEncoder().encode('MsigProgram');
59
+ exports.PROGRAM_TAG = new TextEncoder().encode('Program');
60
+ exports.PQ_PROGRAM_TAG = new TextEncoder().encode('PQProgram');
61
+ exports.MSIG_PROGRAM_TAG = new TextEncoder().encode('MsigProgram');
61
62
  /**
62
63
  LogicSig implementation
63
64
 
@@ -79,6 +80,7 @@ class LogicSig {
79
80
  this.sig = undefined;
80
81
  this.msig = undefined;
81
82
  this.lmsig = undefined;
83
+ this.pqsig = undefined;
82
84
  }
83
85
  // eslint-disable-next-line class-methods-use-this
84
86
  getEncodingSchema() {
@@ -96,6 +98,9 @@ class LogicSig {
96
98
  if (this.lmsig) {
97
99
  data.set('lmsig', (0, encoded_js_1.encodedMultiSigToEncodingData)(this.lmsig));
98
100
  }
101
+ if (this.pqsig) {
102
+ data.set('pqsig', (0, encoded_js_1.encodedPQSigToEncodingData)(this.pqsig));
103
+ }
99
104
  return data;
100
105
  }
101
106
  static fromEncodingData(data) {
@@ -110,14 +115,20 @@ class LogicSig {
110
115
  if (data.get('lmsig')) {
111
116
  lsig.lmsig = (0, encoded_js_1.encodedMultiSigFromEncodingData)(data.get('lmsig'));
112
117
  }
118
+ if (data.get('pqsig')) {
119
+ lsig.pqsig = (0, encoded_js_1.encodedPQSigFromEncodingData)(data.get('pqsig'));
120
+ }
113
121
  return lsig;
114
122
  }
115
123
  /**
124
+ * @deprecated This function does not perform full verification and should not be fully trusted on its own.
125
+ * For example, it does not evaluate programs and does not have the ability to validate PQ signatures.
126
+ *
116
127
  * Performs signature verification
117
128
  * @param publicKey - Verification key (derived from sender address or escrow address)
118
129
  */
119
130
  verify(publicKey) {
120
- const sigCount = [this.sig, this.msig, this.lmsig].filter(Boolean).length;
131
+ const sigCount = [this.sig, this.msig, this.lmsig, this.pqsig].filter(Boolean).length;
121
132
  if (sigCount > 1) {
122
133
  return false;
123
134
  }
@@ -127,11 +138,18 @@ class LogicSig {
127
138
  catch (e) {
128
139
  return false;
129
140
  }
130
- const toBeSigned = utils.concatArrays(programTag, this.logic);
131
- if (!this.sig && !this.msig && !this.lmsig) {
141
+ const toBeSigned = utils.concatArrays(exports.PROGRAM_TAG, this.logic);
142
+ if (!this.sig && !this.msig && !this.lmsig && !this.pqsig) {
132
143
  const hash = nacl.genericHash(toBeSigned);
133
144
  return utils.arrayEqual(hash, publicKey);
134
145
  }
146
+ if (this.pqsig) {
147
+ // This function has no way to validate a post-quantum signature, so it
148
+ // cannot report success here. Callers that need to sign a transaction
149
+ // with a PQ delegated LogicSig should go through
150
+ // signLogicSigTransactionObject, which skips this check.
151
+ return false;
152
+ }
135
153
  if (this.sig) {
136
154
  return nacl.verify(toBeSigned, this.sig, publicKey);
137
155
  }
@@ -141,7 +159,7 @@ class LogicSig {
141
159
  threshold: this.lmsig.thr,
142
160
  pks: this.lmsig.subsig.map((subsig) => subsig.pk),
143
161
  });
144
- const lmsigProgram = utils.concatArrays(multisigProgramTag, multisigAddr.publicKey, this.logic);
162
+ const lmsigProgram = utils.concatArrays(exports.MSIG_PROGRAM_TAG, multisigAddr.publicKey, this.logic);
145
163
  return (0, multisig_js_1.verifyMultisig)(lmsigProgram, this.lmsig, publicKey);
146
164
  }
147
165
  if (this.msig) {
@@ -154,11 +172,13 @@ class LogicSig {
154
172
  * @returns String representation of the address
155
173
  */
156
174
  address() {
157
- const toBeSigned = utils.concatArrays(programTag, this.logic);
175
+ const toBeSigned = utils.concatArrays(exports.PROGRAM_TAG, this.logic);
158
176
  const hash = nacl.genericHash(toBeSigned);
159
177
  return new address_js_1.Address(Uint8Array.from(hash));
160
178
  }
161
179
  /**
180
+ * @deprecated Use `signWithSigner` instead
181
+ *
162
182
  * Creates signature (if no msig provided) or multi signature otherwise
163
183
  * @param secretKey - Secret key to sign with
164
184
  * @param msig - Multisig account as \{version, threshold, addrs\}
@@ -179,6 +199,64 @@ class LogicSig {
179
199
  }
180
200
  }
181
201
  /**
202
+ * Signs this LogicSig for delegation using the given signer.
203
+ *
204
+ * @param signer - The signer to delegate to
205
+ * @param msig - Optional multisig account the signer is a subsigner of
206
+ * @returns The address the signer signed as. When `msig` is omitted this is
207
+ * the delegating account. When `msig` is given it is the individual
208
+ * subsigner, not the multisig, so the delegating account is
209
+ * `multisigAddress(msig)`. Either way it is an authorizing address, which
210
+ * is not necessarily the address a signer sends transactions from.
211
+ *
212
+ * Re-signing an already-signed LogicSig is allowed, and replaces the previous
213
+ * delegation signature. At most one of `sig`, `msig`, `lmsig` and `pqsig` may
214
+ * be set, so any signature left over from an earlier call is cleared.
215
+ */
216
+ async signWithSigner(signer, msig) {
217
+ const sigResult = await signer(this, msig);
218
+ if (msig == null) {
219
+ if ('pqsig' in sigResult && sigResult.pqsig) {
220
+ this.clearSignatures();
221
+ this.pqsig = sigResult.pqsig;
222
+ return sigResult.address;
223
+ }
224
+ if (!('sig' in sigResult) || !sigResult.sig) {
225
+ throw Error('Expected DelegatedLsigSigner to return sig or pqsig, but both are undefined. If signing for an msig, be sure to pass the msig argument');
226
+ }
227
+ this.clearSignatures();
228
+ this.sig = sigResult.sig;
229
+ }
230
+ else {
231
+ if (!('lmsig' in sigResult) || !sigResult.lmsig) {
232
+ throw Error('Expected DelegatedLsigSigner to return lmsig, but lmsig is undefined. If signing for a single account, do not pass msig argument');
233
+ }
234
+ const { lmsig } = sigResult;
235
+ const expectedPks = (0, multisig_js_1.pksFromAddresses)(msig.addrs);
236
+ if (lmsig.v !== msig.version ||
237
+ lmsig.thr !== msig.threshold ||
238
+ lmsig.subsig.length !== expectedPks.length ||
239
+ !lmsig.subsig.every((subsig, i) => utils.arrayEqual(subsig.pk, expectedPks[i]))) {
240
+ throw Error('DelegatedLsigSigner returned an lmsig whose version, threshold or public keys do not match the requested multisig');
241
+ }
242
+ this.clearSignatures();
243
+ this.lmsig = sigResult.lmsig;
244
+ }
245
+ return sigResult.address;
246
+ }
247
+ /**
248
+ * Removes every delegation signature from this LogicSig, so that exactly one
249
+ * of them can be set afterwards.
250
+ */
251
+ clearSignatures() {
252
+ this.sig = undefined;
253
+ this.msig = undefined;
254
+ this.lmsig = undefined;
255
+ this.pqsig = undefined;
256
+ }
257
+ /**
258
+ * @deprecated Use `appendToMultisigWithSigner` instead
259
+ *
182
260
  * Appends a signature to multi signature
183
261
  * @param secretKey - Secret key to sign with
184
262
  */
@@ -189,21 +267,66 @@ class LogicSig {
189
267
  const [sig, index] = this.singleSignMultisig(secretKey, this.lmsig);
190
268
  this.lmsig.subsig[index].s = sig;
191
269
  }
270
+ async appendToMultisigWithSigner(signer) {
271
+ if (this.lmsig === undefined) {
272
+ throw new Error('no multisig present');
273
+ }
274
+ const sigResult = await signer(this, {
275
+ version: this.lmsig.v,
276
+ threshold: this.lmsig.thr,
277
+ addrs: this.lmsig.subsig.map((s) => new address_js_1.Address(s.pk)),
278
+ });
279
+ if (!('lmsig' in sigResult) || !sigResult.lmsig) {
280
+ throw Error('Expected DelegatedLsigSigner to return lmsig, but lmsig is undefined');
281
+ }
282
+ if (sigResult.lmsig.v !== this.lmsig.v ||
283
+ sigResult.lmsig.thr !== this.lmsig.thr) {
284
+ throw Error('DelegatedLsigSigner returned an lmsig whose version or threshold does not match the current msig');
285
+ }
286
+ let signaturesReturned = false;
287
+ for (const subsig of sigResult.lmsig.subsig) {
288
+ if (subsig.s) {
289
+ signaturesReturned = true;
290
+ const thisSubsig = this.lmsig.subsig.find((s) => utils.arrayEqual(s.pk, subsig.pk));
291
+ if (thisSubsig === undefined) {
292
+ throw Error(`DelegatedLsigSigner returned a signature for ${new address_js_1.Address(subsig.pk)} but this pk is not in the current msig`);
293
+ }
294
+ // Never let the signer silently replace a signature already collected
295
+ // from another member.
296
+ if (thisSubsig.s && !utils.arrayEqual(thisSubsig.s, subsig.s)) {
297
+ throw Error(`DelegatedLsigSigner returned a signature for ${new address_js_1.Address(subsig.pk)} that conflicts with the signature already collected for it`);
298
+ }
299
+ thisSubsig.s = subsig.s;
300
+ }
301
+ }
302
+ if (!signaturesReturned) {
303
+ throw Error('DelegatedLsigSigner returned an lmsig with no signatures');
304
+ }
305
+ }
306
+ /**
307
+ * @deprecated Use `signWithSigner` followed by `.sig` instead
308
+ */
192
309
  signProgram(secretKey) {
193
- const toBeSigned = utils.concatArrays(programTag, this.logic);
310
+ const toBeSigned = utils.concatArrays(exports.PROGRAM_TAG, this.logic);
194
311
  const sig = nacl.sign(toBeSigned, secretKey);
195
312
  return sig;
196
313
  }
314
+ /**
315
+ * @deprecated Use `signWithSigner` followed by `.sig` instead
316
+ */
197
317
  signProgramMultisig(secretKey, msig) {
198
318
  const multisigAddr = (0, multisig_js_1.addressFromMultisigPreImg)({
199
319
  version: msig.v,
200
320
  threshold: msig.thr,
201
321
  pks: msig.subsig.map((subsig) => subsig.pk),
202
322
  });
203
- const toBeSigned = utils.concatArrays(multisigProgramTag, multisigAddr.publicKey, this.logic);
323
+ const toBeSigned = utils.concatArrays(exports.MSIG_PROGRAM_TAG, multisigAddr.publicKey, this.logic);
204
324
  const sig = nacl.sign(toBeSigned, secretKey);
205
325
  return sig;
206
326
  }
327
+ /**
328
+ * @deprecated Use `signWithSigner` followed by `.sig` instead
329
+ */
207
330
  singleSignMultisig(secretKey, msig) {
208
331
  let index = -1;
209
332
  const myPk = nacl.keyPairFromSecretKey(secretKey).publicKey;
@@ -226,6 +349,16 @@ class LogicSig {
226
349
  static fromByte(encoded) {
227
350
  return encoding.decodeMsgpack(encoded, LogicSig);
228
351
  }
352
+ /**
353
+ * Signs arbitrary data for use with the `ed25519verify` opcode from within
354
+ * this LogicSig's program.
355
+ *
356
+ * @param signer - The signer to sign the data with
357
+ * @param data - The data to sign
358
+ */
359
+ async signDataWithSigner(signer, data) {
360
+ return signer(data, this);
361
+ }
229
362
  }
230
363
  exports.LogicSig = LogicSig;
231
364
  LogicSig.encodingSchema = new index_js_1.NamedMapSchema((0, index_js_1.allOmitEmpty)([
@@ -249,6 +382,10 @@ LogicSig.encodingSchema = new index_js_1.NamedMapSchema((0, index_js_1.allOmitEm
249
382
  key: 'lmsig',
250
383
  valueSchema: new index_js_1.OptionalSchema(encoded_js_1.ENCODED_MULTISIG_SCHEMA),
251
384
  },
385
+ {
386
+ key: 'pqsig',
387
+ valueSchema: new index_js_1.OptionalSchema(encoded_js_1.ENCODED_PQSIG_SCHEMA),
388
+ },
252
389
  ]));
253
390
  /**
254
391
  * Represents an account that can sign with a LogicSig program.
@@ -309,9 +446,15 @@ class LogicSigAccount {
309
446
  * To verify the delegation signature, use `verify`.
310
447
  */
311
448
  isDelegated() {
312
- return !!(this.lsig.sig || this.lsig.msig || this.lsig.lmsig);
449
+ return !!(this.lsig.sig ||
450
+ this.lsig.msig ||
451
+ this.lsig.lmsig ||
452
+ this.lsig.pqsig);
313
453
  }
314
454
  /**
455
+ * @deprecated This function does not perform full verification and should not be fully trusted on its own.
456
+ * For example, it does not evaluate programs and does not have the ability to validate PQ signatures.
457
+ *
315
458
  * Verifies this LogicSig's program and signatures.
316
459
  * @returns true if and only if the LogicSig program and signatures are valid.
317
460
  */
@@ -329,9 +472,24 @@ class LogicSigAccount {
329
472
  * escrow address that is the hash of the LogicSig's program code.
330
473
  */
331
474
  address() {
332
- const sigCount = [this.lsig.sig, this.lsig.msig, this.lsig.lmsig].filter(Boolean).length;
475
+ const sigCount = [
476
+ this.lsig.sig,
477
+ this.lsig.msig,
478
+ this.lsig.lmsig,
479
+ this.lsig.pqsig,
480
+ ].filter(Boolean).length;
333
481
  if (sigCount > 1) {
334
- throw new Error('LogicSig has too many signatures. At most one of sig, msig, or lmsig may be present');
482
+ throw new Error('LogicSig has too many signatures. At most one of sig, msig, lmsig, or pqsig may be present');
483
+ }
484
+ if (this.lsig.pqsig) {
485
+ // A PQ signature carries the scheme, salt and public key of the
486
+ // delegating account, so derive the address rather than trusting
487
+ // `sigkey`. Also throws if the signature is not self-consistent.
488
+ const derived = (0, address_js_1.addressFromPQSig)(this.lsig.pqsig);
489
+ if (this.sigkey && !utils.arrayEqual(this.sigkey, derived.publicKey)) {
490
+ throw new Error(`Signing key for delegated account does not match the PQ signature. The signature authorizes ${derived}, but sigkey is ${new address_js_1.Address(this.sigkey)}`);
491
+ }
492
+ return derived;
335
493
  }
336
494
  if (this.lsig.sig) {
337
495
  if (!this.sigkey) {
@@ -351,6 +509,8 @@ class LogicSigAccount {
351
509
  return this.lsig.address();
352
510
  }
353
511
  /**
512
+ * @deprecated Use `signMultisigWithSigner` instead
513
+ *
354
514
  * Turns this LogicSigAccount into a delegated LogicSig. This type of LogicSig
355
515
  * has the authority to sign transactions on behalf of another account, called
356
516
  * the delegating account. Use this function if the delegating account is a
@@ -364,7 +524,12 @@ class LogicSigAccount {
364
524
  signMultisig(msig, secretKey) {
365
525
  this.lsig.sign(secretKey, msig);
366
526
  }
527
+ async signMultisigWithSigner(msig, signer) {
528
+ await this.lsig.signWithSigner(signer, msig);
529
+ }
367
530
  /**
531
+ * @deprecated Use appendToMultisigWithSigner
532
+ *
368
533
  * Adds an additional signature from a member of the delegating multisig
369
534
  * account.
370
535
  *
@@ -374,7 +539,12 @@ class LogicSigAccount {
374
539
  appendToMultisig(secretKey) {
375
540
  this.lsig.appendToMultisig(secretKey);
376
541
  }
542
+ async appendToMultisigWithSigner(signer) {
543
+ await this.lsig.appendToMultisigWithSigner(signer);
544
+ }
377
545
  /**
546
+ * @deprecated Use `signWithSigner` instead
547
+ *
378
548
  * Turns this LogicSigAccount into a delegated LogicSig. This type of LogicSig
379
549
  * has the authority to sign transactions on behalf of another account, called
380
550
  * the delegating account. If the delegating account is a multisig account,
@@ -386,6 +556,21 @@ class LogicSigAccount {
386
556
  this.lsig.sign(secretKey);
387
557
  this.sigkey = nacl.keyPairFromSecretKey(secretKey).publicKey;
388
558
  }
559
+ /**
560
+ * Turns this LogicSigAccount into a delegated LogicSig, signed by the given
561
+ * signer. If the delegating account is a multisig account, use
562
+ * `signMultisigWithSigner` instead.
563
+ *
564
+ * @param signer - The signer of the delegating account.
565
+ */
566
+ async signWithSigner(signer) {
567
+ // Record the address the signer reports rather than any sending address it
568
+ // may advertise: the latter is the address the signer sends transactions
569
+ // from, which for a rekeyed account is not the account that authorizes
570
+ // this delegation.
571
+ const delegatingAddress = await this.lsig.signWithSigner(signer);
572
+ this.sigkey = delegatingAddress.publicKey;
573
+ }
389
574
  }
390
575
  exports.LogicSigAccount = LogicSigAccount;
391
576
  LogicSigAccount.encodingSchema = new index_js_1.NamedMapSchema((0, index_js_1.allOmitEmpty)([
@@ -406,7 +591,7 @@ function logicSigFromByte(encoded) {
406
591
  return encoding.decodeMsgpack(encoded, LogicSig);
407
592
  }
408
593
  exports.logicSigFromByte = logicSigFromByte;
409
- const SIGN_PROGRAM_DATA_PREFIX = new TextEncoder().encode('ProgData');
594
+ exports.SIGN_PROGRAM_DATA_PREFIX = new TextEncoder().encode('ProgData');
410
595
  /**
411
596
  * tealSign creates a signature compatible with ed25519verify opcode from program hash
412
597
  * @param sk - Uint8Array with secret key
@@ -418,7 +603,7 @@ function tealSign(sk, data, programHash) {
418
603
  ? address_js_1.Address.fromString(programHash)
419
604
  : programHash;
420
605
  const parts = utils.concatArrays(programAddr.publicKey, data);
421
- const toBeSigned = utils.concatArrays(SIGN_PROGRAM_DATA_PREFIX, parts);
606
+ const toBeSigned = utils.concatArrays(exports.SIGN_PROGRAM_DATA_PREFIX, parts);
422
607
  return nacl.sign(toBeSigned, sk);
423
608
  }
424
609
  exports.tealSign = tealSign;
@@ -434,7 +619,7 @@ function verifyTealSign(data, programHash, sig, pk) {
434
619
  ? address_js_1.Address.fromString(programHash)
435
620
  : programHash;
436
621
  const parts = utils.concatArrays(programAddr.publicKey, data);
437
- const toBeSigned = utils.concatArrays(SIGN_PROGRAM_DATA_PREFIX, parts);
622
+ const toBeSigned = utils.concatArrays(exports.SIGN_PROGRAM_DATA_PREFIX, parts);
438
623
  return nacl.verify(toBeSigned, sig, pk);
439
624
  }
440
625
  exports.verifyTealSign = verifyTealSign;