@thruputchain/client 0.0.0-stage → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +935 -2
  3. package/dist/actions-CdFSUTO2.js +298 -0
  4. package/dist/actions-CdFSUTO2.js.map +1 -0
  5. package/dist/actions-DxJZ3yIv.cjs +357 -0
  6. package/dist/actions-DxJZ3yIv.cjs.map +1 -0
  7. package/dist/actions.cjs +19 -0
  8. package/dist/actions.d.cts +4 -0
  9. package/dist/actions.d.ts +4 -0
  10. package/dist/actions.js +3 -0
  11. package/dist/client-BxB6ktQd.d.cts +690 -0
  12. package/dist/client-BxB6ktQd.d.cts.map +1 -0
  13. package/dist/client-BxB6ktQd.d.ts +690 -0
  14. package/dist/client-BxB6ktQd.d.ts.map +1 -0
  15. package/dist/codec-B7HJjMzI.cjs +8190 -0
  16. package/dist/codec-B7HJjMzI.cjs.map +1 -0
  17. package/dist/codec-CX-19jac.js +8130 -0
  18. package/dist/codec-CX-19jac.js.map +1 -0
  19. package/dist/contract-BpxjDMHw.js +1105 -0
  20. package/dist/contract-BpxjDMHw.js.map +1 -0
  21. package/dist/contract-D0wCFcAN.cjs +1219 -0
  22. package/dist/contract-D0wCFcAN.cjs.map +1 -0
  23. package/dist/contract.cjs +58 -0
  24. package/dist/contract.d.cts +3 -0
  25. package/dist/contract.d.ts +3 -0
  26. package/dist/contract.js +2 -0
  27. package/dist/contracts.cjs +1050 -0
  28. package/dist/contracts.cjs.map +1 -0
  29. package/dist/contracts.d.cts +397 -0
  30. package/dist/contracts.d.cts.map +1 -0
  31. package/dist/contracts.d.ts +397 -0
  32. package/dist/contracts.d.ts.map +1 -0
  33. package/dist/contracts.js +1030 -0
  34. package/dist/contracts.js.map +1 -0
  35. package/dist/dev_wallet-BXWK5KR6.cjs +530 -0
  36. package/dist/dev_wallet-BXWK5KR6.cjs.map +1 -0
  37. package/dist/dev_wallet-C9eMQROk.js +497 -0
  38. package/dist/dev_wallet-C9eMQROk.js.map +1 -0
  39. package/dist/domainSeparator-B_vU_zUD.cjs +102 -0
  40. package/dist/domainSeparator-B_vU_zUD.cjs.map +1 -0
  41. package/dist/domainSeparator-CBCvxIj-.js +79 -0
  42. package/dist/domainSeparator-CBCvxIj-.js.map +1 -0
  43. package/dist/execution-CRDyKu45.d.ts +227 -0
  44. package/dist/execution-CRDyKu45.d.ts.map +1 -0
  45. package/dist/execution-DyxaIG4v.d.cts +227 -0
  46. package/dist/execution-DyxaIG4v.d.cts.map +1 -0
  47. package/dist/hex-DIcaALXL.js +112 -0
  48. package/dist/hex-DIcaALXL.js.map +1 -0
  49. package/dist/hex-DkGpiZ5e.cjs +189 -0
  50. package/dist/hex-DkGpiZ5e.cjs.map +1 -0
  51. package/dist/index--5LsCotr.d.ts +192 -0
  52. package/dist/index--5LsCotr.d.ts.map +1 -0
  53. package/dist/index-B5KqSHeL.d.cts +192 -0
  54. package/dist/index-B5KqSHeL.d.cts.map +1 -0
  55. package/dist/index-BZ0O5jZG.d.cts +163 -0
  56. package/dist/index-BZ0O5jZG.d.cts.map +1 -0
  57. package/dist/index-BuPQcAK2.d.ts +23 -0
  58. package/dist/index-BuPQcAK2.d.ts.map +1 -0
  59. package/dist/index-ByNNqY7S.d.cts +83 -0
  60. package/dist/index-ByNNqY7S.d.cts.map +1 -0
  61. package/dist/index-C-M-4jMR.d.cts +263 -0
  62. package/dist/index-C-M-4jMR.d.cts.map +1 -0
  63. package/dist/index-C97zw2rk.d.ts +137 -0
  64. package/dist/index-C97zw2rk.d.ts.map +1 -0
  65. package/dist/index-CIHK7Ew9.d.cts +303 -0
  66. package/dist/index-CIHK7Ew9.d.cts.map +1 -0
  67. package/dist/index-CIHK7Ew9.d.ts +303 -0
  68. package/dist/index-CIHK7Ew9.d.ts.map +1 -0
  69. package/dist/index-CXuO2Zjx.d.ts +263 -0
  70. package/dist/index-CXuO2Zjx.d.ts.map +1 -0
  71. package/dist/index-DOEBWXY2.d.cts +137 -0
  72. package/dist/index-DOEBWXY2.d.cts.map +1 -0
  73. package/dist/index-DzrLv3EA.d.cts +82 -0
  74. package/dist/index-DzrLv3EA.d.cts.map +1 -0
  75. package/dist/index-DzrLv3EA.d.ts +82 -0
  76. package/dist/index-DzrLv3EA.d.ts.map +1 -0
  77. package/dist/index-fdTURpBk.d.ts +83 -0
  78. package/dist/index-fdTURpBk.d.ts.map +1 -0
  79. package/dist/index-sAzHHayu.d.ts +163 -0
  80. package/dist/index-sAzHHayu.d.ts.map +1 -0
  81. package/dist/index-uQqRk9Ww.d.cts +23 -0
  82. package/dist/index-uQqRk9Ww.d.cts.map +1 -0
  83. package/dist/index.cjs +478 -0
  84. package/dist/index.cjs.map +1 -0
  85. package/dist/index.d.cts +173 -0
  86. package/dist/index.d.cts.map +1 -0
  87. package/dist/index.d.ts +173 -0
  88. package/dist/index.d.ts.map +1 -0
  89. package/dist/index.js +231 -0
  90. package/dist/index.js.map +1 -0
  91. package/dist/provider.cjs +101 -0
  92. package/dist/provider.cjs.map +1 -0
  93. package/dist/provider.d.cts +2 -0
  94. package/dist/provider.d.ts +2 -0
  95. package/dist/provider.js +76 -0
  96. package/dist/provider.js.map +1 -0
  97. package/dist/readError-BVbfTMLv.cjs +604 -0
  98. package/dist/readError-BVbfTMLv.cjs.map +1 -0
  99. package/dist/readError-Dn_XN98x.js +551 -0
  100. package/dist/readError-Dn_XN98x.js.map +1 -0
  101. package/dist/readViews-BKJtE5J3.d.cts +594 -0
  102. package/dist/readViews-BKJtE5J3.d.cts.map +1 -0
  103. package/dist/readViews-C_FX8wby.d.ts +594 -0
  104. package/dist/readViews-C_FX8wby.d.ts.map +1 -0
  105. package/dist/rolldown-runtime-D6vf50IK.cjs +28 -0
  106. package/dist/sendInvocation-2EZanZZr.cjs +661 -0
  107. package/dist/sendInvocation-2EZanZZr.cjs.map +1 -0
  108. package/dist/sendInvocation-C4ruTC-9.js +505 -0
  109. package/dist/sendInvocation-C4ruTC-9.js.map +1 -0
  110. package/dist/sign-BewmV_EL.cjs +139 -0
  111. package/dist/sign-BewmV_EL.cjs.map +1 -0
  112. package/dist/sign-DVIRyW8Y.js +122 -0
  113. package/dist/sign-DVIRyW8Y.js.map +1 -0
  114. package/dist/sign-Ve0eetRO.d.ts +48 -0
  115. package/dist/sign-Ve0eetRO.d.ts.map +1 -0
  116. package/dist/sign-eUT0iGQG.d.cts +48 -0
  117. package/dist/sign-eUT0iGQG.d.cts.map +1 -0
  118. package/dist/signed-op.cjs +9 -0
  119. package/dist/signed-op.d.cts +3 -0
  120. package/dist/signed-op.d.ts +3 -0
  121. package/dist/signed-op.js +3 -0
  122. package/dist/signedOp-Bluo0OAd.cjs +183 -0
  123. package/dist/signedOp-Bluo0OAd.cjs.map +1 -0
  124. package/dist/signedOp-x4fakrr4.js +166 -0
  125. package/dist/signedOp-x4fakrr4.js.map +1 -0
  126. package/dist/signed_op-BzVbBgv4.js +154 -0
  127. package/dist/signed_op-BzVbBgv4.js.map +1 -0
  128. package/dist/signed_op-DFgQ2yFj.d.ts +58 -0
  129. package/dist/signed_op-DFgQ2yFj.d.ts.map +1 -0
  130. package/dist/signed_op-LwxrDud8.d.cts +58 -0
  131. package/dist/signed_op-LwxrDud8.d.cts.map +1 -0
  132. package/dist/signed_op-z_8fqAi1.cjs +175 -0
  133. package/dist/signed_op-z_8fqAi1.cjs.map +1 -0
  134. package/dist/signers-BFP84wJP.cjs +137 -0
  135. package/dist/signers-BFP84wJP.cjs.map +1 -0
  136. package/dist/signers-CzOSedwJ.js +120 -0
  137. package/dist/signers-CzOSedwJ.js.map +1 -0
  138. package/dist/signers.cjs +5 -0
  139. package/dist/signers.d.cts +3 -0
  140. package/dist/signers.d.ts +3 -0
  141. package/dist/signers.js +2 -0
  142. package/dist/size-506oTE28.js +91 -0
  143. package/dist/size-506oTE28.js.map +1 -0
  144. package/dist/size-OAFfOthl.cjs +108 -0
  145. package/dist/size-OAFfOthl.cjs.map +1 -0
  146. package/dist/transaction-CwkQxQOx.js +24 -0
  147. package/dist/transaction-CwkQxQOx.js.map +1 -0
  148. package/dist/transaction-DrSrCJ5y.cjs +47 -0
  149. package/dist/transaction-DrSrCJ5y.cjs.map +1 -0
  150. package/dist/transaction.cjs +13 -0
  151. package/dist/transaction.d.cts +3 -0
  152. package/dist/transaction.d.ts +3 -0
  153. package/dist/transaction.js +4 -0
  154. package/dist/transactionHash-CO9ajbvU.js +24 -0
  155. package/dist/transactionHash-CO9ajbvU.js.map +1 -0
  156. package/dist/transactionHash-D5yf4KoL.cjs +29 -0
  157. package/dist/transactionHash-D5yf4KoL.cjs.map +1 -0
  158. package/dist/transport-B-P16rs6.cjs +252 -0
  159. package/dist/transport-B-P16rs6.cjs.map +1 -0
  160. package/dist/transport-DqyoNtUy.js +234 -0
  161. package/dist/transport-DqyoNtUy.js.map +1 -0
  162. package/dist/transport.cjs +19 -0
  163. package/dist/transport.d.cts +3 -0
  164. package/dist/transport.d.ts +3 -0
  165. package/dist/transport.js +4 -0
  166. package/dist/types-BE40oD_Q.d.cts +18 -0
  167. package/dist/types-BE40oD_Q.d.cts.map +1 -0
  168. package/dist/types-BE40oD_Q.d.ts +18 -0
  169. package/dist/types-BE40oD_Q.d.ts.map +1 -0
  170. package/dist/validation-4w-vDGAi.cjs +543 -0
  171. package/dist/validation-4w-vDGAi.cjs.map +1 -0
  172. package/dist/validation-eXATmgO0.js +411 -0
  173. package/dist/validation-eXATmgO0.js.map +1 -0
  174. package/dist/wallet-Bthapk8i.cjs +709 -0
  175. package/dist/wallet-Bthapk8i.cjs.map +1 -0
  176. package/dist/wallet-CwWPYoHF.js +667 -0
  177. package/dist/wallet-CwWPYoHF.js.map +1 -0
  178. package/dist/wallet.cjs +27 -0
  179. package/dist/wallet.d.cts +3 -0
  180. package/dist/wallet.d.ts +3 -0
  181. package/dist/wallet.js +3 -0
  182. package/package.json +122 -4
