@dignetwork/chip35-dl-coin-wasm 0.6.0 → 0.7.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.
@@ -16,6 +16,15 @@ export function addFee(spender_synthetic_key: Uint8Array, selected_coins: any, a
16
16
  */
17
17
  export function adminDelegatedPuzzleFromKey(synthetic_key: Uint8Array): any;
18
18
 
19
+ /**
20
+ * Build the coin spends for a buyer to pay the dapp owner `amount` base units of a **CAT** (incl.
21
+ * DIG) (#46 payment). `selected_cats` is the buyer's `Cat[]` of ONE asset id (as
22
+ * `chip0002_getAssetCoins` returns them); `nonce` is the 32-byte unlock nonce. The CAT ring nets to
23
+ * zero, so carry any XCH network fee with a separate XCH coin via `addFee` asserting the lead CAT
24
+ * coin id. Returns `{ coinSpends, receipt }`.
25
+ */
26
+ export function buildCatPayment(buyer_synthetic_key: Uint8Array, selected_cats: any, owner_puzzle_hash: Uint8Array, amount: bigint, nonce: Uint8Array): any;
27
+
19
28
  /**
20
29
  * Build a CHIP-0007 metadata document from a JS object and return its canonical JSON + the
21
30
  * `metadata_hash` (sha256 of that JSON). De-dupes the hand-computed badge metadata: callers stop
@@ -23,6 +32,13 @@ export function adminDelegatedPuzzleFromKey(synthetic_key: Uint8Array): any;
23
32
  */
24
33
  export function buildChip0007Metadata(metadata: any): any;
25
34
 
35
+ /**
36
+ * Build the coin spends for a buyer to pay the dapp owner `amount` mojos of **XCH** (#46 payment).
37
+ * `selected_coins` is the buyer's XCH `Coin[]`; `nonce` is the 32-byte unlock nonce. Returns
38
+ * `{ coinSpends, receipt }` where `receipt` is the `PaymentReceipt` the paywall later verifies.
39
+ */
40
+ export function buildPayment(buyer_synthetic_key: Uint8Array, selected_coins: any, owner_puzzle_hash: Uint8Array, amount: bigint, nonce: Uint8Array, fee: bigint): any;
41
+
26
42
  /**
27
43
  * Bulk-mint every item in a parsed traits manifest into a collection, attributed to a DID (#34).
28
44
  * `did` is the DID coin + identifiers `{ launcherId, innerPuzzleHash, didCoin }` (e.g. from a prior
@@ -119,6 +135,35 @@ export function oracleDelegatedPuzzle(oracle_puzzle_hash: Uint8Array, oracle_fee
119
135
  */
120
136
  export function oracleSpend(spender_synthetic_key: Uint8Array, selected_coins: any, store: any, fee: bigint): any;
121
137
 
138
+ /**
139
+ * SHA-256-derive a 32-byte unlock nonce from arbitrary request bytes (`dappId||resource||user`).
140
+ * A dapp issues one nonce per unlock request, embeds it in the payment, and verifies it later. The
141
+ * dapp may instead use any random 32 bytes — this is a deterministic convenience. Returns 32 bytes.
142
+ */
143
+ export function paymentNonce(request_bytes: Uint8Array): Uint8Array;
144
+
145
+ /**
146
+ * Prove an NFT held by `claimed_owner_puzzle_hash` is a member of the collection/creator identified
147
+ * by `required_did` (#46 collection-gating). Returns `{ ok, proof?, error? }`.
148
+ */
149
+ export function proveCollectionMembership(parent_spend: any, claimed_owner_puzzle_hash: Uint8Array, required_did: Uint8Array): any;
150
+
151
+ /**
152
+ * Prove an NFT (reconstructed from `parent_spend`, the coin spend that created its current coin) is
153
+ * owned by `claimed_owner_puzzle_hash`, optionally gating on a specific NFT launcher id (#46 NFT-
154
+ * gating). `parent_spend` is the wasm `CoinSpend` shape. Returns `{ ok, proof?, error? }` — on
155
+ * success `proof` is the `NftOwnershipProof` (launcher id, owner, attributed DID, current coin id);
156
+ * the caller still confirms `proof.nftCoinId` is unspent on-chain for liveness.
157
+ */
158
+ export function proveNftOwnership(parent_spend: any, claimed_owner_puzzle_hash: Uint8Array, required_nft?: Uint8Array | null): any;
159
+
160
+ /**
161
+ * Read an NFT's ownership facts (owner, attributed DID, launcher id, current coin id) from
162
+ * `parent_spend` WITHOUT applying a gate — for dapps that want to decide in their own code.
163
+ * Returns `{ ok, proof?, error? }`.
164
+ */
165
+ export function readNftOwnership(parent_spend: any): any;
166
+
122
167
  /**
123
168
  * SHA-256 of arbitrary bytes → 32-byte hash (the one true primitive for `data_hash`/
124
169
  * `metadata_hash`/`license_hash`). Returns the raw 32 bytes (`Uint8Array`).
@@ -154,6 +199,15 @@ export function updateStoreOwnership(store: any, new_owner_puzzle_hash: Uint8Arr
154
199
  */
155
200
  export function validateChip0007(metadata: any, assets: any): any;
156
201
 
202
+ /**
203
+ * Verify an observed payment unlocks a paywall (#46 pay-to-unlock): it must pay `owner_puzzle_hash`,
204
+ * in `required_asset`, at least `min_amount`, and (when `require_nonce` is a 32-byte value) carry
205
+ * that nonce. `observed` is an `ObservedPayment` the dapp filled in after reading the owner's coin;
206
+ * `required_asset` is a `PaymentAsset` (`{xch:true}` or `{assetId}`). Returns `{ ok, error? }` —
207
+ * `ok:true` grants access, otherwise `error` is the human-readable denial reason.
208
+ */
209
+ export function verifyPaymentReceipt(observed: any, owner_puzzle_hash: Uint8Array, min_amount: bigint, required_asset: any, require_nonce?: Uint8Array | null): any;
210
+
157
211
  /**
158
212
  * Build the **Writer** delegated puzzle for a 48-byte synthetic public key — a revocable deploy
159
213
  * token (#17) or a hub Teams writer (#43). A writer may advance the root (deploy a new capsule)
@@ -5,5 +5,5 @@ import { __wbg_set_wasm } from "./chip35_dl_coin_wasm_bg.js";
5
5
  __wbg_set_wasm(wasm);
6
6
 
7
7
  export {
8
- addFee, adminDelegatedPuzzleFromKey, buildChip0007Metadata, bulkMint, createDid, dataStoreFromSpend, decodeOffer, digstoreOwnerHint, encodeOffer, generateItemMetadata, hexSpendBundleToCoinSpends, init, issueCat, meltStore, mintNft, mintStore, oracleDelegatedPuzzle, oracleSpend, sha256, spendBundleToHex, updateStoreMetadata, updateStoreOwnership, validateChip0007, writerDelegatedPuzzleFromKey
8
+ addFee, adminDelegatedPuzzleFromKey, buildCatPayment, buildChip0007Metadata, buildPayment, bulkMint, createDid, dataStoreFromSpend, decodeOffer, digstoreOwnerHint, encodeOffer, generateItemMetadata, hexSpendBundleToCoinSpends, init, issueCat, meltStore, mintNft, mintStore, oracleDelegatedPuzzle, oracleSpend, paymentNonce, proveCollectionMembership, proveNftOwnership, readNftOwnership, sha256, spendBundleToHex, updateStoreMetadata, updateStoreOwnership, validateChip0007, verifyPaymentReceipt, writerDelegatedPuzzleFromKey
9
9
  } from "./chip35_dl_coin_wasm_bg.js";
@@ -52,6 +52,41 @@ export function adminDelegatedPuzzleFromKey(synthetic_key) {
52
52
  }
53
53
  }
54
54
 
55
+ /**
56
+ * Build the coin spends for a buyer to pay the dapp owner `amount` base units of a **CAT** (incl.
57
+ * DIG) (#46 payment). `selected_cats` is the buyer's `Cat[]` of ONE asset id (as
58
+ * `chip0002_getAssetCoins` returns them); `nonce` is the 32-byte unlock nonce. The CAT ring nets to
59
+ * zero, so carry any XCH network fee with a separate XCH coin via `addFee` asserting the lead CAT
60
+ * coin id. Returns `{ coinSpends, receipt }`.
61
+ * @param {Uint8Array} buyer_synthetic_key
62
+ * @param {any} selected_cats
63
+ * @param {Uint8Array} owner_puzzle_hash
64
+ * @param {bigint} amount
65
+ * @param {Uint8Array} nonce
66
+ * @returns {any}
67
+ */
68
+ export function buildCatPayment(buyer_synthetic_key, selected_cats, owner_puzzle_hash, amount, nonce) {
69
+ try {
70
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
71
+ const ptr0 = passArray8ToWasm0(buyer_synthetic_key, wasm.__wbindgen_export);
72
+ const len0 = WASM_VECTOR_LEN;
73
+ const ptr1 = passArray8ToWasm0(owner_puzzle_hash, wasm.__wbindgen_export);
74
+ const len1 = WASM_VECTOR_LEN;
75
+ const ptr2 = passArray8ToWasm0(nonce, wasm.__wbindgen_export);
76
+ const len2 = WASM_VECTOR_LEN;
77
+ wasm.buildCatPayment(retptr, ptr0, len0, addHeapObject(selected_cats), ptr1, len1, amount, ptr2, len2);
78
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
79
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
80
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
81
+ if (r2) {
82
+ throw takeObject(r1);
83
+ }
84
+ return takeObject(r0);
85
+ } finally {
86
+ wasm.__wbindgen_add_to_stack_pointer(16);
87
+ }
88
+ }
89
+
55
90
  /**
56
91
  * Build a CHIP-0007 metadata document from a JS object and return its canonical JSON + the
57
92
  * `metadata_hash` (sha256 of that JSON). De-dupes the hand-computed badge metadata: callers stop
@@ -75,6 +110,40 @@ export function buildChip0007Metadata(metadata) {
75
110
  }
76
111
  }
77
112
 
113
+ /**
114
+ * Build the coin spends for a buyer to pay the dapp owner `amount` mojos of **XCH** (#46 payment).
115
+ * `selected_coins` is the buyer's XCH `Coin[]`; `nonce` is the 32-byte unlock nonce. Returns
116
+ * `{ coinSpends, receipt }` where `receipt` is the `PaymentReceipt` the paywall later verifies.
117
+ * @param {Uint8Array} buyer_synthetic_key
118
+ * @param {any} selected_coins
119
+ * @param {Uint8Array} owner_puzzle_hash
120
+ * @param {bigint} amount
121
+ * @param {Uint8Array} nonce
122
+ * @param {bigint} fee
123
+ * @returns {any}
124
+ */
125
+ export function buildPayment(buyer_synthetic_key, selected_coins, owner_puzzle_hash, amount, nonce, fee) {
126
+ try {
127
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
128
+ const ptr0 = passArray8ToWasm0(buyer_synthetic_key, wasm.__wbindgen_export);
129
+ const len0 = WASM_VECTOR_LEN;
130
+ const ptr1 = passArray8ToWasm0(owner_puzzle_hash, wasm.__wbindgen_export);
131
+ const len1 = WASM_VECTOR_LEN;
132
+ const ptr2 = passArray8ToWasm0(nonce, wasm.__wbindgen_export);
133
+ const len2 = WASM_VECTOR_LEN;
134
+ wasm.buildPayment(retptr, ptr0, len0, addHeapObject(selected_coins), ptr1, len1, amount, ptr2, len2, fee);
135
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
136
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
137
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
138
+ if (r2) {
139
+ throw takeObject(r1);
140
+ }
141
+ return takeObject(r0);
142
+ } finally {
143
+ wasm.__wbindgen_add_to_stack_pointer(16);
144
+ }
145
+ }
146
+
78
147
  /**
79
148
  * Bulk-mint every item in a parsed traits manifest into a collection, attributed to a DID (#34).
80
149
  * `did` is the DID coin + identifiers `{ launcherId, innerPuzzleHash, didCoin }` (e.g. from a prior
@@ -471,6 +540,111 @@ export function oracleSpend(spender_synthetic_key, selected_coins, store, fee) {
471
540
  }
472
541
  }
473
542
 
543
+ /**
544
+ * SHA-256-derive a 32-byte unlock nonce from arbitrary request bytes (`dappId||resource||user`).
545
+ * A dapp issues one nonce per unlock request, embeds it in the payment, and verifies it later. The
546
+ * dapp may instead use any random 32 bytes — this is a deterministic convenience. Returns 32 bytes.
547
+ * @param {Uint8Array} request_bytes
548
+ * @returns {Uint8Array}
549
+ */
550
+ export function paymentNonce(request_bytes) {
551
+ try {
552
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
553
+ const ptr0 = passArray8ToWasm0(request_bytes, wasm.__wbindgen_export);
554
+ const len0 = WASM_VECTOR_LEN;
555
+ wasm.paymentNonce(retptr, ptr0, len0);
556
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
557
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
558
+ var v2 = getArrayU8FromWasm0(r0, r1).slice();
559
+ wasm.__wbindgen_export4(r0, r1 * 1, 1);
560
+ return v2;
561
+ } finally {
562
+ wasm.__wbindgen_add_to_stack_pointer(16);
563
+ }
564
+ }
565
+
566
+ /**
567
+ * Prove an NFT held by `claimed_owner_puzzle_hash` is a member of the collection/creator identified
568
+ * by `required_did` (#46 collection-gating). Returns `{ ok, proof?, error? }`.
569
+ * @param {any} parent_spend
570
+ * @param {Uint8Array} claimed_owner_puzzle_hash
571
+ * @param {Uint8Array} required_did
572
+ * @returns {any}
573
+ */
574
+ export function proveCollectionMembership(parent_spend, claimed_owner_puzzle_hash, required_did) {
575
+ try {
576
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
577
+ const ptr0 = passArray8ToWasm0(claimed_owner_puzzle_hash, wasm.__wbindgen_export);
578
+ const len0 = WASM_VECTOR_LEN;
579
+ const ptr1 = passArray8ToWasm0(required_did, wasm.__wbindgen_export);
580
+ const len1 = WASM_VECTOR_LEN;
581
+ wasm.proveCollectionMembership(retptr, addHeapObject(parent_spend), ptr0, len0, ptr1, len1);
582
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
583
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
584
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
585
+ if (r2) {
586
+ throw takeObject(r1);
587
+ }
588
+ return takeObject(r0);
589
+ } finally {
590
+ wasm.__wbindgen_add_to_stack_pointer(16);
591
+ }
592
+ }
593
+
594
+ /**
595
+ * Prove an NFT (reconstructed from `parent_spend`, the coin spend that created its current coin) is
596
+ * owned by `claimed_owner_puzzle_hash`, optionally gating on a specific NFT launcher id (#46 NFT-
597
+ * gating). `parent_spend` is the wasm `CoinSpend` shape. Returns `{ ok, proof?, error? }` — on
598
+ * success `proof` is the `NftOwnershipProof` (launcher id, owner, attributed DID, current coin id);
599
+ * the caller still confirms `proof.nftCoinId` is unspent on-chain for liveness.
600
+ * @param {any} parent_spend
601
+ * @param {Uint8Array} claimed_owner_puzzle_hash
602
+ * @param {Uint8Array | null} [required_nft]
603
+ * @returns {any}
604
+ */
605
+ export function proveNftOwnership(parent_spend, claimed_owner_puzzle_hash, required_nft) {
606
+ try {
607
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
608
+ const ptr0 = passArray8ToWasm0(claimed_owner_puzzle_hash, wasm.__wbindgen_export);
609
+ const len0 = WASM_VECTOR_LEN;
610
+ var ptr1 = isLikeNone(required_nft) ? 0 : passArray8ToWasm0(required_nft, wasm.__wbindgen_export);
611
+ var len1 = WASM_VECTOR_LEN;
612
+ wasm.proveNftOwnership(retptr, addHeapObject(parent_spend), ptr0, len0, ptr1, len1);
613
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
614
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
615
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
616
+ if (r2) {
617
+ throw takeObject(r1);
618
+ }
619
+ return takeObject(r0);
620
+ } finally {
621
+ wasm.__wbindgen_add_to_stack_pointer(16);
622
+ }
623
+ }
624
+
625
+ /**
626
+ * Read an NFT's ownership facts (owner, attributed DID, launcher id, current coin id) from
627
+ * `parent_spend` WITHOUT applying a gate — for dapps that want to decide in their own code.
628
+ * Returns `{ ok, proof?, error? }`.
629
+ * @param {any} parent_spend
630
+ * @returns {any}
631
+ */
632
+ export function readNftOwnership(parent_spend) {
633
+ try {
634
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
635
+ wasm.readNftOwnership(retptr, addHeapObject(parent_spend));
636
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
637
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
638
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
639
+ if (r2) {
640
+ throw takeObject(r1);
641
+ }
642
+ return takeObject(r0);
643
+ } finally {
644
+ wasm.__wbindgen_add_to_stack_pointer(16);
645
+ }
646
+ }
647
+
474
648
  /**
475
649
  * SHA-256 of arbitrary bytes → 32-byte hash (the one true primitive for `data_hash`/
476
650
  * `metadata_hash`/`license_hash`). Returns the raw 32 bytes (`Uint8Array`).
@@ -628,6 +802,39 @@ export function validateChip0007(metadata, assets) {
628
802
  }
629
803
  }
630
804
 
805
+ /**
806
+ * Verify an observed payment unlocks a paywall (#46 pay-to-unlock): it must pay `owner_puzzle_hash`,
807
+ * in `required_asset`, at least `min_amount`, and (when `require_nonce` is a 32-byte value) carry
808
+ * that nonce. `observed` is an `ObservedPayment` the dapp filled in after reading the owner's coin;
809
+ * `required_asset` is a `PaymentAsset` (`{xch:true}` or `{assetId}`). Returns `{ ok, error? }` —
810
+ * `ok:true` grants access, otherwise `error` is the human-readable denial reason.
811
+ * @param {any} observed
812
+ * @param {Uint8Array} owner_puzzle_hash
813
+ * @param {bigint} min_amount
814
+ * @param {any} required_asset
815
+ * @param {Uint8Array | null} [require_nonce]
816
+ * @returns {any}
817
+ */
818
+ export function verifyPaymentReceipt(observed, owner_puzzle_hash, min_amount, required_asset, require_nonce) {
819
+ try {
820
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
821
+ const ptr0 = passArray8ToWasm0(owner_puzzle_hash, wasm.__wbindgen_export);
822
+ const len0 = WASM_VECTOR_LEN;
823
+ var ptr1 = isLikeNone(require_nonce) ? 0 : passArray8ToWasm0(require_nonce, wasm.__wbindgen_export);
824
+ var len1 = WASM_VECTOR_LEN;
825
+ wasm.verifyPaymentReceipt(retptr, addHeapObject(observed), ptr0, len0, min_amount, addHeapObject(required_asset), ptr1, len1);
826
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
827
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
828
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
829
+ if (r2) {
830
+ throw takeObject(r1);
831
+ }
832
+ return takeObject(r0);
833
+ } finally {
834
+ wasm.__wbindgen_add_to_stack_pointer(16);
835
+ }
836
+ }
837
+
631
838
  /**
632
839
  * Build the **Writer** delegated puzzle for a 48-byte synthetic public key — a revocable deploy
633
840
  * token (#17) or a hub Teams writer (#43). A writer may advance the root (deploy a new capsule)
Binary file
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@dignetwork/chip35-dl-coin-wasm",
3
3
  "type": "module",
4
4
  "description": "WebAssembly bindings for the isolated CHIP-0035 DataLayer store coin driver.",
5
- "version": "0.6.0",
5
+ "version": "0.7.0",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",