@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.
- package/README.md +373 -0
- package/dist/constants.d.ts +2 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +2 -0
- package/dist/constants.js.map +1 -0
- package/dist/core/belt.d.ts +16 -0
- package/dist/core/belt.d.ts.map +1 -0
- package/dist/core/belt.js +120 -0
- package/dist/core/belt.js.map +1 -0
- package/dist/core/digest.d.ts +9 -0
- package/dist/core/digest.d.ts.map +1 -0
- package/dist/core/digest.js +76 -0
- package/dist/core/digest.js.map +1 -0
- package/dist/core/hashable.d.ts +21 -0
- package/dist/core/hashable.d.ts.map +1 -0
- package/dist/core/hashable.js +128 -0
- package/dist/core/hashable.js.map +1 -0
- package/dist/core/lock.d.ts +8 -0
- package/dist/core/lock.d.ts.map +1 -0
- package/dist/core/lock.js +95 -0
- package/dist/core/lock.js.map +1 -0
- package/dist/core/merkle.d.ts +7 -0
- package/dist/core/merkle.d.ts.map +1 -0
- package/dist/core/merkle.js +57 -0
- package/dist/core/merkle.js.map +1 -0
- package/dist/core/must.d.ts +3 -0
- package/dist/core/must.d.ts.map +1 -0
- package/dist/core/must.js +14 -0
- package/dist/core/must.js.map +1 -0
- package/dist/core/tip5/constants.d.ts +10 -0
- package/dist/core/tip5/constants.d.ts.map +1 -0
- package/dist/core/tip5/constants.js +70 -0
- package/dist/core/tip5/constants.js.map +1 -0
- package/dist/core/tip5/index.d.ts +5 -0
- package/dist/core/tip5/index.d.ts.map +1 -0
- package/dist/core/tip5/index.js +100 -0
- package/dist/core/tip5/index.js.map +1 -0
- package/dist/core/u256.d.ts +21 -0
- package/dist/core/u256.d.ts.map +1 -0
- package/dist/core/u256.js +96 -0
- package/dist/core/u256.js.map +1 -0
- package/dist/core/ubig.d.ts +20 -0
- package/dist/core/ubig.d.ts.map +1 -0
- package/dist/core/ubig.js +81 -0
- package/dist/core/ubig.js.map +1 -0
- package/dist/core/zbase.d.ts +11 -0
- package/dist/core/zbase.d.ts.map +1 -0
- package/dist/core/zbase.js +82 -0
- package/dist/core/zbase.js.map +1 -0
- package/dist/crypto/bpoly.d.ts +3 -0
- package/dist/crypto/bpoly.d.ts.map +1 -0
- package/dist/crypto/bpoly.js +121 -0
- package/dist/crypto/bpoly.js.map +1 -0
- package/dist/crypto/cheetah.d.ts +25 -0
- package/dist/crypto/cheetah.d.ts.map +1 -0
- package/dist/crypto/cheetah.js +250 -0
- package/dist/crypto/cheetah.js.map +1 -0
- package/dist/crypto/index.d.ts +7 -0
- package/dist/crypto/index.d.ts.map +1 -0
- package/dist/crypto/index.js +24 -0
- package/dist/crypto/index.js.map +1 -0
- package/dist/crypto/privateKey.d.ts +11 -0
- package/dist/crypto/privateKey.d.ts.map +1 -0
- package/dist/crypto/privateKey.js +88 -0
- package/dist/crypto/privateKey.js.map +1 -0
- package/dist/crypto/publicKey.d.ts +18 -0
- package/dist/crypto/publicKey.d.ts.map +1 -0
- package/dist/crypto/publicKey.js +79 -0
- package/dist/crypto/publicKey.js.map +1 -0
- package/dist/crypto/slip10.d.ts +10 -0
- package/dist/crypto/slip10.d.ts.map +1 -0
- package/dist/crypto/slip10.js +104 -0
- package/dist/crypto/slip10.js.map +1 -0
- package/dist/grpc/index.d.ts +12 -0
- package/dist/grpc/index.d.ts.map +1 -0
- package/dist/grpc/index.js +13 -0
- package/dist/grpc/index.js.map +1 -0
- package/dist/grpc/proto.d.ts +26 -0
- package/dist/grpc/proto.d.ts.map +1 -0
- package/dist/grpc/proto.js +219 -0
- package/dist/grpc/proto.js.map +1 -0
- package/dist/hash/index.d.ts +32 -0
- package/dist/hash/index.d.ts.map +1 -0
- package/dist/hash/index.js +138 -0
- package/dist/hash/index.js.map +1 -0
- package/dist/hash/note.d.ts +13 -0
- package/dist/hash/note.d.ts.map +1 -0
- package/dist/hash/note.js +78 -0
- package/dist/hash/note.js.map +1 -0
- package/dist/hash/noteData.d.ts +12 -0
- package/dist/hash/noteData.d.ts.map +1 -0
- package/dist/hash/noteData.js +115 -0
- package/dist/hash/noteData.js.map +1 -0
- package/dist/hash/noun.d.ts +4 -0
- package/dist/hash/noun.d.ts.map +1 -0
- package/dist/hash/noun.js +15 -0
- package/dist/hash/noun.js.map +1 -0
- package/dist/hash/structural.d.ts +5 -0
- package/dist/hash/structural.d.ts.map +1 -0
- package/dist/hash/structural.js +41 -0
- package/dist/hash/structural.js.map +1 -0
- package/dist/hash/tx.d.ts +15 -0
- package/dist/hash/tx.d.ts.map +1 -0
- package/dist/hash/tx.js +146 -0
- package/dist/hash/tx.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/noun/belts.d.ts +9 -0
- package/dist/noun/belts.d.ts.map +1 -0
- package/dist/noun/belts.js +73 -0
- package/dist/noun/belts.js.map +1 -0
- package/dist/noun/bitwriter.d.ts +14 -0
- package/dist/noun/bitwriter.d.ts.map +1 -0
- package/dist/noun/bitwriter.js +100 -0
- package/dist/noun/bitwriter.js.map +1 -0
- package/dist/noun/codec.d.ts +9 -0
- package/dist/noun/codec.d.ts.map +1 -0
- package/dist/noun/codec.js +144 -0
- package/dist/noun/codec.js.map +1 -0
- package/dist/noun/cue.d.ts +3 -0
- package/dist/noun/cue.d.ts.map +1 -0
- package/dist/noun/cue.js +152 -0
- package/dist/noun/cue.js.map +1 -0
- package/dist/noun/encode.d.ts +12 -0
- package/dist/noun/encode.d.ts.map +1 -0
- package/dist/noun/encode.js +37 -0
- package/dist/noun/encode.js.map +1 -0
- package/dist/noun/index.d.ts +10 -0
- package/dist/noun/index.d.ts.map +1 -0
- package/dist/noun/index.js +29 -0
- package/dist/noun/index.js.map +1 -0
- package/dist/noun/jam.d.ts +3 -0
- package/dist/noun/jam.d.ts.map +1 -0
- package/dist/noun/jam.js +107 -0
- package/dist/noun/jam.js.map +1 -0
- package/dist/noun/types.d.ts +21 -0
- package/dist/noun/types.d.ts.map +1 -0
- package/dist/noun/types.js +66 -0
- package/dist/noun/types.js.map +1 -0
- package/dist/noun/words.d.ts +3 -0
- package/dist/noun/words.d.ts.map +1 -0
- package/dist/noun/words.js +6 -0
- package/dist/noun/words.js.map +1 -0
- package/dist/proto/decode.d.ts +10 -0
- package/dist/proto/decode.d.ts.map +1 -0
- package/dist/proto/decode.js +44 -0
- package/dist/proto/decode.js.map +1 -0
- package/dist/proto/digest.d.ts +21 -0
- package/dist/proto/digest.d.ts.map +1 -0
- package/dist/proto/digest.js +29 -0
- package/dist/proto/digest.js.map +1 -0
- package/dist/proto/index.d.ts +9 -0
- package/dist/proto/index.d.ts.map +1 -0
- package/dist/proto/index.js +140 -0
- package/dist/proto/index.js.map +1 -0
- package/dist/proto/note.d.ts +4 -0
- package/dist/proto/note.d.ts.map +1 -0
- package/dist/proto/note.js +99 -0
- package/dist/proto/note.js.map +1 -0
- package/dist/proto/rawTx.d.ts +3 -0
- package/dist/proto/rawTx.d.ts.map +1 -0
- package/dist/proto/rawTx.js +186 -0
- package/dist/proto/rawTx.js.map +1 -0
- package/dist/rpc/client.d.ts +13 -0
- package/dist/rpc/client.d.ts.map +1 -0
- package/dist/rpc/client.js +75 -0
- package/dist/rpc/client.js.map +1 -0
- package/dist/rpc/types.d.ts +18 -0
- package/dist/rpc/types.d.ts.map +1 -0
- package/dist/rpc/types.js +2 -0
- package/dist/rpc/types.js.map +1 -0
- package/dist/rpc/wire/encode.d.ts +4 -0
- package/dist/rpc/wire/encode.d.ts.map +1 -0
- package/dist/rpc/wire/encode.js +168 -0
- package/dist/rpc/wire/encode.js.map +1 -0
- package/dist/rpc/wire/protobuf.d.ts +10 -0
- package/dist/rpc/wire/protobuf.d.ts.map +1 -0
- package/dist/rpc/wire/protobuf.js +50 -0
- package/dist/rpc/wire/protobuf.js.map +1 -0
- package/dist/stubs.d.ts +6 -0
- package/dist/stubs.d.ts.map +1 -0
- package/dist/stubs.js +12 -0
- package/dist/stubs.js.map +1 -0
- package/dist/tx/accessors.d.ts +13 -0
- package/dist/tx/accessors.d.ts.map +1 -0
- package/dist/tx/accessors.js +65 -0
- package/dist/tx/accessors.js.map +1 -0
- package/dist/tx/builder.d.ts +63 -0
- package/dist/tx/builder.d.ts.map +1 -0
- package/dist/tx/builder.js +601 -0
- package/dist/tx/builder.js.map +1 -0
- package/dist/tx/display.d.ts +7 -0
- package/dist/tx/display.d.ts.map +1 -0
- package/dist/tx/display.js +34 -0
- package/dist/tx/display.js.map +1 -0
- package/dist/tx/fee.d.ts +8 -0
- package/dist/tx/fee.d.ts.map +1 -0
- package/dist/tx/fee.js +81 -0
- package/dist/tx/fee.js.map +1 -0
- package/dist/tx/htlc.d.ts +21 -0
- package/dist/tx/htlc.d.ts.map +1 -0
- package/dist/tx/htlc.js +65 -0
- package/dist/tx/htlc.js.map +1 -0
- package/dist/tx/index.d.ts +19 -0
- package/dist/tx/index.d.ts.map +1 -0
- package/dist/tx/index.js +64 -0
- package/dist/tx/index.js.map +1 -0
- package/dist/tx/multisig.d.ts +3 -0
- package/dist/tx/multisig.d.ts.map +1 -0
- package/dist/tx/multisig.js +8 -0
- package/dist/tx/multisig.js.map +1 -0
- package/dist/tx/outputs.d.ts +3 -0
- package/dist/tx/outputs.d.ts.map +1 -0
- package/dist/tx/outputs.js +57 -0
- package/dist/tx/outputs.js.map +1 -0
- package/dist/tx/spend.d.ts +10 -0
- package/dist/tx/spend.d.ts.map +1 -0
- package/dist/tx/spend.js +17 -0
- package/dist/tx/spend.js.map +1 -0
- package/dist/tx/spends.d.ts +8 -0
- package/dist/tx/spends.d.ts.map +1 -0
- package/dist/tx/spends.js +48 -0
- package/dist/tx/spends.js.map +1 -0
- package/dist/tx/types.d.ts +5 -0
- package/dist/tx/types.d.ts.map +1 -0
- package/dist/tx/types.js +2 -0
- package/dist/tx/types.js.map +1 -0
- package/dist/tx/unlocks.d.ts +4 -0
- package/dist/tx/unlocks.d.ts.map +1 -0
- package/dist/tx/unlocks.js +49 -0
- package/dist/tx/unlocks.js.map +1 -0
- package/dist/tx/witness.d.ts +14 -0
- package/dist/tx/witness.d.ts.map +1 -0
- package/dist/tx/witness.js +81 -0
- package/dist/tx/witness.js.map +1 -0
- package/dist/types.d.ts +311 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +45 -0
package/README.md
ADDED
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
# @nockchain/rose-ts
|
|
2
|
+
|
|
3
|
+
Pure TypeScript Nockchain wallet primitives — a curated drop-in for protocol-facing APIs in `@nockchain/rose-wasm`, without a WebAssembly runtime.
|
|
4
|
+
|
|
5
|
+
Use it in Node.js, browsers, React Native, Cloudflare Workers, or anywhere you want Nockchain cryptography and transaction semantics in plain TS.
|
|
6
|
+
|
|
7
|
+
**Parity bar:** 78 vitest tests compare implemented exports against `@nockchain/rose-wasm` as the oracle. See [roadmap.md](./roadmap.md) for coverage detail.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @nockchain/rose-ts
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Wasm parity overview
|
|
18
|
+
|
|
19
|
+
| | `@nockchain/iris-wasm` | `@nockchain/rose-ts` |
|
|
20
|
+
|--|------------------------|----------------------|
|
|
21
|
+
| Surface | ~280 functions + 4 classes | Curated wallet / v1-tx subset |
|
|
22
|
+
| Runtime | Wasm init required | Plain TS / ESM |
|
|
23
|
+
| v0 tx construction | Supported | **Out of scope** (v0 decode in protobuf OK) |
|
|
24
|
+
| Noun codecs | `*FromNoun` / `*ToNoun` / `*Hash` per type | Selected hash helpers only |
|
|
25
|
+
| gRPC client | `GrpcClient` | `RpcClient` (+ deprecated `GrpcClient` alias) |
|
|
26
|
+
| SLIP-10 / signing | `PrivateKey`, `ExtendedKey` | ✅ parity (`PrivateKey`, `ExtendedKey`) |
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## APIs only in rose-ts (not wasm)
|
|
31
|
+
|
|
32
|
+
These helpers exist in pure TS to cover wallet flows wasm does not export as standalone functions:
|
|
33
|
+
|
|
34
|
+
### Witness assembly (manual spends)
|
|
35
|
+
|
|
36
|
+
| API | Description |
|
|
37
|
+
|-----|-------------|
|
|
38
|
+
| `lockMerkleProofFromLock(lock, index)` | Merkle proof for spending `lock` at spend-condition index |
|
|
39
|
+
| `witnessNew(lock, index)` | Empty witness shell (`Witness::new`) |
|
|
40
|
+
| `witnessFromLock` | Alias of `witnessNew` |
|
|
41
|
+
| `witnessFromLockMerkleProof(lmp, pkhSigs?, haxMap?)` | Build witness from parts |
|
|
42
|
+
| `witnessClearSignatures(witness)` | Strip `pkh_signature` / `hax_map` |
|
|
43
|
+
| `witnessWithPkhSignature(witness, [pkh, [pubkeyB58, sig]])` | Immutable witness + PKH sig |
|
|
44
|
+
| `witnessWithHaxPreimage(witness, digest, noun)` | Immutable witness + hax preimage |
|
|
45
|
+
| `spendV1FromLock(lock, lockSpIndex, seeds, fee, unlocks?)` | One-shot witness spend constructor |
|
|
46
|
+
|
|
47
|
+
`SpendBuilder` extras for manual assembly:
|
|
48
|
+
|
|
49
|
+
| API | Description |
|
|
50
|
+
|-----|-------------|
|
|
51
|
+
| `SpendBuilder.newFromWitness(note, witness, refundLock?)` | Start a spend from a pre-built witness |
|
|
52
|
+
| `setWitness(witness)` | Replace witness (invalidates sigs) |
|
|
53
|
+
| `pushPkhSignature(pkh, pubkeyBase58, signature)` | Add/update a PKH unlock |
|
|
54
|
+
| `pushHaxPreimage(digest, preimageNoun)` | Add/update a hax unlock |
|
|
55
|
+
|
|
56
|
+
Wasm equivalent today: build witness in Rust via `SpendBuilder.new(note, lock, index)` only; no standalone witness helpers.
|
|
57
|
+
|
|
58
|
+
### HTLC / multisig spend helpers
|
|
59
|
+
|
|
60
|
+
| API | Description |
|
|
61
|
+
|-----|-------------|
|
|
62
|
+
| `htlcOrLock(hNock, buyerPkh, sellerPkh, refundHeight)` | OR(claim \| refund) lock tree |
|
|
63
|
+
| `htlcLockRootDigest(...)` | Digest of HTLC lock root |
|
|
64
|
+
| `multisigLock(m, pkhDigests)` | Single-leaf m-of-n PKH lock |
|
|
65
|
+
| `TxBuilder.simpleSpendWithLocks(notes, locks, lockSpIndices, …, options?)` | Explicit lock + index per note; optional `preimageJam` + `outputExtras` |
|
|
66
|
+
| `TxBuilder.simpleSpendHtlc(notes, locks, lockSpIndex, …, options?)` | HTLC: index `0` = claim (requires `preimageJam`), `1` = refund |
|
|
67
|
+
| `TxBuilder.simpleSpendMultisig(notes, locks, lockSpIndex, …, outputExtras?)` | Wrapper over `simpleSpendWithLocks` |
|
|
68
|
+
|
|
69
|
+
Wasm has only `TxBuilder.simpleSpend(notes, locks, recipient, gift, fee, refundPkh, includeLockData)` — no HTLC/multisig wrappers, no memo/blob on seeds.
|
|
70
|
+
|
|
71
|
+
### Note-data memo / blob ([nockchain#116](https://github.com/nockchain/nockchain/pull/116))
|
|
72
|
+
|
|
73
|
+
| API | Description |
|
|
74
|
+
|-----|-------------|
|
|
75
|
+
| `noteDataPushMemo(data, utf8)` | Push `%memo` (non-empty UTF-8) |
|
|
76
|
+
| `noteDataPushBlob(data, utf8)` | Push `%blob` (trimmed UTF-8; empty omits) |
|
|
77
|
+
| `decodePackedBlobUtf8(jamBytes)` | Decode packed belt jam → UTF-8 |
|
|
78
|
+
| `decodeNoteDataPackedUtf8(noun)` | Decode note-data entry value |
|
|
79
|
+
| `encodeBlobBelts(bytes)` | Length-prefixed LE u32 belt packing |
|
|
80
|
+
|
|
81
|
+
Encoding uses `vecToNoun` (proper list with trailing `0`), matching wallet / explorer jam. Decoder accepts both proper and improper lists.
|
|
82
|
+
|
|
83
|
+
### Transaction helpers
|
|
84
|
+
|
|
85
|
+
| API | Description |
|
|
86
|
+
|-----|-------------|
|
|
87
|
+
| `rawTxV1ToNockchainTx(raw)` | Inverse of `nockchainTxToRawTx` |
|
|
88
|
+
| `spendsV1ApplyWitness(spends, witnessData)` | Reattach witness payloads |
|
|
89
|
+
| `nockchainTxOutputs`, `rawTxV1Outputs` | Derive output notes from a tx |
|
|
90
|
+
|
|
91
|
+
### Crypto
|
|
92
|
+
|
|
93
|
+
| API | Description |
|
|
94
|
+
|-----|-------------|
|
|
95
|
+
| `PublicKey` class | `fromBeBytes`, `fromHex`, `toHex`, `verify(digest, sig)` |
|
|
96
|
+
| `publicKeyFromHex`, `publicKeyToHex`, `publicKeyVerify` | Functional wrappers |
|
|
97
|
+
|
|
98
|
+
Wasm exposes `PublicKey` as a type alias to `CheetahPoint` with free functions (`publicKeyFromHex`, …), not a TS class.
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## Rose-ts extensions to wasm APIs
|
|
103
|
+
|
|
104
|
+
| Wasm API | Rose-ts difference |
|
|
105
|
+
|----------|-------------------|
|
|
106
|
+
| `TxBuilder.simpleSpend(...)` | **8th argument** `outputExtras?: { memo?, blob? }` on output seeds |
|
|
107
|
+
| `SpendBuilder.addPreimage` / `TxBuilder.addPreimage` | See [behavioral differences](#behavioral-differences-vs-wasm) below |
|
|
108
|
+
| `rawTxFromProtobuf` | Decodes **legacy (v0) spends** inside v1 raw txs (wasm path); rose-ts implements both witness and legacy branches |
|
|
109
|
+
| `GrpcClient` | Prefer `RpcClient` — same wire, clearer naming |
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## Behavioral differences vs wasm
|
|
114
|
+
|
|
115
|
+
### Hax preimage hashing (`addPreimage`)
|
|
116
|
+
|
|
117
|
+
- **HTLC / wallet convention:** Hax preimages in lock trees use the **structural** hash-noun digest (`hashPreimage` / `hashStructuredNoun` / node “hax check”).
|
|
118
|
+
- **rose-ts `addPreimage`:** Cues jam, hashes with `hashNounStructural`, and only attaches when that digest appears in the spend condition’s hax preimage set.
|
|
119
|
+
- **wasm / Rust `SpendBuilder::add_preimage`:** Uses `preimage.hash()` (varlen / “whole” noun hash via Dyck + leaves).
|
|
120
|
+
|
|
121
|
+
For HTLC locks built with `hashPreimage(jam)` (as in `htlcOrLock`), **rose-ts correctly attaches claim preimages**. Wasm may not attach the same jam when the spend condition lists structural digests — claim spends built only in wasm should be validated before broadcast.
|
|
122
|
+
|
|
123
|
+
### Memo / blob note-data
|
|
124
|
+
|
|
125
|
+
- Keys and order on output seeds: `lock` → `blob` → `memo` (when `includeLockData` and extras are set).
|
|
126
|
+
- Packed blob/memo values: `[byte-len, …u32-le limbs…]` jammed as a proper list (`vecToNoun`).
|
|
127
|
+
- Empty memo throws; empty/whitespace blob is omitted.
|
|
128
|
+
|
|
129
|
+
### Multisig (`multisigLock`)
|
|
130
|
+
|
|
131
|
+
- Lock **construction** matches wasm (`pkhNew(m, hashes)` + `lockFromList`).
|
|
132
|
+
- **Local** `lockRootHash(multisigLock(...))` fails for `m > 1` until multi-element ZSet hashing is implemented in TS.
|
|
133
|
+
- Use wasm `lockRootHash` as oracle, or build spends via `simpleSpendMultisig` (witness path works for locks wasm can hash).
|
|
134
|
+
|
|
135
|
+
### V0 protocol
|
|
136
|
+
|
|
137
|
+
- `SpendBuilder.new` **rejects** v0 notes.
|
|
138
|
+
- v0 spend **decoding** from protobuf is supported; v0 spend **construction** is out of scope.
|
|
139
|
+
|
|
140
|
+
### Types / wire shapes
|
|
141
|
+
|
|
142
|
+
- `PkhSignature`: wire `[pkh, [pubkey_base58, {c,s}][]` (TS arrays); wasm typings use `ZMap` — values round-trip the same on the wire.
|
|
143
|
+
- `NoteData`: wire `[key, noun][]`; empty map is `[]`.
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## Quick reference — transaction building
|
|
148
|
+
|
|
149
|
+
### Simple PKH spend with memo/blob
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
import {
|
|
153
|
+
TxBuilder,
|
|
154
|
+
txEngineSettingsV1BythosDefault,
|
|
155
|
+
nockchainTxToRawTx,
|
|
156
|
+
rawTxToProtobuf,
|
|
157
|
+
} from "@nockchain/rose-ts";
|
|
158
|
+
|
|
159
|
+
const settings = txEngineSettingsV1BythosDefault();
|
|
160
|
+
const builder = new TxBuilder(settings);
|
|
161
|
+
|
|
162
|
+
builder.simpleSpend(
|
|
163
|
+
[note],
|
|
164
|
+
[{ lock, lock_sp_index: 0 }],
|
|
165
|
+
recipientPkh,
|
|
166
|
+
"1000000",
|
|
167
|
+
null, // auto fee
|
|
168
|
+
myPkh, // change
|
|
169
|
+
true, // include lock in note_data
|
|
170
|
+
{ memo: "hello", blob: "nns/v1/claim/example.nock" }
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
await builder.sign(privateKey);
|
|
174
|
+
const nockTx = builder.build();
|
|
175
|
+
const raw = nockchainTxToRawTx(nockTx);
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### HTLC claim
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
import { htlcOrLock, hashPreimage, TxBuilder } from "@nockchain/rose-ts";
|
|
182
|
+
|
|
183
|
+
const hNock = hashPreimage(preimageJam);
|
|
184
|
+
const lock = htlcOrLock(hNock, buyerPkh, sellerPkh, 1000n);
|
|
185
|
+
|
|
186
|
+
builder.simpleSpendHtlc(
|
|
187
|
+
[note],
|
|
188
|
+
[lock],
|
|
189
|
+
0, // claim branch
|
|
190
|
+
recipientPkh,
|
|
191
|
+
gift,
|
|
192
|
+
null,
|
|
193
|
+
buyerPkh,
|
|
194
|
+
true,
|
|
195
|
+
{
|
|
196
|
+
preimageJam,
|
|
197
|
+
outputExtras: { memo: "claim", blob: "payload" },
|
|
198
|
+
}
|
|
199
|
+
);
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Manual witness spend
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
import {
|
|
206
|
+
spendV1FromLock,
|
|
207
|
+
spendV1NewWitness,
|
|
208
|
+
witnessWithHaxPreimage,
|
|
209
|
+
witnessNew,
|
|
210
|
+
} from "@nockchain/rose-ts";
|
|
211
|
+
|
|
212
|
+
// Option A: one-shot
|
|
213
|
+
const spend = spendV1FromLock(lock, 0, seeds, fee, {
|
|
214
|
+
haxMap: [[hNock, preimageNoun]],
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
// Option B: compose
|
|
218
|
+
let witness = witnessNew(lock, 0);
|
|
219
|
+
witness = witnessWithHaxPreimage(witness, hNock, preimageNoun);
|
|
220
|
+
const spend2 = spendV1NewWitness(witness, seeds, fee);
|
|
221
|
+
|
|
222
|
+
const sb = SpendBuilder.newFromWitness(note, witness, refundLock);
|
|
223
|
+
sb.seed(recipientSeed);
|
|
224
|
+
sb.fee(feePortion);
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### Multisig lock (construction)
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
import { multisigLock, lockRootHash } from "@nockchain/rose-ts";
|
|
231
|
+
|
|
232
|
+
const lock = multisigLock(2, [pkhA, pkhB, pkhC]);
|
|
233
|
+
// lock_sp_index is 0 for this single-leaf lock
|
|
234
|
+
|
|
235
|
+
builder.simpleSpendMultisig(
|
|
236
|
+
[note],
|
|
237
|
+
[lock],
|
|
238
|
+
0,
|
|
239
|
+
recipientPkh,
|
|
240
|
+
gift,
|
|
241
|
+
null,
|
|
242
|
+
myPkh,
|
|
243
|
+
false,
|
|
244
|
+
{ memo: "2-of-3" }
|
|
245
|
+
);
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
## Getting started (identity → lock → tx)
|
|
251
|
+
|
|
252
|
+
### Identity
|
|
253
|
+
|
|
254
|
+
```typescript
|
|
255
|
+
import { hashPublicKey, verifySignature, deriveMasterKeyFromMnemonic, PrivateKey } from "@nockchain/rose-ts";
|
|
256
|
+
|
|
257
|
+
const master = deriveMasterKeyFromMnemonic(mnemonic, "");
|
|
258
|
+
const pkh = hashPublicKey(master.publicKey);
|
|
259
|
+
const key = PrivateKey.fromBytes(master.privateKey);
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
### PKH lock
|
|
263
|
+
|
|
264
|
+
```typescript
|
|
265
|
+
import { pkhSingle, spendConditionNewPkh, lockFromList, lockRootHash } from "@nockchain/rose-ts";
|
|
266
|
+
|
|
267
|
+
const lock = lockFromList([spendConditionNewPkh(pkhSingle(pkh))]);
|
|
268
|
+
const lockRoot = lockRootHash(lock);
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
### Connect & submit
|
|
272
|
+
|
|
273
|
+
```typescript
|
|
274
|
+
import { RpcClient, noteFromProtobuf, rawTxToProtobuf } from "@nockchain/rose-ts";
|
|
275
|
+
|
|
276
|
+
const client = new RpcClient("http://localhost:8080");
|
|
277
|
+
const balance = await client.getBalanceByFirstName(pkh);
|
|
278
|
+
const note = noteFromProtobuf(balance.notes[0].note);
|
|
279
|
+
|
|
280
|
+
// ... build & sign ...
|
|
281
|
+
|
|
282
|
+
await client.sendTransaction(rawTxToProtobuf(raw));
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
---
|
|
286
|
+
|
|
287
|
+
## Exported API index (by module)
|
|
288
|
+
|
|
289
|
+
### Noun (`jam`, `cue`, `tas`, `tasBelts`, `atomToBelts`, `beltsToAtom`, `untas`)
|
|
290
|
+
|
|
291
|
+
### Crypto
|
|
292
|
+
|
|
293
|
+
`deriveMasterKey`, `deriveMasterKeyFromMnemonic`, `ExtendedKey`, `PrivateKey`, `PublicKey`, `hashPublicKey`, `signMessage`, `verifySignature`, `publicKeyFromBeBytes`, `publicKeyFromHex`, `publicKeyToHex`, `publicKeyVerify`
|
|
294
|
+
|
|
295
|
+
### Hash / locks / note-data
|
|
296
|
+
|
|
297
|
+
`hashPreimage`, `hashNoun`, `hashStructuredNoun`, `hashU64`, `pkhSingle`, `pkhNew`, `pkhHash`, `haxHash`, `haxHashPreimage`, `spendCondition*`, `lockFromList`, `lockFromListBurnpad`, `lockRootHash`, `lockHash`, `lockHeight`, `lockProve`, `noteDataEmpty`, `noteDataPushPkh`, `noteDataPushLock`, `noteDataPushMemo`, `noteDataPushBlob`, `decodeNoteDataPackedUtf8`, `decodePackedBlobUtf8`, `encodeBlobBelts`, `noteHash`, `nameV1`, `nameHash`, `hashName`, `hashSeedV1Digest`, `hashSeedsV1Digest`, `hashSpendV1SigHash`, `hashWitnessDigest`, `hashPkhSignatureDigest`, `hashSpendsV1`, `hashLockMerkleProofDigest`, `seedV1NewSinglePkh`
|
|
298
|
+
|
|
299
|
+
### Transaction
|
|
300
|
+
|
|
301
|
+
`TxBuilder`, `SpendBuilder`, `txEngineSettingsV1Default`, `txEngineSettingsV1BythosDefault`, `nockchainTxToRawTx`, `rawTxV1ToNockchainTx`, `rawTxV1New`, `rawTxV1Version`, `rawTxV1InputNames`, `rawTxV1InputSpendConditions`, `spendV1NewWitness`, `spendV1NewLegacy`, `spendV1SigHash`, `spendV1FromLock`, `witnessFromLock`, `witnessNew`, `lockMerkleProofFromLock`, `witnessFromLockMerkleProof`, `witnessClearSignatures`, `witnessWithPkhSignature`, `witnessWithHaxPreimage`, `multisigLock`, `htlcOrLock`, `htlcLockRootDigest`, `nockchainTxOutputs`, `rawTxV1Outputs`, `rawTxTotalFees`, `rawTxV1CalcId`, `spendV1Fee`, `spendV1TotalGifts`, `spendV1UnclampedFee`, `spendsV1Fee`, `spendsV1TotalFees`, `spendsV1TotalGifts`, `spendsV1UnclampedFee`, `spendsV1ApplyWitness`
|
|
302
|
+
|
|
303
|
+
Types: `OutputNoteData`, `SimpleSpendLockOptions`
|
|
304
|
+
|
|
305
|
+
### Protobuf (wire)
|
|
306
|
+
|
|
307
|
+
`noteFromProtobuf`, `noteToProtobuf`, `spendConditionFromProtobuf`, `spendConditionToProtobuf`, `digestFromProtobuf`, `digestToProtobuf`, `rawTxFromProtobuf`, `rawTxToProtobuf`
|
|
308
|
+
|
|
309
|
+
### RPC
|
|
310
|
+
|
|
311
|
+
`RpcClient` — `getBalanceByFirstName`, `getBalanceByAddress`, `sendTransaction`, `transactionAccepted`, …
|
|
312
|
+
|
|
313
|
+
---
|
|
314
|
+
|
|
315
|
+
## Hybrid setup with rose-wasm
|
|
316
|
+
|
|
317
|
+
Use wasm when you need an oracle or APIs not yet ported. Rose-ts can verify txs wasm builds:
|
|
318
|
+
|
|
319
|
+
```typescript
|
|
320
|
+
import init, { TxBuilder as WasmTxBuilder, rawTxFromProtobuf } from "@nockchain/rose-wasm";
|
|
321
|
+
import { TxBuilder, nockchainTxToRawTx, rawTxV1CalcId } from "@nockchain/rose-ts";
|
|
322
|
+
|
|
323
|
+
await init();
|
|
324
|
+
|
|
325
|
+
const wasmTx = new WasmTxBuilder(settings).build();
|
|
326
|
+
const tsTx = TxBuilder.fromNockchainTx(wasmTx, settings).build();
|
|
327
|
+
// For PKH paths: rawTxV1CalcId(nockchainTxToRawTx(wasmTx)) === rawTxV1CalcId(nockchainTxToRawTx(tsTx))
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
Migrate incrementally: keep wasm for exotic noun codecs; use rose-ts for bundler-friendly wallet code paths.
|
|
331
|
+
|
|
332
|
+
---
|
|
333
|
+
|
|
334
|
+
## Development
|
|
335
|
+
|
|
336
|
+
```bash
|
|
337
|
+
npm install
|
|
338
|
+
npm run build
|
|
339
|
+
npm test # 78 parity tests (requires @nockchain/rose-wasm devDep)
|
|
340
|
+
npm run test:watch
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
## Related Projects
|
|
344
|
+
|
|
345
|
+
- [`@nockbox/iris-rs`](https://github.com/nockbox/iris-rs) — iris-rs
|
|
346
|
+
- [`@nockbox/iris-sdk`](https://github.com/nockbox/iris-sdk) — iris-sdk
|
|
347
|
+
- [`roadmap.md`](./roadmap.md) — coverage matrix and next steps
|
|
348
|
+
- [`@nockchain/rose-rs`](../../) — Rust workspace (protocol types, crypto, gRPC proto)
|
|
349
|
+
|
|
350
|
+
## License
|
|
351
|
+
|
|
352
|
+
MIT License
|
|
353
|
+
|
|
354
|
+
Copyright (c) 2026 nockchain.net <oss@nockchain.net>
|
|
355
|
+
Copyright (c) 2025 NockBox inc. <tech@nockbox.org>
|
|
356
|
+
|
|
357
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
358
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
359
|
+
in the Software without restriction, including without limitation the rights
|
|
360
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
361
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
362
|
+
furnished to do so, subject to the following conditions:
|
|
363
|
+
|
|
364
|
+
The above copyright notice and this permission notice shall be included in all
|
|
365
|
+
copies or substantial portions of the Software.
|
|
366
|
+
|
|
367
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
368
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
369
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
370
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
371
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
372
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
373
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,oBAAoB,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const PRIME = 18446744069414584321n;
|
|
2
|
+
export declare const PRIME_128 = 18446744069414584321n;
|
|
3
|
+
export type Belt = bigint;
|
|
4
|
+
export declare function basedCheck(a: Belt): boolean;
|
|
5
|
+
export declare function montReduction(a: bigint): Belt;
|
|
6
|
+
export declare function montiply(a: Belt, b: Belt): Belt;
|
|
7
|
+
export declare function montify(a: Belt): Belt;
|
|
8
|
+
export declare function badd(a: Belt, b: Belt): Belt;
|
|
9
|
+
export declare function bneg(a: Belt): Belt;
|
|
10
|
+
export declare function bsub(a: Belt, b: Belt): Belt;
|
|
11
|
+
export declare function reduce(n: bigint): Belt;
|
|
12
|
+
export declare function bmul(a: Belt, b: Belt): Belt;
|
|
13
|
+
export declare function binv(a: Belt): Belt;
|
|
14
|
+
export declare function bpow(mutA: Belt, mutB: Belt): Belt;
|
|
15
|
+
export declare function beltsFromBytes(bytes: Uint8Array): Belt[];
|
|
16
|
+
//# sourceMappingURL=belt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"belt.d.ts","sourceRoot":"","sources":["../../src/core/belt.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,KAAK,wBAAwB,CAAC;AAC3C,eAAO,MAAM,SAAS,wBAAwB,CAAC;AAI/C,MAAM,MAAM,IAAI,GAAG,MAAM,CAAC;AAE1B,wBAAgB,UAAU,CAAC,CAAC,EAAE,IAAI,GAAG,OAAO,CAE3C;AAMD,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAW7C;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,GAAG,IAAI,CAE/C;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,IAAI,GAAG,IAAI,CAErC;AAED,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,GAAG,IAAI,CAQ3C;AAED,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,GAAG,IAAI,CAElC;AAED,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,GAAG,IAAI,CAM3C;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAEtC;AAeD,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,GAAG,IAAI,CAE3C;AAUD,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,GAAG,IAAI,CAWlC;AAED,wBAAgB,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,CAiBjD;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,EAAE,CAWxD"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { mustAt } from "./must.js";
|
|
2
|
+
export const PRIME = 18446744069414584321n;
|
|
3
|
+
export const PRIME_128 = 18446744069414584321n;
|
|
4
|
+
const R2 = 18446744065119617025n;
|
|
5
|
+
const U64_MASK = 0xffffffffffffffffn;
|
|
6
|
+
export function basedCheck(a) {
|
|
7
|
+
return a >= 0n && a < PRIME;
|
|
8
|
+
}
|
|
9
|
+
function u64(x) {
|
|
10
|
+
return x & U64_MASK;
|
|
11
|
+
}
|
|
12
|
+
export function montReduction(a) {
|
|
13
|
+
const x1 = (a >> 32n) & 0xffffffffn;
|
|
14
|
+
const x2 = a >> 64n;
|
|
15
|
+
const x0 = a & 0xffffffffn;
|
|
16
|
+
const c = (x0 + x1) << 32n;
|
|
17
|
+
const f = c >> 64n;
|
|
18
|
+
const d = c - (x1 + f * PRIME_128);
|
|
19
|
+
if (x2 >= d) {
|
|
20
|
+
return u64(x2 - d);
|
|
21
|
+
}
|
|
22
|
+
return u64(x2 + PRIME_128 - d);
|
|
23
|
+
}
|
|
24
|
+
export function montiply(a, b) {
|
|
25
|
+
return montReduction(a * b);
|
|
26
|
+
}
|
|
27
|
+
export function montify(a) {
|
|
28
|
+
return montReduction(a * R2);
|
|
29
|
+
}
|
|
30
|
+
export function badd(a, b) {
|
|
31
|
+
const bb = u64(PRIME - b);
|
|
32
|
+
let r = a - bb;
|
|
33
|
+
const c = r < 0n;
|
|
34
|
+
if (c)
|
|
35
|
+
r += 1n << 64n;
|
|
36
|
+
const adj = c ? (1n << 32n) - 1n : 0n;
|
|
37
|
+
r = u64(r - adj);
|
|
38
|
+
return r;
|
|
39
|
+
}
|
|
40
|
+
export function bneg(a) {
|
|
41
|
+
return a !== 0n ? u64(PRIME - a) : 0n;
|
|
42
|
+
}
|
|
43
|
+
export function bsub(a, b) {
|
|
44
|
+
let r = a - b;
|
|
45
|
+
const c = r < 0n;
|
|
46
|
+
if (c)
|
|
47
|
+
r += 1n << 64n;
|
|
48
|
+
const adj = c ? (1n << 32n) - 1n : 0n;
|
|
49
|
+
return u64(r - adj);
|
|
50
|
+
}
|
|
51
|
+
export function reduce(n) {
|
|
52
|
+
return reduce159(u64(n), Number((n >> 64n) & 0xffffffffn), u64(n >> 96n));
|
|
53
|
+
}
|
|
54
|
+
function reduce159(low, mid, high) {
|
|
55
|
+
let low2 = low - high;
|
|
56
|
+
if (low2 < 0n)
|
|
57
|
+
low2 = u64(low2 + PRIME);
|
|
58
|
+
let product = BigInt(mid) << 32n;
|
|
59
|
+
product -= product >> 32n;
|
|
60
|
+
let result = u64(product + low2);
|
|
61
|
+
if (result < product)
|
|
62
|
+
result = u64(result + (1n << 64n) - PRIME);
|
|
63
|
+
if (result >= PRIME)
|
|
64
|
+
result -= PRIME;
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
export function bmul(a, b) {
|
|
68
|
+
return reduce(a * b);
|
|
69
|
+
}
|
|
70
|
+
function montwopow(a, b) {
|
|
71
|
+
let res = a;
|
|
72
|
+
for (let i = 0; i < b; i++) {
|
|
73
|
+
res = montiply(res, res);
|
|
74
|
+
}
|
|
75
|
+
return res;
|
|
76
|
+
}
|
|
77
|
+
export function binv(a) {
|
|
78
|
+
const y = montify(a);
|
|
79
|
+
const y2 = montiply(y, montiply(y, y));
|
|
80
|
+
const y3 = montiply(y, montiply(y2, y2));
|
|
81
|
+
const y5 = montiply(y2, montwopow(y3, 2));
|
|
82
|
+
const y10 = montiply(y5, montwopow(y5, 5));
|
|
83
|
+
const y20 = montiply(y10, montwopow(y10, 10));
|
|
84
|
+
const y30 = montiply(y10, montwopow(y20, 10));
|
|
85
|
+
const y31 = montiply(y, montiply(y30, y30));
|
|
86
|
+
const dup = montiply(montwopow(y31, 32), y31);
|
|
87
|
+
return montReduction(montiply(y, montiply(dup, dup)));
|
|
88
|
+
}
|
|
89
|
+
export function bpow(mutA, mutB) {
|
|
90
|
+
let a = mutA;
|
|
91
|
+
let b = mutB;
|
|
92
|
+
let c = 1n;
|
|
93
|
+
if (b === 0n)
|
|
94
|
+
return c;
|
|
95
|
+
while (b > 1n) {
|
|
96
|
+
if ((b & 1n) === 0n) {
|
|
97
|
+
a = reduce(a * a);
|
|
98
|
+
b /= 2n;
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
c = reduce(c * a);
|
|
102
|
+
a = reduce(a * a);
|
|
103
|
+
b = (b - 1n) / 2n;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return reduce(c * a);
|
|
107
|
+
}
|
|
108
|
+
export function beltsFromBytes(bytes) {
|
|
109
|
+
const belts = [];
|
|
110
|
+
for (let i = 0; i < bytes.length; i += 4) {
|
|
111
|
+
const chunk = bytes.subarray(i, i + 4);
|
|
112
|
+
let val = 0n;
|
|
113
|
+
for (let j = 0; j < chunk.length; j++) {
|
|
114
|
+
val |= BigInt(mustAt(chunk, j)) << BigInt(j * 8);
|
|
115
|
+
}
|
|
116
|
+
belts.push(val);
|
|
117
|
+
}
|
|
118
|
+
return belts;
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=belt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"belt.js","sourceRoot":"","sources":["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AC,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YAClB,CAAC,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YAClB,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC;QACpB,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AACvB,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAiB;IAC9C,MAAM,KAAK,GAAW,EAAE,CAAC;IACzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QACzC,MAAM,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QACvC,IAAI,GAAG,GAAG,EAAE,CAAC;QACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACtC,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QACnD,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAClB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type DigestBelts = [bigint, bigint, bigint, bigint, bigint];
|
|
2
|
+
export declare function beltsToUint(belts: DigestBelts): bigint;
|
|
3
|
+
export declare function digestToBase58(belts: DigestBelts): string;
|
|
4
|
+
export declare function digestFromBelts(belts: bigint[]): DigestBelts;
|
|
5
|
+
export declare function digestFromBase58(s: string): DigestBelts;
|
|
6
|
+
export declare function digestBeltsToBase58(belts: DigestBelts): string;
|
|
7
|
+
export declare function digestBeltsToBytes(belts: DigestBelts): Uint8Array;
|
|
8
|
+
export declare function digestBytesFromBase58(s: string): Uint8Array;
|
|
9
|
+
//# sourceMappingURL=digest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"digest.d.ts","sourceRoot":"","sources":["../../src/core/digest.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,WAAW,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAInE,wBAAgB,WAAW,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAQtD;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAUzD;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,WAAW,CAQ5D;AAGD,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,GAAG,WAAW,CAoBvD;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAE9D;AAGD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,WAAW,GAAG,UAAU,CAUjE;AAED,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,MAAM,GAAG,UAAU,CAE3D"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { base58 } from "@scure/base";
|
|
2
|
+
import { PRIME } from "./belt.js";
|
|
3
|
+
import { mustAt } from "./must.js";
|
|
4
|
+
import { UBig } from "./ubig.js";
|
|
5
|
+
const DIGEST_BYTE_LEN = 40;
|
|
6
|
+
export function beltsToUint(belts) {
|
|
7
|
+
let result = 0n;
|
|
8
|
+
let power = 1n;
|
|
9
|
+
for (const belt of belts) {
|
|
10
|
+
result += belt * power;
|
|
11
|
+
power *= PRIME;
|
|
12
|
+
}
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
export function digestToBase58(belts) {
|
|
16
|
+
let hex = beltsToUint(belts).toString(16);
|
|
17
|
+
if (hex.length % 2 !== 0)
|
|
18
|
+
hex = "0" + hex;
|
|
19
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
20
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
21
|
+
bytes[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
22
|
+
}
|
|
23
|
+
let start = 0;
|
|
24
|
+
while (start < bytes.length && bytes[start] === 0)
|
|
25
|
+
start++;
|
|
26
|
+
return base58.encode(bytes.subarray(start));
|
|
27
|
+
}
|
|
28
|
+
export function digestFromBelts(belts) {
|
|
29
|
+
return [
|
|
30
|
+
mustAt(belts, 0),
|
|
31
|
+
mustAt(belts, 1),
|
|
32
|
+
mustAt(belts, 2),
|
|
33
|
+
mustAt(belts, 3),
|
|
34
|
+
mustAt(belts, 4),
|
|
35
|
+
];
|
|
36
|
+
}
|
|
37
|
+
export function digestFromBase58(s) {
|
|
38
|
+
const decoded = base58.decode(s);
|
|
39
|
+
const padded = new Uint8Array(DIGEST_BYTE_LEN);
|
|
40
|
+
padded.set(decoded, DIGEST_BYTE_LEN - decoded.length);
|
|
41
|
+
let num = UBig.zero();
|
|
42
|
+
for (const byte of padded) {
|
|
43
|
+
num = UBig.from((num.value << 8n) | BigInt(byte));
|
|
44
|
+
}
|
|
45
|
+
const belts = new Array(5).fill(0n);
|
|
46
|
+
let remainder = num;
|
|
47
|
+
const zero = UBig.zero();
|
|
48
|
+
for (let i = 0; i < 5; i++) {
|
|
49
|
+
const { quotient, remainder: rem } = remainder.divRem(PRIME);
|
|
50
|
+
belts[i] = rem.value;
|
|
51
|
+
remainder = quotient;
|
|
52
|
+
}
|
|
53
|
+
if (!remainder.eq(zero)) {
|
|
54
|
+
throw new Error("invalid digest: too many belts");
|
|
55
|
+
}
|
|
56
|
+
return digestFromBelts(belts);
|
|
57
|
+
}
|
|
58
|
+
export function digestBeltsToBase58(belts) {
|
|
59
|
+
return digestToBase58(belts);
|
|
60
|
+
}
|
|
61
|
+
export function digestBeltsToBytes(belts) {
|
|
62
|
+
let hex = beltsToUint(belts).toString(16);
|
|
63
|
+
if (hex.length % 2 !== 0)
|
|
64
|
+
hex = "0" + hex;
|
|
65
|
+
const raw = new Uint8Array(hex.length / 2);
|
|
66
|
+
for (let i = 0; i < raw.length; i++) {
|
|
67
|
+
raw[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
68
|
+
}
|
|
69
|
+
const out = new Uint8Array(DIGEST_BYTE_LEN);
|
|
70
|
+
out.set(raw, DIGEST_BYTE_LEN - raw.length);
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
export function digestBytesFromBase58(s) {
|
|
74
|
+
return digestBeltsToBytes(digestFromBase58(s));
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=digest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"digest.js","sourceRoot":"","sources":["../../src/core/digest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAIjC,MAAM,eAAe,GAAG,EAAE,CAAC;AAE3B,MAAM,UAAU,WAAW,CAAC,KAAkB;IAC5C,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,KAAK,GAAG,EAAE,CAAC;IACf,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,IAAI,IAAI,GAAG,KAAK,CAAC;QACvB,KAAK,IAAI,KAAK,CAAC;IACjB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAkB;IAC/C,IAAI,GAAG,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAC1C,IAAI,GAAG,CAAC,MAAM,GAAG,CAA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AM,GAAG,CAAC,CAAC,CAAC;IAC3C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACpC,GAAG,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACrD,CAAC;IACD,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,eAAe,CAAC,CAAC;IAC5C,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,eAAe,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC;IAC3C,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,CAAS;IAC7C,OAAO,kBAAkB,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;AACjD,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type DigestBelts } from "./digest.js";
|
|
2
|
+
import type { Digest, Hax, Lock, LockPrimitive, LockRoot, Nicks, Pkh } from "../types.js";
|
|
3
|
+
export declare function hashU64(v: bigint): DigestBelts;
|
|
4
|
+
export declare function hashPair(a: DigestBelts, b: DigestBelts): DigestBelts;
|
|
5
|
+
export declare function hashBool(v: boolean): DigestBelts;
|
|
6
|
+
export declare function hashTuple(a: DigestBelts, b: DigestBelts): DigestBelts;
|
|
7
|
+
export declare function hashString(s: string): DigestBelts;
|
|
8
|
+
export declare function hashPkh(pkh: Pkh | {
|
|
9
|
+
m: number;
|
|
10
|
+
hashes: Pkh["hashes"] | readonly Digest[];
|
|
11
|
+
}): DigestBelts;
|
|
12
|
+
export declare function hashHax(hax: Hax | {
|
|
13
|
+
preimages: Hax["preimages"] | readonly Digest[];
|
|
14
|
+
}): DigestBelts;
|
|
15
|
+
export declare function hashLockPrimitive(prim: LockPrimitive): DigestBelts;
|
|
16
|
+
export declare function hashSpendCondition(sc: readonly LockPrimitive[]): DigestBelts;
|
|
17
|
+
export declare function hashLock(lock: Lock): DigestBelts;
|
|
18
|
+
export declare function hashLockRoot(root: LockRoot): DigestBelts;
|
|
19
|
+
export declare function hashNicks(nicks: Nicks): DigestBelts;
|
|
20
|
+
export declare function hashToDigest(belts: DigestBelts): Digest;
|
|
21
|
+
//# sourceMappingURL=hashable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hashable.d.ts","sourceRoot":"","sources":["../../src/core/hashable.ts"],"names":[],"mappings":"AAMA,OAAO,EAIL,KAAK,WAAW,EACjB,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAW,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAMnG,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,WAAW,CAE9C;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,WAAW,GAAG,WAAW,CAEpE;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,OAAO,GAAG,WAAW,CAEhD;AAMD,wBAAgB,SAAS,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,WAAW,GAAG,WAAW,CAErE;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,WAAW,CAMjD;AA+BD,wBAAgB,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,GAAG,CAAC,QAAQ,CAAC,GAAG,SAAS,MAAM,EAAE,CAAA;CAAE,GAAG,WAAW,CAGxG;AAED,wBAAgB,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG;IAAE,SAAS,EAAE,GAAG,CAAC,WAAW,CAAC,GAAG,SAAS,MAAM,EAAE,CAAA;CAAE,GAAG,WAAW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