@nockchain/rose-ts 0.1.1-alpha

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 (242) hide show
  1. package/README.md +373 -0
  2. package/dist/constants.d.ts +2 -0
  3. package/dist/constants.d.ts.map +1 -0
  4. package/dist/constants.js +2 -0
  5. package/dist/constants.js.map +1 -0
  6. package/dist/core/belt.d.ts +16 -0
  7. package/dist/core/belt.d.ts.map +1 -0
  8. package/dist/core/belt.js +120 -0
  9. package/dist/core/belt.js.map +1 -0
  10. package/dist/core/digest.d.ts +9 -0
  11. package/dist/core/digest.d.ts.map +1 -0
  12. package/dist/core/digest.js +76 -0
  13. package/dist/core/digest.js.map +1 -0
  14. package/dist/core/hashable.d.ts +21 -0
  15. package/dist/core/hashable.d.ts.map +1 -0
  16. package/dist/core/hashable.js +128 -0
  17. package/dist/core/hashable.js.map +1 -0
  18. package/dist/core/lock.d.ts +8 -0
  19. package/dist/core/lock.d.ts.map +1 -0
  20. package/dist/core/lock.js +95 -0
  21. package/dist/core/lock.js.map +1 -0
  22. package/dist/core/merkle.d.ts +7 -0
  23. package/dist/core/merkle.d.ts.map +1 -0
  24. package/dist/core/merkle.js +57 -0
  25. package/dist/core/merkle.js.map +1 -0
  26. package/dist/core/must.d.ts +3 -0
  27. package/dist/core/must.d.ts.map +1 -0
  28. package/dist/core/must.js +14 -0
  29. package/dist/core/must.js.map +1 -0
  30. package/dist/core/tip5/constants.d.ts +10 -0
  31. package/dist/core/tip5/constants.d.ts.map +1 -0
  32. package/dist/core/tip5/constants.js +70 -0
  33. package/dist/core/tip5/constants.js.map +1 -0
  34. package/dist/core/tip5/index.d.ts +5 -0
  35. package/dist/core/tip5/index.d.ts.map +1 -0
  36. package/dist/core/tip5/index.js +100 -0
  37. package/dist/core/tip5/index.js.map +1 -0
  38. package/dist/core/u256.d.ts +21 -0
  39. package/dist/core/u256.d.ts.map +1 -0
  40. package/dist/core/u256.js +96 -0
  41. package/dist/core/u256.js.map +1 -0
  42. package/dist/core/ubig.d.ts +20 -0
  43. package/dist/core/ubig.d.ts.map +1 -0
  44. package/dist/core/ubig.js +81 -0
  45. package/dist/core/ubig.js.map +1 -0
  46. package/dist/core/zbase.d.ts +11 -0
  47. package/dist/core/zbase.d.ts.map +1 -0
  48. package/dist/core/zbase.js +82 -0
  49. package/dist/core/zbase.js.map +1 -0
  50. package/dist/crypto/bpoly.d.ts +3 -0
  51. package/dist/crypto/bpoly.d.ts.map +1 -0
  52. package/dist/crypto/bpoly.js +121 -0
  53. package/dist/crypto/bpoly.js.map +1 -0
  54. package/dist/crypto/cheetah.d.ts +25 -0
  55. package/dist/crypto/cheetah.d.ts.map +1 -0
  56. package/dist/crypto/cheetah.js +250 -0
  57. package/dist/crypto/cheetah.js.map +1 -0
  58. package/dist/crypto/index.d.ts +7 -0
  59. package/dist/crypto/index.d.ts.map +1 -0
  60. package/dist/crypto/index.js +24 -0
  61. package/dist/crypto/index.js.map +1 -0
  62. package/dist/crypto/privateKey.d.ts +11 -0
  63. package/dist/crypto/privateKey.d.ts.map +1 -0
  64. package/dist/crypto/privateKey.js +88 -0
  65. package/dist/crypto/privateKey.js.map +1 -0
  66. package/dist/crypto/publicKey.d.ts +18 -0
  67. package/dist/crypto/publicKey.d.ts.map +1 -0
  68. package/dist/crypto/publicKey.js +79 -0
  69. package/dist/crypto/publicKey.js.map +1 -0
  70. package/dist/crypto/slip10.d.ts +10 -0
  71. package/dist/crypto/slip10.d.ts.map +1 -0
  72. package/dist/crypto/slip10.js +104 -0
  73. package/dist/crypto/slip10.js.map +1 -0
  74. package/dist/grpc/index.d.ts +12 -0
  75. package/dist/grpc/index.d.ts.map +1 -0
  76. package/dist/grpc/index.js +13 -0
  77. package/dist/grpc/index.js.map +1 -0
  78. package/dist/grpc/proto.d.ts +26 -0
  79. package/dist/grpc/proto.d.ts.map +1 -0
  80. package/dist/grpc/proto.js +219 -0
  81. package/dist/grpc/proto.js.map +1 -0
  82. package/dist/hash/index.d.ts +32 -0
  83. package/dist/hash/index.d.ts.map +1 -0
  84. package/dist/hash/index.js +138 -0
  85. package/dist/hash/index.js.map +1 -0
  86. package/dist/hash/note.d.ts +13 -0
  87. package/dist/hash/note.d.ts.map +1 -0
  88. package/dist/hash/note.js +78 -0
  89. package/dist/hash/note.js.map +1 -0
  90. package/dist/hash/noteData.d.ts +12 -0
  91. package/dist/hash/noteData.d.ts.map +1 -0
  92. package/dist/hash/noteData.js +115 -0
  93. package/dist/hash/noteData.js.map +1 -0
  94. package/dist/hash/noun.d.ts +4 -0
  95. package/dist/hash/noun.d.ts.map +1 -0
  96. package/dist/hash/noun.js +15 -0
  97. package/dist/hash/noun.js.map +1 -0
  98. package/dist/hash/structural.d.ts +5 -0
  99. package/dist/hash/structural.d.ts.map +1 -0
  100. package/dist/hash/structural.js +41 -0
  101. package/dist/hash/structural.js.map +1 -0
  102. package/dist/hash/tx.d.ts +15 -0
  103. package/dist/hash/tx.d.ts.map +1 -0
  104. package/dist/hash/tx.js +146 -0
  105. package/dist/hash/tx.js.map +1 -0
  106. package/dist/index.d.ts +14 -0
  107. package/dist/index.d.ts.map +1 -0
  108. package/dist/index.js +10 -0
  109. package/dist/index.js.map +1 -0
  110. package/dist/noun/belts.d.ts +9 -0
  111. package/dist/noun/belts.d.ts.map +1 -0
  112. package/dist/noun/belts.js +73 -0
  113. package/dist/noun/belts.js.map +1 -0
  114. package/dist/noun/bitwriter.d.ts +14 -0
  115. package/dist/noun/bitwriter.d.ts.map +1 -0
  116. package/dist/noun/bitwriter.js +100 -0
  117. package/dist/noun/bitwriter.js.map +1 -0
  118. package/dist/noun/codec.d.ts +9 -0
  119. package/dist/noun/codec.d.ts.map +1 -0
  120. package/dist/noun/codec.js +144 -0
  121. package/dist/noun/codec.js.map +1 -0
  122. package/dist/noun/cue.d.ts +3 -0
  123. package/dist/noun/cue.d.ts.map +1 -0
  124. package/dist/noun/cue.js +152 -0
  125. package/dist/noun/cue.js.map +1 -0
  126. package/dist/noun/encode.d.ts +12 -0
  127. package/dist/noun/encode.d.ts.map +1 -0
  128. package/dist/noun/encode.js +37 -0
  129. package/dist/noun/encode.js.map +1 -0
  130. package/dist/noun/index.d.ts +10 -0
  131. package/dist/noun/index.d.ts.map +1 -0
  132. package/dist/noun/index.js +29 -0
  133. package/dist/noun/index.js.map +1 -0
  134. package/dist/noun/jam.d.ts +3 -0
  135. package/dist/noun/jam.d.ts.map +1 -0
  136. package/dist/noun/jam.js +107 -0
  137. package/dist/noun/jam.js.map +1 -0
  138. package/dist/noun/types.d.ts +21 -0
  139. package/dist/noun/types.d.ts.map +1 -0
  140. package/dist/noun/types.js +66 -0
  141. package/dist/noun/types.js.map +1 -0
  142. package/dist/noun/words.d.ts +3 -0
  143. package/dist/noun/words.d.ts.map +1 -0
  144. package/dist/noun/words.js +6 -0
  145. package/dist/noun/words.js.map +1 -0
  146. package/dist/proto/decode.d.ts +10 -0
  147. package/dist/proto/decode.d.ts.map +1 -0
  148. package/dist/proto/decode.js +44 -0
  149. package/dist/proto/decode.js.map +1 -0
  150. package/dist/proto/digest.d.ts +21 -0
  151. package/dist/proto/digest.d.ts.map +1 -0
  152. package/dist/proto/digest.js +29 -0
  153. package/dist/proto/digest.js.map +1 -0
  154. package/dist/proto/index.d.ts +9 -0
  155. package/dist/proto/index.d.ts.map +1 -0
  156. package/dist/proto/index.js +140 -0
  157. package/dist/proto/index.js.map +1 -0
  158. package/dist/proto/note.d.ts +4 -0
  159. package/dist/proto/note.d.ts.map +1 -0
  160. package/dist/proto/note.js +99 -0
  161. package/dist/proto/note.js.map +1 -0
  162. package/dist/proto/rawTx.d.ts +3 -0
  163. package/dist/proto/rawTx.d.ts.map +1 -0
  164. package/dist/proto/rawTx.js +186 -0
  165. package/dist/proto/rawTx.js.map +1 -0
  166. package/dist/rpc/client.d.ts +13 -0
  167. package/dist/rpc/client.d.ts.map +1 -0
  168. package/dist/rpc/client.js +75 -0
  169. package/dist/rpc/client.js.map +1 -0
  170. package/dist/rpc/types.d.ts +18 -0
  171. package/dist/rpc/types.d.ts.map +1 -0
  172. package/dist/rpc/types.js +2 -0
  173. package/dist/rpc/types.js.map +1 -0
  174. package/dist/rpc/wire/encode.d.ts +4 -0
  175. package/dist/rpc/wire/encode.d.ts.map +1 -0
  176. package/dist/rpc/wire/encode.js +168 -0
  177. package/dist/rpc/wire/encode.js.map +1 -0
  178. package/dist/rpc/wire/protobuf.d.ts +10 -0
  179. package/dist/rpc/wire/protobuf.d.ts.map +1 -0
  180. package/dist/rpc/wire/protobuf.js +50 -0
  181. package/dist/rpc/wire/protobuf.js.map +1 -0
  182. package/dist/stubs.d.ts +6 -0
  183. package/dist/stubs.d.ts.map +1 -0
  184. package/dist/stubs.js +12 -0
  185. package/dist/stubs.js.map +1 -0
  186. package/dist/tx/accessors.d.ts +13 -0
  187. package/dist/tx/accessors.d.ts.map +1 -0
  188. package/dist/tx/accessors.js +65 -0
  189. package/dist/tx/accessors.js.map +1 -0
  190. package/dist/tx/builder.d.ts +63 -0
  191. package/dist/tx/builder.d.ts.map +1 -0
  192. package/dist/tx/builder.js +601 -0
  193. package/dist/tx/builder.js.map +1 -0
  194. package/dist/tx/display.d.ts +7 -0
  195. package/dist/tx/display.d.ts.map +1 -0
  196. package/dist/tx/display.js +34 -0
  197. package/dist/tx/display.js.map +1 -0
  198. package/dist/tx/fee.d.ts +8 -0
  199. package/dist/tx/fee.d.ts.map +1 -0
  200. package/dist/tx/fee.js +81 -0
  201. package/dist/tx/fee.js.map +1 -0
  202. package/dist/tx/htlc.d.ts +21 -0
  203. package/dist/tx/htlc.d.ts.map +1 -0
  204. package/dist/tx/htlc.js +65 -0
  205. package/dist/tx/htlc.js.map +1 -0
  206. package/dist/tx/index.d.ts +19 -0
  207. package/dist/tx/index.d.ts.map +1 -0
  208. package/dist/tx/index.js +64 -0
  209. package/dist/tx/index.js.map +1 -0
  210. package/dist/tx/multisig.d.ts +3 -0
  211. package/dist/tx/multisig.d.ts.map +1 -0
  212. package/dist/tx/multisig.js +8 -0
  213. package/dist/tx/multisig.js.map +1 -0
  214. package/dist/tx/outputs.d.ts +3 -0
  215. package/dist/tx/outputs.d.ts.map +1 -0
  216. package/dist/tx/outputs.js +57 -0
  217. package/dist/tx/outputs.js.map +1 -0
  218. package/dist/tx/spend.d.ts +10 -0
  219. package/dist/tx/spend.d.ts.map +1 -0
  220. package/dist/tx/spend.js +17 -0
  221. package/dist/tx/spend.js.map +1 -0
  222. package/dist/tx/spends.d.ts +8 -0
  223. package/dist/tx/spends.d.ts.map +1 -0
  224. package/dist/tx/spends.js +48 -0
  225. package/dist/tx/spends.js.map +1 -0
  226. package/dist/tx/types.d.ts +5 -0
  227. package/dist/tx/types.d.ts.map +1 -0
  228. package/dist/tx/types.js +2 -0
  229. package/dist/tx/types.js.map +1 -0
  230. package/dist/tx/unlocks.d.ts +4 -0
  231. package/dist/tx/unlocks.d.ts.map +1 -0
  232. package/dist/tx/unlocks.js +49 -0
  233. package/dist/tx/unlocks.js.map +1 -0
  234. package/dist/tx/witness.d.ts +14 -0
  235. package/dist/tx/witness.d.ts.map +1 -0
  236. package/dist/tx/witness.js +81 -0
  237. package/dist/tx/witness.js.map +1 -0
  238. package/dist/types.d.ts +311 -0
  239. package/dist/types.d.ts.map +1 -0
  240. package/dist/types.js +2 -0
  241. package/dist/types.js.map +1 -0
  242. package/package.json +45 -0