@@ -0,0 +1,112 @@
1
+ import { contractAddress, fromHex, sha256Hash, toHex } from "@thruputchain/protocol";
2
+ import { base32nopad } from "@scure/base";
3
+ import { fromBase58, fromBase58 as fromBase58$1, maxBase58Length, toBase58 } from "@thruputchain/protocol/utils";
4
+ //#region src/encoding.ts
5
+ const ADDRESS_STRKEY_VERSION = 200;
6
+ /** Decode exactly the expected number of bytes, with no format fallback. */
7
+ function fixedFromBase58(text, byteLength) {
8
+ const bytes = fromBase58(text, byteLength);
9
+ if (bytes.length !== byteLength) {
10
+ bytes.fill(0);
11
+ throw new Error(`Expected ${byteLength} bytes`);
12
+ }
13
+ return bytes;
14
+ }
15
+ /** Decode a canonical base58 Thruput address, without account derivation. */
16
+ function addressFromBase58(text) {
17
+ return contractAddress(fixedFromBase58(text, 32));
18
+ }
19
+ /** Decode a canonical base58 SHA-256 hash. */
20
+ function hashFromBase58(text) {
21
+ return sha256Hash(fixedFromBase58(text, 32));
22
+ }
23
+ function checksum(bytes) {
24
+ let crc = 0;
25
+ for (const byte of bytes) {
26
+ crc ^= byte << 8;
27
+ for (let bit = 0; bit < 8; bit++) crc = (crc << 1 ^ (crc & 32768 ? 4129 : 0)) & 65535;
28
+ }
29
+ return crc;
30
+ }
31
+ function strkey(bytes, version) {
32
+ if (bytes.length !== 32) throw new Error("Expected 32 bytes");
33
+ const encoded = new Uint8Array(35);
34
+ try {
35
+ encoded[0] = version;
36
+ encoded.set(bytes, 1);
37
+ const crc = checksum(encoded.subarray(0, 33));
38
+ encoded[33] = crc & 255;
39
+ encoded[34] = crc >>> 8;
40
+ return base32nopad.encode(encoded);
41
+ } finally {
42
+ encoded.fill(0);
43
+ }
44
+ }
45
+ function parseTyped(text, version, prefix) {
46
+ if (typeof text === "string" && text.length === 56) {
47
+ let decoded;
48
+ try {
49
+ decoded = base32nopad.decode(text);
50
+ if (decoded.length === 35 && decoded[0] === version && base32nopad.encode(decoded) === text && checksum(decoded.subarray(0, 33)) === (decoded[33] | decoded[34] << 8)) return decoded.slice(1, 33);
51
+ } catch {} finally {
52
+ decoded?.fill(0);
53
+ }
54
+ } else try {
55
+ return fixedFromBase58(text, 32);
56
+ } catch {}
57
+ throw new Error(`Expected a 32-byte base58 value or a valid ${prefix} StrKey`);
58
+ }
59
+ /**
60
+ * Parse human address input: base58 or Thruput Z StrKey, without account derivation.
61
+ * Stellar C addresses are rejected. Z does not identify a specific Thruput network.
62
+ */
63
+ function parseAddress(text) {
64
+ return contractAddress(parseTyped(text, ADDRESS_STRKEY_VERSION, "Z"));
65
+ }
66
+ /** Parse human Ed25519 key input: base58 or G StrKey, never a wallet address. */
67
+ function parsePublicKey(text) {
68
+ return parseTyped(text, 48, "G");
69
+ }
70
+ /**
71
+ * Explicitly import a 32-byte Ed25519 seed from base58 or S StrKey.
72
+ * Callers must clear returned bytes after use. JavaScript input strings cannot
73
+ * be reliably erased; do not log or persist them in diagnostics.
74
+ */
75
+ function parseSecretSeed(text) {
76
+ return parseTyped(text, 144, "S");
77
+ }
78
+ /** Render address bytes as a Thruput Z StrKey, without a specific network identity. */
79
+ function addressToStrkey(bytes) {
80
+ return strkey(bytes, ADDRESS_STRKEY_VERSION);
81
+ }
82
+ /** Render an Ed25519 public key as a G StrKey, without deriving an address. */
83
+ function publicKeyToStrkey(bytes) {
84
+ return strkey(bytes, 48);
85
+ }
86
+ /** Explicitly export a seed as an S StrKey. Treat the returned string as secret. */
87
+ function secretSeedToStrkey(bytes) {
88
+ return strkey(bytes, 144);
89
+ }
90
+ //#endregion
91
+ //#region src/actions/hex.ts
92
+ /** Convert bytes to a `0x`-prefixed lowercase hex string. */
93
+ function toHex0x(bytes) {
94
+ return "0x" + toHex(bytes);
95
+ }
96
+ /** Decode a `0x`-prefixed hex string into bytes. */
97
+ function fromHex0x(hex) {
98
+ if (!hex.startsWith("0x")) throw new Error(`Expected 0x-prefixed hex string, got: ${hex}`);
99
+ return fromHex(hex.slice(2));
100
+ }
101
+ /** Decode a `0x`-prefixed hex string into a protocol SHA-256 hash. */
102
+ function hashFromHex(hex) {
103
+ return sha256Hash(fromHex0x(hex));
104
+ }
105
+ /** Decode a `0x`-prefixed hex string into a contract address. */
106
+ function addressFromHex(hex) {
107
+ return contractAddress(fromHex0x(hex));
108
+ }
109
+ //#endregion
110
+ export { addressFromBase58 as a, fromBase58$1 as c, parseAddress as d, parsePublicKey as f, toBase58 as g, secretSeedToStrkey as h, toHex0x as i, hashFromBase58 as l, publicKeyToStrkey as m, fromHex0x as n, addressToStrkey as o, parseSecretSeed as p, hashFromHex as r, fixedFromBase58 as s, addressFromHex as t, maxBase58Length as u };
111
+
112
+ //# sourceMappingURL=hex-DIcaALXL.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hex-DIcaALXL.js","names":[],"sources":["../src/encoding.ts","../src/actions/hex.ts"],"sourcesContent":["import { base32nopad } from \"@scure/base\";\nimport { fromBase58 } from \"@thruputchain/protocol/utils\";\nimport { contractAddress, sha256Hash } from \"@thruputchain/protocol\";\nimport type { ContractAddress, SHA256Hash } from \"@thruputchain/protocol\";\n\nconst ADDRESS_STRKEY_VERSION = 25 << 3;\n\nexport {\n toBase58,\n fromBase58,\n maxBase58Length,\n} from \"@thruputchain/protocol/utils\";\n\n/** Decode exactly the expected number of bytes, with no format fallback. */\nexport function fixedFromBase58(text: string, byteLength: number): Uint8Array {\n const bytes = fromBase58(text, byteLength);\n if (bytes.length !== byteLength) {\n bytes.fill(0);\n throw new Error(`Expected ${byteLength} bytes`);\n }\n return bytes;\n}\n\n/** Decode a canonical base58 Thruput address, without account derivation. */\nexport function addressFromBase58(text: string): ContractAddress {\n return contractAddress(fixedFromBase58(text, 32));\n}\n\n/** Decode a canonical base58 SHA-256 hash. */\nexport function hashFromBase58(text: string): SHA256Hash {\n return sha256Hash(fixedFromBase58(text, 32));\n}\n\n// SEP-23 CRC16-XModem: polynomial 0x1021, initial value zero, little-endian\n// checksum bytes. This is typo detection, not cryptographic authentication.\nfunction checksum(bytes: Uint8Array): number {\n let crc = 0;\n for (const byte of bytes) {\n crc ^= byte << 8;\n for (let bit = 0; bit < 8; bit++) {\n crc = ((crc << 1) ^ (crc & 0x8000 ? 0x1021 : 0)) & 0xffff;\n }\n }\n return crc;\n}\n\nfunction strkey(bytes: Uint8Array, version: number): string {\n if (bytes.length !== 32) throw new Error(\"Expected 32 bytes\");\n const encoded = new Uint8Array(35);\n try {\n encoded[0] = version;\n encoded.set(bytes, 1);\n const crc = checksum(encoded.subarray(0, 33));\n encoded[33] = crc & 0xff;\n encoded[34] = crc >>> 8;\n return base32nopad.encode(encoded);\n } finally {\n encoded.fill(0);\n }\n}\n\nfunction parseTyped(text: string, version: number, prefix: string): Uint8Array {\n // A 32-byte base58 value is at most 44 characters. Z/G/S StrKeys have 56.\n // Dispatch by full length, never by a prefix that valid base58 can share.\n if (typeof text === \"string\" && text.length === 56) {\n let decoded: Uint8Array | undefined;\n try {\n decoded = base32nopad.decode(text);\n if (\n decoded.length === 35 &&\n decoded[0] === version &&\n base32nopad.encode(decoded) === text &&\n checksum(decoded.subarray(0, 33)) ===\n (decoded[33]! | (decoded[34]! << 8))\n ) {\n return decoded.slice(1, 33);\n }\n } catch {\n // Return the same redacted error for malformed and wrong-type StrKeys.\n } finally {\n decoded?.fill(0);\n }\n } else {\n try {\n return fixedFromBase58(text, 32);\n } catch {\n // Do not expose input (which may be a secret seed) in errors.\n }\n }\n throw new Error(\n `Expected a 32-byte base58 value or a valid ${prefix} StrKey`,\n );\n}\n\n/**\n * Parse human address input: base58 or Thruput Z StrKey, without account derivation.\n * Stellar C addresses are rejected. Z does not identify a specific Thruput network.\n */\nexport function parseAddress(text: string): ContractAddress {\n return contractAddress(parseTyped(text, ADDRESS_STRKEY_VERSION, \"Z\"));\n}\n\n/** Parse human Ed25519 key input: base58 or G StrKey, never a wallet address. */\nexport function parsePublicKey(text: string): Uint8Array {\n return parseTyped(text, 6 << 3, \"G\");\n}\n\n/**\n * Explicitly import a 32-byte Ed25519 seed from base58 or S StrKey.\n * Callers must clear returned bytes after use. JavaScript input strings cannot\n * be reliably erased; do not log or persist them in diagnostics.\n */\nexport function parseSecretSeed(text: string): Uint8Array {\n return parseTyped(text, 18 << 3, \"S\");\n}\n\n/** Render address bytes as a Thruput Z StrKey, without a specific network identity. */\nexport function addressToStrkey(bytes: Uint8Array): string {\n return strkey(bytes, ADDRESS_STRKEY_VERSION);\n}\n\n/** Render an Ed25519 public key as a G StrKey, without deriving an address. */\nexport function publicKeyToStrkey(bytes: Uint8Array): string {\n return strkey(bytes, 6 << 3);\n}\n\n/** Explicitly export a seed as an S StrKey. Treat the returned string as secret. */\nexport function secretSeedToStrkey(bytes: Uint8Array): string {\n return strkey(bytes, 18 << 3);\n}\n","import type { SHA256Hash, ContractAddress } from \"@thruputchain/protocol\";\nimport {\n toHex,\n fromHex,\n sha256Hash,\n contractAddress,\n} from \"@thruputchain/protocol\";\n\nexport { toHex, fromHex } from \"@thruputchain/protocol\";\n\n/** Convert bytes to a `0x`-prefixed lowercase hex string. */\nexport function toHex0x(bytes: Uint8Array): string {\n return \"0x\" + toHex(bytes);\n}\n\n/** Decode a `0x`-prefixed hex string into bytes. */\nexport function fromHex0x(hex: string): Uint8Array {\n if (!hex.startsWith(\"0x\"))\n throw new Error(`Expected 0x-prefixed hex string, got: ${hex}`);\n return fromHex(hex.slice(2));\n}\n\n/** Decode a `0x`-prefixed hex string into a protocol SHA-256 hash. */\nexport function hashFromHex(hex: string): SHA256Hash {\n return sha256Hash(fromHex0x(hex));\n}\n\n/** Decode a `0x`-prefixed hex string into a contract address. */\nexport function addressFromHex(hex: string): ContractAddress {\n return contractAddress(fromHex0x(hex));\n}\n"],"mappings":";;;;AAKA,MAAM,yBAAyB;;AAS/B,SAAgB,gBAAgB,MAAc,YAAgC;CAC5E,MAAM,QAAQ,WAAW,MAAM,UAAU;CACzC,IAAI,MAAM,WAAW,YAAY;EAC/B,MAAM,KAAK,CAAC;EACZ,MAAM,IAAI,MAAM,YAAY,WAAW,OAAO;CAChD;CACA,OAAO;AACT;;AAGA,SAAgB,kBAAkB,MAA+B;CAC/D,OAAO,gBAAgB,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O,gBAAgB,WAAW,MAAM,wBAAwB,GAAG,CAAC;AACtE;;AAGA,SAAgB,eAAe,MAA0B;CACvD,OAAO,WAAW,MAAM,IAAQ,GAAG;AACrC;;;;;;AAOA,SAAgB,gBAAgB,MAA0B;CACxD,OAAO,WAAW,MAAM,KAAS,GAAG;AACtC;;AAGA,SAAgB,gBAAgB,OAA2B;CACzD,OAAO,OAAO,OAAO,sBAAsB;AAC7C;;AAGA,SAAgB,kBAAkB,OAA2B;CAC3D,OAAO,OAAO,OAAO,EAAM;AAC7B;;AAGA,SAAgB,mBAAmB,OAA2B;CAC5D,OAAO,OAAO,OAAO,GAAO;AAC9B;;;;ACtHA,SAAgB,QAAQ,OAA2B;CACjD,OAAO,OAAO,MAAM,KAAK;AAC3B;;AAGA,SAAgB,UAAU,KAAyB;CACjD,IAAI,CAAC,IAAI,WAAW,IAAI,GACtB,MAAM,IAAI,MAAM,yCAAyC,KAAK;CAChE,OAAO,QAAQ,IAAI,MAAM,CAAC,CAAC;AAC7B;;AAGA,SAAgB,YAAY,KAAyB;CACnD,OAAO,WAAW,UAAU,GAAG,CAAC;AAClC;;AAGA,SAAgB,eAAe,KAA8B;CAC3D,OAAO,gBAAgB,UAAU,GAAG,CAAC;AACvC"}
@@ -0,0 +1,189 @@
1
+ let _thruputchain_protocol = require("@thruputchain/protocol");
2
+ let _scure_base = require("@scure/base");
3
+ let _thruputchain_protocol_utils = require("@thruputchain/protocol/utils");
4
+ //#region src/encoding.ts
5
+ const ADDRESS_STRKEY_VERSION = 200;
6
+ /** Decode exactly the expected number of bytes, with no format fallback. */
7
+ function fixedFromBase58(text, byteLength) {
8
+ const bytes = (0, _thruputchain_protocol_utils.fromBase58)(text, byteLength);
9
+ if (bytes.length !== byteLength) {
10
+ bytes.fill(0);
11
+ throw new Error(`Expected ${byteLength} bytes`);
12
+ }
13
+ return bytes;
14
+ }
15
+ /** Decode a canonical base58 Thruput address, without account derivation. */
16
+ function addressFromBase58(text) {
17
+ return (0, _thruputchain_protocol.contractAddress)(fixedFromBase58(text, 32));
18
+ }
19
+ /** Decode a canonical base58 SHA-256 hash. */
20
+ function hashFromBase58(text) {
21
+ return (0, _thruputchain_protocol.sha256Hash)(fixedFromBase58(text, 32));
22
+ }
23
+ function checksum(bytes) {
24
+ let crc = 0;
25
+ for (const byte of bytes) {
26
+ crc ^= byte << 8;
27
+ for (let bit = 0; bit < 8; bit++) crc = (crc << 1 ^ (crc & 32768 ? 4129 : 0)) & 65535;
28
+ }
29
+ return crc;
30
+ }
31
+ function strkey(bytes, version) {
32
+ if (bytes.length !== 32) throw new Error("Expected 32 bytes");
33
+ const encoded = new Uint8Array(35);
34
+ try {
35
+ encoded[0] = version;
36
+ encoded.set(bytes, 1);
37
+ const crc = checksum(encoded.subarray(0, 33));
38
+ encoded[33] = crc & 255;
39
+ encoded[34] = crc >>> 8;
40
+ return _scure_base.base32nopad.encode(encoded);
41
+ } finally {
42
+ encoded.fill(0);
43
+ }
44
+ }
45
+ function parseTyped(text, version, prefix) {
46
+ if (typeof text === "string" && text.length === 56) {
47
+ let decoded;
48
+ try {
49
+ decoded = _scure_base.base32nopad.decode(text);
50
+ if (decoded.length === 35 && decoded[0] === version && _scure_base.base32nopad.encode(decoded) === text && checksum(decoded.subarray(0, 33)) === (decoded[33] | decoded[34] << 8)) return decoded.slice(1, 33);
51
+ } catch {} finally {
52
+ decoded?.fill(0);
53
+ }
54
+ } else try {
55
+ return fixedFromBase58(text, 32);
56
+ } catch {}
57
+ throw new Error(`Expected a 32-byte base58 value or a valid ${prefix} StrKey`);
58
+ }
59
+ /**
60
+ * Parse human address input: base58 or Thruput Z StrKey, without account derivation.
61
+ * Stellar C addresses are rejected. Z does not identify a specific Thruput network.
62
+ */
63
+ function parseAddress(text) {
64
+ return (0, _thruputchain_protocol.contractAddress)(parseTyped(text, ADDRESS_STRKEY_VERSION, "Z"));
65
+ }
66
+ /** Parse human Ed25519 key input: base58 or G StrKey, never a wallet address. */
67
+ function parsePublicKey(text) {
68
+ return parseTyped(text, 48, "G");
69
+ }
70
+ /**
71
+ * Explicitly import a 32-byte Ed25519 seed from base58 or S StrKey.
72
+ * Callers must clear returned bytes after use. JavaScript input strings cannot
73
+ * be reliably erased; do not log or persist them in diagnostics.
74
+ */
75
+ function parseSecretSeed(text) {
76
+ return parseTyped(text, 144, "S");
77
+ }
78
+ /** Render address bytes as a Thruput Z StrKey, without a specific network identity. */
79
+ function addressToStrkey(bytes) {
80
+ return strkey(bytes, ADDRESS_STRKEY_VERSION);
81
+ }
82
+ /** Render an Ed25519 public key as a G StrKey, without deriving an address. */
83
+ function publicKeyToStrkey(bytes) {
84
+ return strkey(bytes, 48);
85
+ }
86
+ /** Explicitly export a seed as an S StrKey. Treat the returned string as secret. */
87
+ function secretSeedToStrkey(bytes) {
88
+ return strkey(bytes, 144);
89
+ }
90
+ //#endregion
91
+ //#region src/actions/hex.ts
92
+ /** Convert bytes to a `0x`-prefixed lowercase hex string. */
93
+ function toHex0x(bytes) {
94
+ return "0x" + (0, _thruputchain_protocol.toHex)(bytes);
95
+ }
96
+ /** Decode a `0x`-prefixed hex string into bytes. */
97
+ function fromHex0x(hex) {
98
+ if (!hex.startsWith("0x")) throw new Error(`Expected 0x-prefixed hex string, got: ${hex}`);
99
+ return (0, _thruputchain_protocol.fromHex)(hex.slice(2));
100
+ }
101
+ /** Decode a `0x`-prefixed hex string into a protocol SHA-256 hash. */
102
+ function hashFromHex(hex) {
103
+ return (0, _thruputchain_protocol.sha256Hash)(fromHex0x(hex));
104
+ }
105
+ /** Decode a `0x`-prefixed hex string into a contract address. */
106
+ function addressFromHex(hex) {
107
+ return (0, _thruputchain_protocol.contractAddress)(fromHex0x(hex));
108
+ }
109
+ //#endregion
110
+ Object.defineProperty(exports, "addressFromBase58", {
111
+ enumerable: true,
112
+ get: function() {
113
+ return addressFromBase58;
114
+ }
115
+ });
116
+ Object.defineProperty(exports, "addressFromHex", {
117
+ enumerable: true,
118
+ get: function() {
119
+ return addressFromHex;
120
+ }
121
+ });
122
+ Object.defineProperty(exports, "addressToStrkey", {
123
+ enumerable: true,
124
+ get: function() {
125
+ return addressToStrkey;
126
+ }
127
+ });
128
+ Object.defineProperty(exports, "fixedFromBase58", {
129
+ enumerable: true,
130
+ get: function() {
131
+ return fixedFromBase58;
132
+ }
133
+ });
134
+ Object.defineProperty(exports, "fromHex0x", {
135
+ enumerable: true,
136
+ get: function() {
137
+ return fromHex0x;
138
+ }
139
+ });
140
+ Object.defineProperty(exports, "hashFromBase58", {
141
+ enumerable: true,
142
+ get: function() {
143
+ return hashFromBase58;
144
+ }
145
+ });
146
+ Object.defineProperty(exports, "hashFromHex", {
147
+ enumerable: true,
148
+ get: function() {
149
+ return hashFromHex;
150
+ }
151
+ });
152
+ Object.defineProperty(exports, "parseAddress", {
153
+ enumerable: true,
154
+ get: function() {
155
+ return parseAddress;
156
+ }
157
+ });
158
+ Object.defineProperty(exports, "parsePublicKey", {
159
+ enumerable: true,
160
+ get: function() {
161
+ return parsePublicKey;
162
+ }
163
+ });
164
+ Object.defineProperty(exports, "parseSecretSeed", {
165
+ enumerable: true,
166
+ get: function() {
167
+ return parseSecretSeed;
168
+ }
169
+ });
170
+ Object.defineProperty(exports, "publicKeyToStrkey", {
171
+ enumerable: true,
172
+ get: function() {
173
+ return publicKeyToStrkey;
174
+ }
175
+ });
176
+ Object.defineProperty(exports, "secretSeedToStrkey", {
177
+ enumerable: true,
178
+ get: function() {
179
+ return secretSeedToStrkey;
180
+ }
181
+ });
182
+ Object.defineProperty(exports, "toHex0x", {
183
+ enumerable: true,
184
+ get: function() {
185
+ return toHex0x;
186
+ }
187
+ });
188
+
189
+ //# sourceMappingURL=hex-DkGpiZ5e.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hex-DkGpiZ5e.cjs","names":["base32nopad"],"sources":["../src/encoding.ts","../src/actions/hex.ts"],"sourcesContent":["import { base32nopad } from \"@scure/base\";\nimport { fromBase58 } from \"@thruputchain/protocol/utils\";\nimport { contractAddress, sha256Hash } from \"@thruputchain/protocol\";\nimport type { ContractAddress, SHA256Hash } from \"@thruputchain/protocol\";\n\nconst ADDRESS_STRKEY_VERSION = 25 << 3;\n\nexport {\n toBase58,\n fromBase58,\n maxBase58Length,\n} from \"@thruputchain/protocol/utils\";\n\n/** Decode exactly the expected number of bytes, with no format fallback. */\nexport function fixedFromBase58(text: string, byteLength: number): Uint8Array {\n const bytes = fromBase58(text, byteLength);\n if (bytes.length !== byteLength) {\n bytes.fill(0);\n throw new Error(`Expected ${byteLength} bytes`);\n }\n return bytes;\n}\n\n/** Decode a canonical base58 Thruput address, without account derivation. */\nexport function addressFromBase58(text: string): ContractAddress {\n return contractAddress(fixedFromBase58(text, 32));\n}\n\n/** Decode a canonical base58 SHA-256 hash. */\nexport function hashFromBase58(text: string): SHA256Hash {\n return sha256Hash(fixedFromBase58(text, 32));\n}\n\n// SEP-23 CRC16-XModem: polynomial 0x1021, initial value zero, little-endian\n// checksum bytes. This is typo detection, not cryptographic authentication.\nfunction checksum(bytes: Uint8Array): number {\n let crc = 0;\n for (const byte of bytes) {\n crc ^= byte << 8;\n for (let bit = 0; bit < 8; bit++) {\n crc = ((crc << 1) ^ (crc & 0x8000 ? 0x1021 : 0)) & 0xffff;\n }\n }\n return crc;\n}\n\nfunction strkey(bytes: Uint8Array, version: number): string {\n if (bytes.length !== 32) throw new Error(\"Expected 32 bytes\");\n const encoded = new Uint8Array(35);\n try {\n encoded[0] = version;\n encoded.set(bytes, 1);\n const crc = checksum(encoded.subarray(0, 33));\n encoded[33] = crc & 0xff;\n encoded[34] = crc >>> 8;\n return base32nopad.encode(encoded);\n } finally {\n encoded.fill(0);\n }\n}\n\nfunction parseTyped(text: string, version: number, prefix: string): Uint8Array {\n // A 32-byte base58 value is at most 44 characters. Z/G/S StrKeys have 56.\n // Dispatch by full length, never by a prefix that valid base58 can share.\n if (typeof text === \"string\" && text.length === 56) {\n let decoded: Uint8Array | undefined;\n try {\n decoded = base32nopad.decode(text);\n if (\n decoded.length === 35 &&\n decoded[0] === version &&\n base32nopad.encode(decoded) === text &&\n checksum(decoded.subarray(0, 33)) ===\n (decoded[33]! | (decoded[34]! << 8))\n ) {\n return decoded.slice(1, 33);\n }\n } catch {\n // Return the same redacted error for malformed and wrong-type StrKeys.\n } finally {\n decoded?.fill(0);\n }\n } else {\n try {\n return fixedFromBase58(text, 32);\n } catch {\n // Do not expose input (which may be a secret seed) in errors.\n }\n }\n throw new Error(\n `Expected a 32-byte base58 value or a valid ${prefix} StrKey`,\n );\n}\n\n/**\n * Parse human address input: base58 or Thruput Z StrKey, without account derivation.\n * Stellar C addresses are rejected. Z does not identify a specific Thruput network.\n */\nexport function parseAddress(text: string): ContractAddress {\n return contractAddress(parseTyped(text, ADDRESS_STRKEY_VERSION, \"Z\"));\n}\n\n/** Parse human Ed25519 key input: base58 or G StrKey, never a wallet address. */\nexport function parsePublicKey(text: string): Uint8Array {\n return parseTyped(text, 6 << 3, \"G\");\n}\n\n/**\n * Explicitly import a 32-byte Ed25519 seed from base58 or S StrKey.\n * Callers must clear returned bytes after use. JavaScript input strings cannot\n * be reliably erased; do not log or persist them in diagnostics.\n */\nexport function parseSecretSeed(text: string): Uint8Array {\n return parseTyped(text, 18 << 3, \"S\");\n}\n\n/** Render address bytes as a Thruput Z StrKey, without a specific network identity. */\nexport function addressToStrkey(bytes: Uint8Array): string {\n return strkey(bytes, ADDRESS_STRKEY_VERSION);\n}\n\n/** Render an Ed25519 public key as a G StrKey, without deriving an address. */\nexport function publicKeyToStrkey(bytes: Uint8Array): string {\n return strkey(bytes, 6 << 3);\n}\n\n/** Explicitly export a seed as an S StrKey. Treat the returned string as secret. */\nexport function secretSeedToStrkey(bytes: Uint8Array): string {\n return strkey(bytes, 18 << 3);\n}\n","import type { SHA256Hash, ContractAddress } from \"@thruputchain/protocol\";\nimport {\n toHex,\n fromHex,\n sha256Hash,\n contractAddress,\n} from \"@thruputchain/protocol\";\n\nexport { toHex, fromHex } from \"@thruputchain/protocol\";\n\n/** Convert bytes to a `0x`-prefixed lowercase hex string. */\nexport function toHex0x(bytes: Uint8Array): string {\n return \"0x\" + toHex(bytes);\n}\n\n/** Decode a `0x`-prefixed hex string into bytes. */\nexport function fromHex0x(hex: string): Uint8Array {\n if (!hex.startsWith(\"0x\"))\n throw new Error(`Expected 0x-prefixed hex string, got: ${hex}`);\n return fromHex(hex.slice(2));\n}\n\n/** Decode a `0x`-prefixed hex string into a protocol SHA-256 hash. */\nexport function hashFromHex(hex: string): SHA256Hash {\n return sha256Hash(fromHex0x(hex));\n}\n\n/** Decode a `0x`-prefixed hex string into a contract address. */\nexport function addressFromHex(hex: string): ContractAddress {\n return contractAddress(fromHex0x(hex));\n}\n"],"mappings":";;;;AAKA,MAAM,yBAAyB;;AAS/B,SAAgB,gBAAgB,MAAc,YAAgC;CAC5E,MAAM,SAAA,GAAA,6BAAA,WAAA,CAAmB,MAAM,UAAU;CACzC,IAAI,MAAM,WAAW,YAAY;EAC/B,MAAM,KAAK,CAAC;EACZ,MAAM,IAAI,MAAM,YAAY,WAAW,OAAO;CAChD;CACA,OAAO;AACT;;AAGA,SAAgB,kBAAkB,MAA+B;CAC/D,QAAA,GAAA,uBAAA,gBAAA,CAAuB,gBAAgB,MAAM,EAAE,CAAC;AAClD;;AAGA,SAAgB,eAAe,MAA0B;CACvD,QAAA,GAAA,uBAAA,WAAA,CAAkB,gBAAgB,MAAM,EAAE,CAAC;AAC7C;AAIA,SAAS,SAAS,OAA2B;CAC3C,IAAI,MAAM;CACV,KAAK,MAAM,QAAQ,OAAO;EACxB,OAAO,QAAQ;EACf,KAAK,IAAI,MAAM,GAAG,MAAM,GAAG,OACzB,OAAQ,OAAO,KAAM,MAAM,QAAS,OAAS,MAAM;CAEvD;CACA,OAAO;AACT;AAEA,SAAS,OAAO,OAAmB,SAAyB;CAC1D,IAAI,MAAM,WAAW,IAAI,MAAM,IAAI,MAAM,mBAAmB;CAC5D,MAAM,UAAU,IAAI,WAAW,EAAE;CACjC,IAAI;EAC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AAgB,QAAQ,OAA2B;CACjD,OAAO,QAAA,GAAA,uBAAA,MAAA,CAAa,KAAK;AAC3B;;AAGA,SAAgB,UAAU,KAAyB;CACjD,IAAI,CAAC,IAAI,WAAW,IAAI,GACtB,MAAM,IAAI,MAAM,yCAAyC,KAAK;CAChE,QAAA,GAAA,uBAAA,QAAA,CAAe,IAAI,MAAM,CAAC,CAAC;AAC7B;;AAGA,SAAgB,YAAY,KAAyB;CACnD,QAAA,GAAA,uBAAA,WAAA,CAAkB,UAAU,GAAG,CAAC;AAClC;;AAGA,SAAgB,eAAe,KAA8B;CAC3D,QAAA,GAAA,uBAAA,gBAAA,CAAuB,UAAU,GAAG,CAAC;AACvC"}
@@ -0,0 +1,192 @@
1
+ import { t as Signer } from "./types-BE40oD_Q.js";
2
+ import { BlockHeight, ContractAddress, NetworkHash } from "@thruputchain/protocol";
3
+ import { FixedBytes } from "@thruputchain/xdr";
4
+ import { ContractTypeDef } from "@thruputchain/contract-spec";
5
+
6
+ //#region src/signedOp/operation.d.ts
7
+ /**
8
+ * Wire form of a signed operation: the `Operation` struct of the
9
+ * `thruput-signed-op-if` interface, in the shape generated bindings give it.
10
+ *
11
+ * The network hash, the verifying contract, and the signing key are covered
12
+ * by the signature but deliberately absent here. The verifying contract
13
+ * supplies the first two from its own syscalls and checks the signature
14
+ * against the key it holds, so a submitter can name neither the network or
15
+ * contract a signature was meant for nor the key it is checked against.
16
+ *
17
+ * `block_expiry_height` and `nonce` are the chain's `Uniquifier`, in its
18
+ * field order, so their encoding is byte for byte a transaction's.
19
+ */
20
+ interface Operation {
21
+ /** Last block height (inclusive) at which the operation may execute. */
22
+ block_expiry_height: bigint;
23
+ /**
24
+ * Chosen by the signer: any value, as long as the pair
25
+ * `(nonce, block_expiry_height)` has not been consumed at the verifying
26
+ * contract. There is no ordering. Consumed pairs are the contract's, not
27
+ * the key's, so where several keys sign for one contract, draw nonces at
28
+ * random ({@link randomNonce}) rather than counting; a lone key may do
29
+ * either.
30
+ */
31
+ nonce: bigint;
32
+ /** CXS encoding of the payload value. */
33
+ body: Uint8Array;
34
+ }
35
+ /** An {@link Operation} and the Ed25519 signature over its preimage. */
36
+ interface SignedOperation {
37
+ readonly op: Operation;
38
+ readonly signature: FixedBytes<64>;
39
+ }
40
+ /** What a signer supplies to produce one operation. */
41
+ interface SignedOperationRequest<TBody> {
42
+ /** Hash of the network the operation is valid on. */
43
+ readonly network: NetworkHash;
44
+ /** Address of the contract that will verify and act on the operation. */
45
+ readonly verifyingContract: ContractAddress;
46
+ /** Last block height (inclusive) at which the operation may execute. */
47
+ readonly blockExpiryHeight: bigint;
48
+ /**
49
+ * Signer-chosen replay guard; see {@link Operation.nonce}. Nothing on
50
+ * chain needs reading to pick one: {@link randomNonce} is always safe.
51
+ */
52
+ readonly nonce: bigint;
53
+ /** The payload value, in the field shape generated bindings use. */
54
+ readonly body: TBody;
55
+ }
56
+ /** Signing helpers bound to one payload type. */
57
+ interface SignedOperationType<TBody> {
58
+ /**
59
+ * Declared name of the payload type: the `declared` segment of its spec id.
60
+ * {@link SignedOperationType.typeDef} carries the full id.
61
+ */
62
+ readonly typeName: string;
63
+ /** The payload type's spec definition, as bound into every preimage. */
64
+ readonly typeDef: ContractTypeDef;
65
+ /** CXS-encode a payload value the way the contract decodes it. */
66
+ encodeBody(body: TBody): Uint8Array;
67
+ /** The bytes a signature over `request` covers. */
68
+ preimage(request: SignedOperationRequest<TBody>): Uint8Array;
69
+ /** Encode, sign, and package `request` for the verifying contract. */
70
+ sign(signer: Signer, request: SignedOperationRequest<TBody>): Promise<SignedOperation>;
71
+ }
72
+ /** Options for {@link defineSignedOperation}. */
73
+ interface DefineSignedOperationOptions {
74
+ /**
75
+ * Type definitions the payload type is resolved against: a generated
76
+ * binding's `spec.type_defs`, which carries the payload type and every type
77
+ * it references.
78
+ */
79
+ readonly typeDefs: readonly ContractTypeDef[];
80
+ /**
81
+ * The payload type: either its name as declared with `#[contract_type]`
82
+ * (the `declared` segment of its spec id), which must name exactly one of
83
+ * `typeDefs`, or its full spec id, which selects one type even when another
84
+ * crate or module declares the same name.
85
+ */
86
+ readonly typeName: string | ContractTypeSelector;
87
+ }
88
+ /**
89
+ * Every segment of a payload type's spec id, as plain strings. A
90
+ * `ContractSpecId` taken from a generated spec is assignable to it.
91
+ */
92
+ interface ContractTypeSelector {
93
+ readonly crate_name: string;
94
+ readonly major: string;
95
+ readonly module_path: string;
96
+ readonly declared: string;
97
+ }
98
+ /**
99
+ * A uniformly random `u64` for {@link Operation.nonce}.
100
+ *
101
+ * Consumed `(nonce, block_expiry_height)` pairs are scoped to the verifying
102
+ * contract, not to the signing key, so a random nonce is the choice that
103
+ * stays safe when several keys sign for one contract; a lone key may count
104
+ * instead. Draws from the platform's `crypto.getRandomValues`.
105
+ */
106
+ declare function randomNonce(): bigint;
107
+ /**
108
+ * Bind signing helpers to a `#[contract_type]` payload.
109
+ *
110
+ * A signed operation authorizes an on-chain action off-chain, so the signer
111
+ * need not submit the transaction: the pattern behind permits, session keys,
112
+ * and delegated wallet actions. The verifying contract embeds
113
+ * `thruput_signed_op::SignedOpReplayCache` and checks the operation with
114
+ * `consume::<Payload>` against the key it holds; this is the client half,
115
+ * producing the `Operation` and signature that contract expects.
116
+ *
117
+ * @example
118
+ * ```ts
119
+ * import {
120
+ * defineSignedOperation,
121
+ * randomNonce,
122
+ * } from "@thruputchain/client/signed-op";
123
+ * import { spec, MyWallet, type my_wallet } from "./generated/my_wallet.js";
124
+ *
125
+ * const transfer = defineSignedOperation<my_wallet.v0_1.Transfer>({
126
+ * typeDefs: spec.type_defs,
127
+ * typeName: "Transfer",
128
+ * });
129
+ * const { op, signature } = await transfer.sign(signer, {
130
+ * network: networkHash,
131
+ * verifyingContract: walletAddress,
132
+ * blockExpiryHeight: currentHeight + 100n,
133
+ * nonce: randomNonce(),
134
+ * body: { to: recipient, amount: 42n },
135
+ * });
136
+ * // `op` and `signature` are the arguments of the contract's submit entrypoint.
137
+ * const invocation = MyWallet.v0_1.submit.invocation(walletAddress, gasLimit, {
138
+ * op,
139
+ * signature,
140
+ * });
141
+ * ```
142
+ *
143
+ * @throws If `typeName` selects none, or more than one, of `typeDefs`.
144
+ */
145
+ declare function defineSignedOperation<TBody>(options: DefineSignedOperationOptions): SignedOperationType<TBody>;
146
+ //#endregion
147
+ //#region src/signedOp/preimage.d.ts
148
+ /** Everything a signed-operation signature commits to. */
149
+ interface SignedOperationPreimage {
150
+ /** Hash of the network the operation is valid on. */
151
+ readonly network: NetworkHash;
152
+ /** Address of the contract entitled to act on the operation. */
153
+ readonly verifyingContract: ContractAddress;
154
+ /**
155
+ * Spec definition of the payload type, as a generated binding ships it in
156
+ * `spec.type_defs`. Part of the signed bytes, so a signature over one
157
+ * payload type is never a signature over another with the same encoding.
158
+ */
159
+ readonly typeDef: ContractTypeDef;
160
+ /** Last block height (inclusive) at which the operation may execute. */
161
+ readonly blockExpiryHeight: BlockHeight;
162
+ /**
163
+ * Signer-chosen value that, with `blockExpiryHeight`, the verifying
164
+ * contract consumes exactly once.
165
+ */
166
+ readonly nonce: bigint;
167
+ /** CXS encoding of the payload value. */
168
+ readonly body: Uint8Array;
169
+ }
170
+ /**
171
+ * The message a signed-operation signature covers:
172
+ *
173
+ * ```text
174
+ * cxs(DomainSeparator("SignedOp")) || network || verifyingContract
175
+ * || cxs(typeDef) || cxs(uniquifier) || body
176
+ * ```
177
+ *
178
+ * where `cxs(uniquifier)` is `cxs(blockExpiryHeight) || cxs(nonce)`: the
179
+ * chain's own `Uniquifier` encoding, so the replay pair is spelled the way a
180
+ * transaction spells its own. The result is signed directly, like
181
+ * {@link transactionSignaturePreimage}; Ed25519 does its own hashing. It must
182
+ * match the Rust `thruput_domain_separator::SignedOp::preimage` byte for
183
+ * byte, or the verifying contract rejects the signature. Only the first 74
184
+ * bytes are fixed-width: the uniquifier's two fields are CXS varints.
185
+ *
186
+ * {@link defineSignedOperation} calls this after encoding the payload; reach
187
+ * for it directly only when the payload is already CXS bytes.
188
+ */
189
+ declare function signedOperationPreimage(preimage: SignedOperationPreimage): Uint8Array;
190
+ //#endregion
191
+ export { Operation as a, SignedOperationType as c, DefineSignedOperationOptions as i, defineSignedOperation as l, signedOperationPreimage as n, SignedOperation as o, ContractTypeSelector as r, SignedOperationRequest as s, SignedOperationPreimage as t, randomNonce as u };
192
+ //# sourceMappingURL=index--5LsCotr.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index--5LsCotr.d.ts","names":[],"sources":["../src/signedOp/operation.ts","../src/signedOp/preimage.ts"],"mappings":";;;;;;;;;AAmCA;;;;;;;;;AAakB;UAbD,SAAA;EAiBe;EAf9B,mBAAA;EAiB8B;;;;;;AAAA;AAIhC;EAZE,KAAA;EAYqC;EAVrC,IAAA,EAAM,UAAU;AAAA;;UAID,eAAA;EAAA,SACN,EAAA,EAAI,SAAA;EAAA,SACJ,SAAA,EAAW,UAAU;AAAA;;UAIf,sBAAA;EAIa;EAAA,SAFnB,OAAA,EAAS,WAAA;EAST;EAAA,SAPA,iBAAA,EAAmB,eAAA;EASb;EAAA,SAPN,iBAAA;EAOW;AAItB;;;EAJsB,SAFX,KAAA;EAeQ;EAAA,SAbR,IAAA,EAAM,KAAA;AAAA;;UAIA,mBAAA;EAcL;;;;EAAA,SATD,QAAA;EAWC;EAAA,SATD,OAAA,EAAS,eAAA;EAPiB;EASnC,UAAA,CAAW,IAAA,EAAM,KAAA,GAAQ,UAAA;EAFhB;EAIT,QAAA,CAAS,OAAA,EAAS,sBAAA,CAAuB,KAAA,IAAS,UAAA;EAFlD;EAIA,IAAA,CACE,MAAA,EAAQ,MAAA,EACR,OAAA,EAAS,sBAAA,CAAuB,KAAA,IAC/B,OAAA,CAAQ,eAAA;AAAA;;UAII,4BAAA;EATG;;;;;EAAA,SAeT,QAAA,WAAmB,eAAA;EAZ1B;;;;;;EAAA,SAmBO,QAAA,WAAmB,oBAAoB;AAAA;AAblD;;;;AAAA,UAoBiB,oBAAA;EAAA,SACN,UAAA;EAAA,SACA,KAAA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