@@ -0,0 +1,78 @@
1
+ import { buildZTree, hashZNode } from "../core/zbase.js";
2
+ import { hashBool, hashNicks, hashPair, hashString, hashToDigest, hashTuple, hashU64, } from "../core/hashable.js";
3
+ import { hashNameBelts } from "./tx.js";
4
+ import { digestFromBase58 } from "../core/digest.js";
5
+ import { hashNounStructural } from "./structural.js";
6
+ import { encodePkh } from "../noun/codec.js";
7
+ import { encodeAtomU64, encodeTuple } from "../noun/encode.js";
8
+ import { cons, fromWire, toWire } from "../noun/types.js";
9
+ import { tasBelts } from "../noun/belts.js";
10
+ import { nounWords } from "../noun/words.js";
11
+ function hashNounWire(noun) {
12
+ return digestFromBase58(hashNounStructural(fromWire(noun)));
13
+ }
14
+ export function hashNoteData(data) {
15
+ if (data.length === 0)
16
+ return hashU64(0n);
17
+ const tree = buildZTree(data.map(([key, noun]) => ({ key, noun })), (e) => e.key, (k) => tasBelts(k));
18
+ return hashZNode(tree, (e) => hashPair(hashString(e.key), hashNounWire(e.noun)));
19
+ }
20
+ export function noteDataFeeWords(data) {
21
+ let w = 1n;
22
+ for (const [, noun] of data) {
23
+ w += 1n + nounWords(fromWire(noun));
24
+ }
25
+ return w;
26
+ }
27
+ export function noteDataPushPkh(data, pkh) {
28
+ const filtered = data.filter(([k]) => k !== "lock");
29
+ const noun = toWire(encodeTuple([encodeAtomU64(0n), cons(tasBelts("pkh"), encodePkh(pkh)), encodeAtomU64(0n)]));
30
+ return [...filtered, ["lock", noun]];
31
+ }
32
+ export function noteDataPushLock(data, lockNoun) {
33
+ const filtered = data.filter(([k]) => k !== "lock");
34
+ return [...filtered, ["lock", toWire(encodeTuple([encodeAtomU64(0n), fromWire(lockNoun)]))]];
35
+ }
36
+ export { noteDataPushMemo, noteDataPushBlob, decodeNoteDataPackedUtf8, decodePackedBlobUtf8, encodeBlobBelts, MAX_MEMO_UTF8_BYTES, MAX_BLOB_UTF8_BYTES, NOTE_DATA_KEY_MEMO, NOTE_DATA_KEY_BLOB, } from "./noteData.js";
37
+ function hashDigestField(d) {
38
+ return digestFromBase58(d);
39
+ }
40
+ function isHashSource(source) {
41
+ return "hash" in source;
42
+ }
43
+ export function hashSourceFields(source) {
44
+ if (!isHashSource(source)) {
45
+ throw new Error("Parent source variant is not hashable as legacy Source");
46
+ }
47
+ return hashToDigest(hashTuple(hashDigestField(source.hash), hashBool(source.is_coinbase)));
48
+ }
49
+ export function nameHash(name) {
50
+ return hashToDigest(hashNameBelts(name));
51
+ }
52
+ export function nameV1(lock, source) {
53
+ const first = hashToDigest(hashTuple(hashBool(true), hashDigestField(lock)));
54
+ const sourceHashed = hashSourceFields(source);
55
+ const last = hashToDigest(hashTuple(hashBool(true), hashTuple(hashDigestField(sourceHashed), hashU64(0n))));
56
+ return { first, last, _sig: 0 };
57
+ }
58
+ function hashNoteV1(note) {
59
+ return hashToDigest(hashTuple(hashU64(BigInt(note.version)), hashTuple(hashU64(BigInt(note.origin_page)), hashTuple(hashNameBelts(note.name), hashTuple(hashNoteData(note.note_data), hashNicks(note.assets))))));
60
+ }
61
+ function hashNoteV0(note) {
62
+ const inner = note.inner;
63
+ const tim = inner.timelock?.tim ?? null;
64
+ const timHash = tim === null ? hashU64(0n) : hashU64(1n);
65
+ const innerHash = hashTuple(hashU64(BigInt(inner.version)), hashTuple(hashU64(BigInt(inner.origin_page)), timHash));
66
+ const sig = note.sig;
67
+ const sigHash = hashU64(0n);
68
+ void sig;
69
+ const sourceHash = hashTuple(hashDigestField(note.source.hash), hashBool(note.source.is_coinbase));
70
+ return hashToDigest(hashTuple(innerHash, hashTuple(hashNameBelts(note.name), hashTuple(sigHash, hashTuple(sourceHash, hashNicks(note.assets))))));
71
+ }
72
+ export function noteHash(note) {
73
+ if ("version" in note && "note_data" in note) {
74
+ return hashNoteV1(note);
75
+ }
76
+ return hashNoteV0(note);
77
+ }
78
+ //# sourceMappingURL=note.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"note.js","sourceRoot":"","sources":["../../src/hash/note.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EACL,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,SAAS,EACT,OAAO,GACR,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7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+ export declare const MAX_MEMO_UTF8_BYTES = 2048;
3
+ export declare const MAX_BLOB_UTF8_BYTES: number;
4
+ export declare const NOTE_DATA_KEY_MEMO = "memo";
5
+ export declare const NOTE_DATA_KEY_BLOB = "blob";
6
+ export declare function encodeBlobBelts(bytes: Uint8Array): bigint[];
7
+ export declare function decodeLenPrefixedBlob(belts: readonly bigint[]): Uint8Array | null;
8
+ export declare function noteDataPushMemo(data: NoteData, memoUtf8: string): NoteData;
9
+ export declare function noteDataPushBlob(data: NoteData, blobUtf8: string): NoteData;
10
+ export declare function decodePackedBlobUtf8(jamBytes: Uint8Array): string | null;
11
+ export declare function decodeNoteDataPackedUtf8(noun: Noun): string | null;
12
+ //# sourceMappingURL=noteData.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"noteData.d.ts","sourceRoot":"","sources":["../../src/hash/noteData.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAElD,eAAO,MAAM,mBAAmB,OAAO,CAAC;AACxC,eAAO,MAAM,mBAAmB,QAAa,CAAC;AAC9C,eAAO,MAAM,kBAAkB,SAAS,CAAC;AACzC,eAAO,MAAM,kBAAkB,SAAS,CAAC;AAGzC,wBAAgB,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,EAAE,CAW3D;AAkCD,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,UAAU,GAAG,IAAI,CAYjF;AAWD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,GAAG,QAAQ,CAS3E;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,GAAG,QAAQ,CAQ3E;AAGD,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,UAAU,GAAG,MAAM,GAAG,IAAI,CAUxE;AAGD,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,CAElE"}
@@ -0,0 +1,115 @@
1
+ import { mustAt } from "../core/must.js";
2
+ import { vecToNoun } from "../noun/belts.js";
3
+ import { cue } from "../noun/cue.js";
4
+ import { jam } from "../noun/jam.js";
5
+ import { fromWire, toWire } from "../noun/types.js";
6
+ export const MAX_MEMO_UTF8_BYTES = 2048;
7
+ export const MAX_BLOB_UTF8_BYTES = 256 * 1024;
8
+ export const NOTE_DATA_KEY_MEMO = "memo";
9
+ export const NOTE_DATA_KEY_BLOB = "blob";
10
+ export function encodeBlobBelts(bytes) {
11
+ const belts = [BigInt(bytes.length)];
12
+ for (let i = 0; i < bytes.length; i += 4) {
13
+ let v = 0n;
14
+ const end = Math.min(i + 4, bytes.length);
15
+ for (let j = i; j < end; j++) {
16
+ v |= BigInt(mustAt(bytes, j)) << BigInt((j - i) * 8);
17
+ }
18
+ belts.push(v);
19
+ }
20
+ return belts;
21
+ }
22
+ function beltSeqFromPackedNoun(noun) {
23
+ const belts = [];
24
+ let current = noun;
25
+ while (current.tag === "cell") {
26
+ const head = current.head;
27
+ if (head.tag !== "atom")
28
+ throw new Error("expected atom belt");
29
+ const v = head.value.tryIntoU64();
30
+ if (v === null)
31
+ throw new Error("belt atom too large");
32
+ belts.push(v);
33
+ current = current.tail;
34
+ }
35
+ if (current.tag !== "atom")
36
+ throw new Error("expected atom terminator");
37
+ const last = current.value.tryIntoU64();
38
+ if (last === null)
39
+ throw new Error("belt atom too large");
40
+ belts.push(last);
41
+ return belts;
42
+ }
43
+ function normalizePackedBlobBelts(belts) {
44
+ if (belts.length === 0)
45
+ return null;
46
+ const byteLen = Number(belts[0]);
47
+ if (!Number.isFinite(byteLen) || byteLen < 0 || byteLen > MAX_BLOB_UTF8_BYTES)
48
+ return null;
49
+ const expectedBelts = 1 + Math.ceil(byteLen / 4);
50
+ if (belts.length === expectedBelts)
51
+ return [...belts];
52
+ if (belts.length === expectedBelts + 1 && belts[belts.length - 1] === 0n) {
53
+ return belts.slice(0, -1);
54
+ }
55
+ return null;
56
+ }
57
+ export function decodeLenPrefixedBlob(belts) {
58
+ const normalized = normalizePackedBlobBelts(belts);
59
+ if (!normalized)
60
+ return null;
61
+ const byteLen = Number(normalized[0]);
62
+ const body = [];
63
+ for (let i = 1; i < normalized.length; i++) {
64
+ const w = mustAt(normalized, i);
65
+ for (let j = 0; j < 4; j++) {
66
+ body.push(Number((w >> BigInt(j * 8)) & 0xffn));
67
+ }
68
+ }
69
+ return new Uint8Array(body.slice(0, byteLen));
70
+ }
71
+ function packedBlobNoun(bytes) {
72
+ return toWire(vecToNoun(encodeBlobBelts(bytes)));
73
+ }
74
+ function pushEntry(data, key, noun) {
75
+ const filtered = data.filter(([k]) => k !== key);
76
+ return [...filtered, [key, noun]];
77
+ }
78
+ export function noteDataPushMemo(data, memoUtf8) {
79
+ const bytes = new TextEncoder().encode(memoUtf8);
80
+ if (bytes.length === 0) {
81
+ throw new Error("Memo cannot be empty. Omit the memo field instead.");
82
+ }
83
+ if (bytes.length > MAX_MEMO_UTF8_BYTES) {
84
+ throw new Error(`Memo too large: ${bytes.length} UTF-8 bytes (max ${MAX_MEMO_UTF8_BYTES})`);
85
+ }
86
+ return pushEntry(data, NOTE_DATA_KEY_MEMO, packedBlobNoun(bytes));
87
+ }
88
+ export function noteDataPushBlob(data, blobUtf8) {
89
+ const trimmed = blobUtf8.trim();
90
+ if (!trimmed)
91
+ return data;
92
+ const bytes = new TextEncoder().encode(trimmed);
93
+ if (bytes.length > MAX_BLOB_UTF8_BYTES) {
94
+ throw new Error(`blob exceeds max size (${MAX_BLOB_UTF8_BYTES} UTF-8 bytes)`);
95
+ }
96
+ return pushEntry(data, NOTE_DATA_KEY_BLOB, packedBlobNoun(bytes));
97
+ }
98
+ export function decodePackedBlobUtf8(jamBytes) {
99
+ const tree = cue(jamBytes);
100
+ if (!tree)
101
+ return null;
102
+ const decoded = decodeLenPrefixedBlob(beltSeqFromPackedNoun(tree));
103
+ if (!decoded)
104
+ return null;
105
+ try {
106
+ return new TextDecoder().decode(decoded);
107
+ }
108
+ catch {
109
+ return null;
110
+ }
111
+ }
112
+ export function decodeNoteDataPackedUtf8(noun) {
113
+ return decodePackedBlobUtf8(jam(fromWire(noun)));
114
+ }
115
+ //# sourceMappingURL=noteData.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"noteData.js","sourceRoot":"","sources":["../../src/hash/noteData.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAiB,MAAM,kBAAkB,CAAC;AAGnE,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,CAAC;AACxC,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,GAAG,IAAI,CAAC;AAC9C,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC;AACzC,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAGzC,MAAM,UAAU,eAAe,CAAC,KAAiB;IAC/C,MAAM,KAAK,GAAa,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IAC/C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QACzC,IAAI,CAAC,GAAG,EAAE,CAAC;QACX,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;QAC1C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;YAC7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IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAChD,IAAI,KAAK,CAAC,MAAM,GAAG,mBAAmB,EAAE,CAAC;QACvC,MAAM,IAAI,KAAK,CAAC,0BAA0B,mBAAmB,eAAe,CAAC,CAAC;IAChF,CAAC;IACD,OAAO,SAAS,CAAC,IAAI,EAAE,kBAAkB,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;AACpE,CAAC;AAGD,MAAM,UAAU,oBAAoB,CAAC,QAAoB;IACvD,MAAM,IAAI,GAAG,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC3B,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IACvB,MAAM,OAAO,GAAG,qBAAqB,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC,CAAC;IACnE,IAAI,CAAC,OAAO;QAAE,OAAO,IAAI,CAAC;IAC1B,IAAI,CAAC;QACH,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC3C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAGD,MAAM,UAAU,wBAAwB,CAAC,IAAU;IACjD,OAAO,oBAAoB,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACnD,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { Digest } from "../types.js";
2
+ export declare function hashNoun(nounJam: Uint8Array): Digest;
3
+ export declare function hashStructuredNoun(nounJam: Uint8Array): Digest;
4
+ //# sourceMappingURL=noun.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"noun.d.ts","sourceRoot":"","sources":["../../src/hash/noun.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAK1C,wBAAgB,QAAQ,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,CAIpD;AAGD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,CAI9D"}
@@ -0,0 +1,15 @@
1
+ import { cue as cueTree } from "../noun/cue.js";
2
+ import { hashNounStructural, hashNounWhole } from "./structural.js";
3
+ export function hashNoun(nounJam) {
4
+ const tree = cueTree(nounJam);
5
+ if (!tree)
6
+ throw new Error("unable to cue noun jam");
7
+ return hashNounWhole(tree);
8
+ }
9
+ export function hashStructuredNoun(nounJam) {
10
+ const tree = cueTree(nounJam);
11
+ if (!tree)
12
+ throw new Error("unable to cue noun jam");
13
+ return hashNounStructural(tree);
14
+ }
15
+ //# sourceMappingURL=noun.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"noun.js","sourceRoot":"","sources":["../../src/hash/noun.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,IAAI,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGpE,MAAM,UAAU,QAAQ,CAAC,OAAmB;IAC1C,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9B,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IACrD,OAAO,aAAa,CAAC,IAAI,CAAW,CAAC;AACvC,CAAC;AAGD,MAAM,UAAU,kBAAkB,CAAC,OAAmB;IACpD,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9B,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IACrD,OAAO,kBAAkB,CAAC,IAAI,CAAW,CAAC;AAC5C,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { NounTree } from "../noun/types.js";
2
+ export declare function hashNounStructural(noun: NounTree): string;
3
+ export declare function hashNounWholeBelts(noun: NounTree): bigint[];
4
+ export declare function hashNounWhole(noun: NounTree): string;
5
+ //# sourceMappingURL=structural.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"structural.d.ts","sourceRoot":"","sources":["../../src/hash/structural.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAajD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,CAEzD;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,EAAE,CAoB3D;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,CAEpD"}
@@ -0,0 +1,41 @@
1
+ import { hashFixed, hashVarlen } from "../core/tip5/index.js";
2
+ import { digestFromBelts, digestToBase58 } from "../core/digest.js";
3
+ function structuralDigestBelts(noun) {
4
+ if (noun.tag === "atom") {
5
+ const v = noun.value.tryIntoU64();
6
+ if (v === null)
7
+ throw new Error("atom too large for structural hash");
8
+ return hashVarlen([1n, v]);
9
+ }
10
+ const l = structuralDigestBelts(noun.head);
11
+ const r = structuralDigestBelts(noun.tail);
12
+ return hashFixed([...l, ...r]);
13
+ }
14
+ export function hashNounStructural(noun) {
15
+ return digestToBase58(digestFromBelts(structuralDigestBelts(noun)));
16
+ }
17
+ export function hashNounWholeBelts(noun) {
18
+ const leaves = [];
19
+ const dyck = [];
20
+ function visit(n) {
21
+ if (n.tag === "atom") {
22
+ const v = n.value.tryIntoU64();
23
+ if (v === null)
24
+ throw new Error("atom too large");
25
+ leaves.push(v);
26
+ }
27
+ else {
28
+ dyck.push(0n);
29
+ visit(n.head);
30
+ dyck.push(1n);
31
+ visit(n.tail);
32
+ }
33
+ }
34
+ visit(noun);
35
+ const combined = [BigInt(leaves.length), ...leaves, ...dyck];
36
+ return hashVarlen(combined);
37
+ }
38
+ export function hashNounWhole(noun) {
39
+ return digestToBase58(digestFromBelts(hashNounWholeBelts(noun)));
40
+ }
41
+ //# sourceMappingURL=structural.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"structural.js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AAC,CAAC;QACjB,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACd,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;YACd,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACd,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAChB,CAAC;IACH,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,CAAC;IACZ,MAAM,QAAQ,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;IAC7D,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC;AAC9B,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,IAAc;IAC1C,OAAO,cAAc,CAAC,eAAe,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACnE,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { Digest, LockMerkleProof, Name, PkhSignature, RawTxV1, SeedV1, Spend1V1, SpendsV1, Witness } from "../types.js";
2
+ import type { DigestBelts } from "../core/digest.js";
3
+ export declare function hashNameBelts(name: Name): DigestBelts;
4
+ export declare function hashName(name: Name): Digest;
5
+ export declare function hashLockMerkleProofDigest(lmp: LockMerkleProof): Digest;
6
+ export declare function hashSeedV1Digest(seed: SeedV1): Digest;
7
+ export declare function hashSeedV1(seed: SeedV1): DigestBelts;
8
+ export declare function seedsV1SigHash(seeds: SeedV1[]): Digest;
9
+ export declare function hashSeedsV1Digest(seeds: SeedV1[]): Digest;
10
+ export declare function hashWitnessDigest(w: Witness): Digest;
11
+ export declare function hashPkhSignatureDigest(sig: PkhSignature): Digest;
12
+ export declare function hashSpendV1SigHash(spend: Spend1V1): Digest;
13
+ export declare function hashSpendsV1(spends: SpendsV1): Digest;
14
+ export declare function rawTxV1CalcId(tx: RawTxV1): Digest;
15
+ //# sourceMappingURL=tx.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tx.d.ts","sourceRoot":"","sources":["../../src/hash/tx.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EACV,MAAM,EACN,eAAe,EAGf,IAAI,EAEJ,YAAY,EACZ,OAAO,EACP,MAAM,EAEN,QAAQ,EAGR,QAAQ,EACR,OAAO,EACR,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAgDrD,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,GAAG,WAAW,CAMrD;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAE3C;AAUD,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,eAAe,GAAG,MAAM,CAEtE;AAkCD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAErD;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAOpD;AA+BD,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAEtD;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAEzD;AAyBD,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAEpD;AAED,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAEhE;AAOD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM,CAG1D;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,QAAQ,GAAG,MAAM,CAUrD;AAED,wBAAgB,aAAa,CAAC,EAAE,EAAE,OAAO,GAAG,MAAM,CAEjD"}
@@ -0,0 +1,146 @@
1
+ import { mustAt } from "../core/must.js";
2
+ import { digestFromBase58 } from "../core/digest.js";
3
+ import { hashBool, hashLockPrimitive, hashLockRoot, hashNicks, hashPair, hashString, hashToDigest, hashTuple, hashU64, } from "../core/hashable.js";
4
+ import { buildZTree, hashZNode } from "../core/zbase.js";
5
+ import { cheetahPointFromBase58, cheetahPointHash } from "../crypto/cheetah.js";
6
+ import { U256 } from "../core/u256.js";
7
+ import { encodeAtomU64, encodeBeltSeq, encodeDigest, encodeName, encodeTuple, } from "../noun/encode.js";
8
+ import { hashNounWhole } from "./structural.js";
9
+ import { hashNoteData as hashNoteDataEntries } from "./note.js";
10
+ const AXIS_MOLD_HASH = "6mhCSwJQDvbkbiPAUNjetJtVoo1VLtEhmEYoU4hmdGd6ep1F6ayaV4A";
11
+ function hashDigest(d) {
12
+ return digestFromBase58(d);
13
+ }
14
+ function hashNested(...parts) {
15
+ if (parts.length === 0)
16
+ return hashU64(0n);
17
+ if (parts.length === 1)
18
+ return mustAt(parts, 0);
19
+ let acc = mustAt(parts, parts.length - 1);
20
+ for (let i = parts.length - 2; i >= 0; i--) {
21
+ acc = hashPair(mustAt(parts, i), acc);
22
+ }
23
+ return acc;
24
+ }
25
+ function hashVec(items, hashItem) {
26
+ if (items.length === 0)
27
+ return hashU64(0n);
28
+ return hashPair(hashItem(mustAt(items, 0)), hashVec(items.slice(1), hashItem));
29
+ }
30
+ function beltsFromLeBytes(bytes) {
31
+ const belts = [];
32
+ for (let i = 0; i < bytes.length; i += 4) {
33
+ const chunk = bytes.subarray(i, Math.min(i + 4, bytes.length));
34
+ let v = 0n;
35
+ for (let j = 0; j < chunk.length; j++) {
36
+ v |= BigInt(mustAt(chunk, j)) << BigInt(j * 8);
37
+ }
38
+ belts.push(v);
39
+ }
40
+ return belts;
41
+ }
42
+ function hashSignature(sig) {
43
+ const c = beltsFromLeBytes(U256.fromLeHex(sig.c).toLeBytes());
44
+ const s = beltsFromLeBytes(U256.fromLeHex(sig.s).toLeBytes());
45
+ const noun = encodeTuple([encodeBeltSeq(c), encodeBeltSeq(s)]);
46
+ return digestFromBase58(hashNounWhole(noun));
47
+ }
48
+ function hashPublicKeyDigest(pk) {
49
+ return digestFromBase58(cheetahPointHash(cheetahPointFromBase58(pk)));
50
+ }
51
+ export function hashNameBelts(name) {
52
+ return hashNested(hashDigest(name.first), hashDigest(name.last), hashU64(BigInt(name._sig ?? 0)));
53
+ }
54
+ export function hashName(name) {
55
+ return hashToDigest(hashNameBelts(name));
56
+ }
57
+ function hashSpendConditionVec(sc) {
58
+ return hashVec(sc, hashLockPrimitive);
59
+ }
60
+ function hashMerkleProof(proof) {
61
+ return hashNested(hashDigest(proof.root), hashVec(proof.path, hashDigest));
62
+ }
63
+ export function hashLockMerkleProofDigest(lmp) {
64
+ return hashToDigest(hashLockMerkleProof(lmp));
65
+ }
66
+ function hashLockMerkleProof(lmp) {
67
+ if ("version" in lmp && lmp.version === "full") {
68
+ return hashNested(hashString("full"), hashSpendConditionVec(lmp.spend_condition), hashU64(BigInt(lmp.axis)), hashMerkleProof(lmp.proof));
69
+ }
70
+ return hashNested(hashSpendConditionVec(lmp.spend_condition), hashDigest(AXIS_MOLD_HASH), hashMerkleProof(lmp.proof));
71
+ }
72
+ function hashNoteData(data) {
73
+ return hashNoteDataEntries(data);
74
+ }
75
+ function encodeSeedNoun(seed) {
76
+ const lockRoot = typeof seed.lock_root === "string" ? encodeDigest(seed.lock_root) : encodeAtomU64(0n);
77
+ return encodeTuple([
78
+ encodeAtomU64(0n),
79
+ lockRoot,
80
+ encodeAtomU64(0n),
81
+ encodeAtomU64(BigInt(seed.gift)),
82
+ encodeDigest(seed.parent_hash),
83
+ ]);
84
+ }
85
+ export function hashSeedV1Digest(seed) {
86
+ return hashToDigest(hashSeedV1(seed));
87
+ }
88
+ export function hashSeedV1(seed) {
89
+ return hashNested(hashLockRoot(seed.lock_root), hashNoteData(seed.note_data), hashNicks(seed.gift), hashDigest(seed.parent_hash));
90
+ }
91
+ function hashSeedsV1(seeds) {
92
+ const tree = buildZTree(seeds, (s) => s, encodeSeedNoun);
93
+ return hashZNode(tree, hashSeedV1);
94
+ }
95
+ function hashOutputSource(source) {
96
+ if (source === null)
97
+ return hashU64(0n);
98
+ if (!("hash" in source)) {
99
+ throw new Error("Parent source variant is not hashable as legacy Source");
100
+ }
101
+ return hashTuple(hashU64(0n), hashTuple(hashDigest(source.hash), hashBool(source.is_coinbase)));
102
+ }
103
+ function hashSigHashSeedV1(seed) {
104
+ return hashNested(hashOutputSource(seed.output_source), hashLockRoot(seed.lock_root), hashNoteData(seed.note_data), hashNicks(seed.gift), hashDigest(seed.parent_hash));
105
+ }
106
+ function hashSeedsV1Sig(seeds) {
107
+ const tree = buildZTree(seeds, (s) => s, encodeSeedNoun);
108
+ return hashZNode(tree, hashSigHashSeedV1);
109
+ }
110
+ export function seedsV1SigHash(seeds) {
111
+ return hashToDigest(hashSeedsV1Sig(seeds));
112
+ }
113
+ export function hashSeedsV1Digest(seeds) {
114
+ return hashToDigest(hashSeedsV1(seeds));
115
+ }
116
+ function hashPkhSignature(sig) {
117
+ const pairs = Array.isArray(sig) ? sig : [];
118
+ const tree = buildZTree(pairs.map(([key, value]) => ({ key, value })), (e) => e.key, encodeDigest);
119
+ return hashZNode(tree, (e) => hashNested(hashDigest(e.key), hashPublicKeyDigest(e.value[0]), hashSignature(e.value[1])));
120
+ }
121
+ function hashWitnessBelts(w) {
122
+ return hashNested(hashLockMerkleProof(w.lock_merkle_proof), hashPkhSignature(w.pkh_signature), hashU64(0n), hashU64(0n));
123
+ }
124
+ export function hashWitnessDigest(w) {
125
+ return hashToDigest(hashWitnessBelts(w));
126
+ }
127
+ export function hashPkhSignatureDigest(sig) {
128
+ return hashToDigest(hashPkhSignature(sig));
129
+ }
130
+ function hashSpend1(spend) {
131
+ const seeds = Array.isArray(spend.seeds) ? spend.seeds : [];
132
+ return hashNested(hashU64(1n), hashWitnessBelts(spend.witness), hashSeedsV1(seeds), hashNicks(spend.fee));
133
+ }
134
+ export function hashSpendV1SigHash(spend) {
135
+ const seeds = Array.isArray(spend.seeds) ? spend.seeds : [];
136
+ return hashToDigest(hashTuple(hashSeedsV1Sig(seeds), hashNicks(spend.fee)));
137
+ }
138
+ export function hashSpendsV1(spends) {
139
+ const pairs = spends;
140
+ const tree = buildZTree(pairs.map(([name, spend]) => ({ name, spend })), (e) => e.name, encodeName);
141
+ return hashToDigest(hashZNode(tree, (e) => hashNested(hashNameBelts(e.name), hashSpend1(e.spend))));
142
+ }
143
+ export function rawTxV1CalcId(tx) {
144
+ return hashToDigest(hashPair(hashU64(1n), digestFromBase58(hashSpendsV1(tx.spends))));
145
+ }
146
+ //# sourceMappingURL=tx.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tx.js","sourceRoot":"","sources":["../../src/hash/tx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EACL,QAAQ,EACR,iBAAiB,EACjB,YAAY,EACZ,SAAS,EACT,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,SAAS,EACT,OAAO,GACR,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAChF,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EACL,aAAa,EACb,aAAa,EACb,YAAY,EACZ,UAAU,EACV,WAAW,GACZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,YAAY,IAAI,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAoBhE,MAAM,cAAc,GAClB,yDAAmE,CAAC;AAEtE,SAAS,UAAU,CAAC,CAAS;IAC3B,OAAO,gBAAgB,CAAC,CAAC,CAAC,CAAC;AAC7B,CAAC;AAED,SAAS,UAAU,CAAC,GAAG,KAAoB;IACzC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAA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AAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,EAC/C,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EACb,UAAU,CACX,CAAC;IACF,OAAO,YAAY,CACjB,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,KAAiB,CAAC,CAAC,CAAC,CAC3F,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,EAAW;IACvC,OAAO,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,gBAAgB,CAAC,YAAY,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AACxF,CAAC"}
@@ -0,0 +1,14 @@
1
+ export { DEFAULT_FEE_PER_WORD } from "./constants.js";
2
+ export { NotImplementedError } from "./stubs.js";
3
+ export type { Digest, PbCom2RawTransaction, Hax, Lock, LockPrimitive, LockRoot, LockTim, MissingUnlocks, Name, Nicks, NockchainTx, Note, NoteData, NoteV1, Pkh, RawTxV1, SeedV1, Signature, Source, SpendCondition, TxEngineSettings, TxLock, Witness, } from "./types.js";
4
+ export type { Balance, BalanceEntry } from "./rpc/types.js";
5
+ export type { OutputNoteData } from "./tx/types.js";
6
+ export type { SimpleSpendLockOptions } from "./tx/builder.js";
7
+ export { jam, cue, tas, untas, tasBelts, atomToBelts, beltsToAtom } from "./noun/index.js";
8
+ export { deriveMasterKey, deriveMasterKeyFromMnemonic, ExtendedKey, hashPublicKey, PrivateKey, PublicKey, publicKeyFromBeBytes, publicKeyFromHex, publicKeyToHex, publicKeyVerify, signMessage, verifySignature, } from "./crypto/index.js";
9
+ export { hashPreimage, hashNoun, hashStructuredNoun, hashU64, pkhSingle, pkhNew, pkhHash, haxHash, haxHashPreimage, spendConditionNewPkh, spendConditionPkh, spendConditionHax, spendConditionTim, spendConditionBrn, spendConditionFirstName, spendConditionHash, lockFromList, lockFromListBurnpad, lockRootHash, lockHash, lockHeight, lockProve, noteDataEmpty, noteDataPushPkh, noteDataPushLock, noteDataPushMemo, noteDataPushBlob, decodeNoteDataPackedUtf8, decodePackedBlobUtf8, noteHash, nameV1, nameHash, hashName, hashSeedV1Digest, hashSeedsV1Digest, hashSpendV1SigHash, hashWitnessDigest, hashPkhSignatureDigest, hashSpendsV1, hashLockMerkleProofDigest, seedV1NewSinglePkh, } from "./hash/index.js";
10
+ export { TxBuilder, SpendBuilder, txEngineSettingsV1Default, txEngineSettingsV1BythosDefault, nockchainTxToRawTx, rawTxV1ToNockchainTx, rawTxV1New, rawTxV1Version, rawTxV1InputNames, rawTxV1InputSpendConditions, spendV1NewWitness, spendV1NewLegacy, spendV1SigHash, nockchainTxOutputs, rawTxV1Outputs, rawTxTotalFees, rawTxV1CalcId, spendV1Fee, spendV1TotalGifts, spendV1UnclampedFee, spendsV1Fee, spendsV1TotalFees, spendsV1TotalGifts, spendsV1UnclampedFee, spendsV1ApplyWitness, witnessFromLock, witnessNew, lockMerkleProofFromLock, witnessFromLockMerkleProof, witnessClearSignatures, witnessWithPkhSignature, witnessWithHaxPreimage, spendV1FromLock, multisigLock, giftOutputFirstNameFromLockOutputs, htlcGiftOutputFirstName, htlcOrLock, htlcLockRootDigest, } from "./tx/index.js";
11
+ export { RpcClient } from "./rpc/client.js";
12
+ export { GrpcClient } from "./grpc/index.js";
13
+ export { noteFromProtobuf, noteToProtobuf, spendConditionFromProtobuf, spendConditionToProtobuf, digestFromProtobuf, digestToProtobuf, rawTxFromProtobuf, rawTxToProtobuf, } from "./proto/index.js";
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBA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,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,sBAAsB,EACtB,YAAY,EACZ,yBAAyB,EACzB,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,SAAS,EACT,YAAY,EACZ,yBAAyB,EACzB,+BAA+B,EAC/B,kBAAkB,EAClB,oBAAoB,EACpB,UAAU,EACV,cAAc,EACd,iBAAiB,EACjB,2BAA2B,EAC3B,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,cAAc,EACd,aAAa,EACb,UAAU,EACV,iBAAiB,EACjB,mBAAmB,EACnB,WAAW,EACX,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,eAAe,EACf,UAAU,EACV,uBAAuB,EACvB,0BAA0B,EAC1B,sBAAsB,EACtB,uBAAuB,EACvB,sBAAsB,EACtB,eAAe,EACf,YAAY,EACZ,kCAAkC,EAClC,uBAAuB,EACvB,UAAU,EACV,kBAAkB,GACnB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,0BAA0B,EAC1B,wBAAwB,EACxB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,GAChB,MAAM,kBAAkB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ export { DEFAULT_FEE_PER_WORD } from "./constants.js";
2
+ export { NotImplementedError } from "./stubs.js";
3
+ export { jam, cue, tas, untas, tasBelts, atomToBelts, beltsToAtom } from "./noun/index.js";
4
+ export { deriveMasterKey, deriveMasterKeyFromMnemonic, ExtendedKey, hashPublicKey, PrivateKey, PublicKey, publicKeyFromBeBytes, publicKeyFromHex, publicKeyToHex, publicKeyVerify, signMessage, verifySignature, } from "./crypto/index.js";
5
+ export { hashPreimage, hashNoun, hashStructuredNoun, hashU64, pkhSingle, pkhNew, pkhHash, haxHash, haxHashPreimage, spendConditionNewPkh, spendConditionPkh, spendConditionHax, spendConditionTim, spendConditionBrn, spendConditionFirstName, spendConditionHash, lockFromList, lockFromListBurnpad, lockRootHash, lockHash, lockHeight, lockProve, noteDataEmpty, noteDataPushPkh, noteDataPushLock, noteDataPushMemo, noteDataPushBlob, decodeNoteDataPackedUtf8, decodePackedBlobUtf8, noteHash, nameV1, nameHash, hashName, hashSeedV1Digest, hashSeedsV1Digest, hashSpendV1SigHash, hashWitnessDigest, hashPkhSignatureDigest, hashSpendsV1, hashLockMerkleProofDigest, seedV1NewSinglePkh, } from "./hash/index.js";
6
+ export { TxBuilder, SpendBuilder, txEngineSettingsV1Default, txEngineSettingsV1BythosDefault, nockchainTxToRawTx, rawTxV1ToNockchainTx, rawTxV1New, rawTxV1Version, rawTxV1InputNames, rawTxV1InputSpendConditions, spendV1NewWitness, spendV1NewLegacy, spendV1SigHash, nockchainTxOutputs, rawTxV1Outputs, rawTxTotalFees, rawTxV1CalcId, spendV1Fee, spendV1TotalGifts, spendV1UnclampedFee, spendsV1Fee, spendsV1TotalFees, spendsV1TotalGifts, spendsV1UnclampedFee, spendsV1ApplyWitness, witnessFromLock, witnessNew, lockMerkleProofFromLock, witnessFromLockMerkleProof, witnessClearSignatures, witnessWithPkhSignature, witnessWithHaxPreimage, spendV1FromLock, multisigLock, giftOutputFirstNameFromLockOutputs, htlcGiftOutputFirstName, htlcOrLock, htlcLockRootDigest, } from "./tx/index.js";
7
+ export { RpcClient } from "./rpc/client.js";
8
+ export { GrpcClient } from "./grpc/index.js";
9
+ export { noteFromProtobuf, noteToProtobuf, spendConditionFromProtobuf, spendConditionToProtobuf, digestFromProtobuf, digestToProtobuf, rawTxFromProtobuf, rawTxToProtobuf, } from "./proto/index.js";
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAgCjD,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC3F,OAAO,EACL,eAAe,EACf,2BAA2B,EAC3B,WAAW,EACX,aAAa,EACb,UAAU,EACV,SAAS,EACT,oBAAoB,EACpB,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,WAAW,EACX,eAAe,GAChB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,YAAY,EACZ,QAAQ,EACR,kBAAkB,EAClB,OAAO,EACP,SAAS,EACT,MAAM,EACN,OAAO,EACP,OAAO,EACP,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,uBAAuB,EACvB,kBAAkB,EAClB,YAAY,EACZ,mBAAmB,EACnB,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,SAAS,EACT,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,wBAAwB,EACxB,oBAAoB,EACpB,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,sBAAsB,EACtB,YAAY,EACZ,yBAAyB,EACzB,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,SAAS,EACT,YAAY,EACZ,yBAAyB,EACzB,+BAA+B,EAC/B,kBAAkB,EAClB,oBAAoB,EACpB,UAAU,EACV,cAAc,EACd,iBAAiB,EACjB,2BAA2B,EAC3B,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,cAAc,EACd,aAAa,EACb,UAAU,EACV,iBAAiB,EACjB,mBAAmB,EACnB,WAAW,EACX,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,eAAe,EACf,UAAU,EACV,uBAAuB,EACvB,0BAA0B,EAC1B,sBAAsB,EACtB,uBAAuB,EACvB,sBAAsB,EACtB,eAAe,EACf,YAAY,EACZ,kCAAkC,EAClC,uBAAuB,EACvB,UAAU,EACV,kBAAkB,GACnB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,0BAA0B,EAC1B,wBAAwB,EACxB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,GAChB,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { type NounTree } from "./types.js";
2
+ export declare function tas(s: string): NounTree;
3
+ export declare function beltSeqToNoun(belts: bigint[]): NounTree;
4
+ export declare function vecToNoun(belts: bigint[]): NounTree;
5
+ export declare function atomToBelts(noun: NounTree): NounTree;
6
+ export declare function tasBelts(s: string): NounTree;
7
+ export declare function beltsToAtom(noun: NounTree): NounTree;
8
+ export declare function untas(noun: NounTree): string;
9
+ //# sourceMappingURL=belts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"belts.d.ts","sourceRoot":"","sources":["../../src/noun/belts.ts"],"names":[],"mappings":"AAGA,OAAO,EAAc,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEvD,wBAAgB,GAAG,CAAC,CAAC,EAAE,MAAM,GAAG,QAAQ,CAGvC;AAGD,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,QAAQ,CAOvD;AAGD,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,QAAQ,CAMnD;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,QAAQ,GAAG,QAAQ,CAKpD;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,GAAG,QAAQ,CAE5C;AA8BD,wBAAgB,WAAW,CAAC,IAAI,EAAE,QAAQ,GAAG,QAAQ,CAEpD;AAED,wBAAgB,KAAK,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,CAI5C"}
@@ -0,0 +1,73 @@
1
+ import { PRIME } from "../core/belt.js";
2
+ import { mustAt } from "../core/must.js";
3
+ import { beltsFromUbig, UBig } from "../core/ubig.js";
4
+ import { atom, cons } from "./types.js";
5
+ export function tas(s) {
6
+ const bytes = new TextEncoder().encode(s);
7
+ return atom(UBig.fromLeBytes(bytes));
8
+ }
9
+ export function beltSeqToNoun(belts) {
10
+ if (belts.length === 0)
11
+ return atom(UBig.zero());
12
+ let acc = atom(UBig.from(mustAt(belts, belts.length - 1)));
13
+ for (let i = belts.length - 2; i >= 0; i--) {
14
+ acc = cons(atom(UBig.from(mustAt(belts, i))), acc);
15
+ }
16
+ return acc;
17
+ }
18
+ export function vecToNoun(belts) {
19
+ let acc = atom(UBig.zero());
20
+ for (let i = belts.length - 1; i >= 0; i--) {
21
+ acc = cons(atom(UBig.from(mustAt(belts, i))), acc);
22
+ }
23
+ return acc;
24
+ }
25
+ export function atomToBelts(noun) {
26
+ if (noun.tag !== "atom") {
27
+ throw new Error("not an atom");
28
+ }
29
+ return beltSeqToNoun(beltsFromUbig(noun.value));
30
+ }
31
+ export function tasBelts(s) {
32
+ return atomToBelts(tas(s));
33
+ }
34
+ function beltSeqFromNoun(noun) {
35
+ const belts = [];
36
+ let current = noun;
37
+ while (current.tag === "cell") {
38
+ const head = current.head;
39
+ if (head.tag !== "atom")
40
+ throw new Error("expected atom belt");
41
+ const v = head.value.tryIntoU64();
42
+ if (v === null)
43
+ throw new Error("belt atom too large");
44
+ belts.push(v);
45
+ current = current.tail;
46
+ }
47
+ if (current.tag !== "atom")
48
+ throw new Error("expected atom terminator");
49
+ const last = current.value.tryIntoU64();
50
+ if (last === null)
51
+ throw new Error("belt atom too large");
52
+ belts.push(last);
53
+ return belts;
54
+ }
55
+ function beltsToUbig(belts) {
56
+ let num = 0n;
57
+ let power = 1n;
58
+ for (const belt of belts) {
59
+ num += belt * power;
60
+ power *= PRIME;
61
+ }
62
+ return UBig.from(num);
63
+ }
64
+ export function beltsToAtom(noun) {
65
+ return atom(beltsToUbig(beltSeqFromNoun(noun)));
66
+ }
67
+ export function untas(noun) {
68
+ if (noun.tag !== "atom")
69
+ throw new Error("not an atom");
70
+ const bytes = noun.value.toLeBytes();
71
+ return new TextDecoder().decode(bytes);
72
+ }
73
+ //# sourceMappingURL=belts.js.map