@toon-protocol/core 3.2.1 → 3.4.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.
@@ -0,0 +1,115 @@
1
+ import {
2
+ EnvelopeError,
3
+ EnvelopeErrorKind,
4
+ GIFTWRAP_NONCE_LENGTH,
5
+ GIFTWRAP_PUBLIC_KEY_LENGTH,
6
+ GIFTWRAP_SECRET_LENGTH,
7
+ GIFTWRAP_TYPE_REQUEST,
8
+ GIFTWRAP_TYPE_RESPONSE,
9
+ GiftWrapError,
10
+ GiftWrapErrorKind,
11
+ OerError,
12
+ OerErrorKind,
13
+ SealedResponseError,
14
+ decodeEnvelope,
15
+ decodeEnvelopeRequest,
16
+ decodeEnvelopeResponse,
17
+ decodeVarOctetString,
18
+ decodeVarUint,
19
+ deriveCondition,
20
+ deriveFulfillment,
21
+ encodeEnvelope,
22
+ encodeEnvelopeRequest,
23
+ encodeEnvelopeResponse,
24
+ encodeVarOctetString,
25
+ encodeVarUint,
26
+ envelopeHeader,
27
+ giftWrapPublicKey,
28
+ localGiftWrapEcdh,
29
+ looksLikeSealedResponse,
30
+ openRequest,
31
+ openResponse,
32
+ readExchangeOutcome,
33
+ sealExchange,
34
+ sealRequest,
35
+ sealRequestWithRandomness,
36
+ sealResponse,
37
+ sealResponseWithRandomness
38
+ } from "../chunk-K72H36Y4.js";
39
+
40
+ // src/wire/condition.ts
41
+ import { sha256 } from "@noble/hashes/sha2.js";
42
+ import { randomBytes } from "@noble/hashes/utils.js";
43
+ var CONDITION_LENGTH = 32;
44
+ function mintExecutionCondition() {
45
+ const preimage = randomBytes(CONDITION_LENGTH);
46
+ return { preimage, condition: sha256(preimage) };
47
+ }
48
+ function isZeroCondition(condition) {
49
+ if (condition === void 0) return true;
50
+ for (const byte of condition) {
51
+ if (byte !== 0) return false;
52
+ }
53
+ return true;
54
+ }
55
+ function assertValidCondition(condition) {
56
+ if (condition.length !== CONDITION_LENGTH) {
57
+ throw new Error(
58
+ `executionCondition must be exactly ${CONDITION_LENGTH} bytes, got ${condition.length}`
59
+ );
60
+ }
61
+ }
62
+ function fulfillmentMatchesCondition(fulfillment, condition) {
63
+ if (fulfillment === void 0 || fulfillment.length !== CONDITION_LENGTH) {
64
+ return false;
65
+ }
66
+ const digest = sha256(fulfillment);
67
+ for (let i = 0; i < CONDITION_LENGTH; i++) {
68
+ if (digest[i] !== condition[i]) return false;
69
+ }
70
+ return true;
71
+ }
72
+ export {
73
+ CONDITION_LENGTH,
74
+ EnvelopeError,
75
+ EnvelopeErrorKind,
76
+ GIFTWRAP_NONCE_LENGTH,
77
+ GIFTWRAP_PUBLIC_KEY_LENGTH,
78
+ GIFTWRAP_SECRET_LENGTH,
79
+ GIFTWRAP_TYPE_REQUEST,
80
+ GIFTWRAP_TYPE_RESPONSE,
81
+ GiftWrapError,
82
+ GiftWrapErrorKind,
83
+ OerError,
84
+ OerErrorKind,
85
+ SealedResponseError,
86
+ assertValidCondition,
87
+ decodeEnvelope,
88
+ decodeEnvelopeRequest,
89
+ decodeEnvelopeResponse,
90
+ decodeVarOctetString,
91
+ decodeVarUint,
92
+ deriveCondition,
93
+ deriveFulfillment,
94
+ encodeEnvelope,
95
+ encodeEnvelopeRequest,
96
+ encodeEnvelopeResponse,
97
+ encodeVarOctetString,
98
+ encodeVarUint,
99
+ envelopeHeader,
100
+ fulfillmentMatchesCondition,
101
+ giftWrapPublicKey,
102
+ isZeroCondition,
103
+ localGiftWrapEcdh,
104
+ looksLikeSealedResponse,
105
+ mintExecutionCondition,
106
+ openRequest,
107
+ openResponse,
108
+ readExchangeOutcome,
109
+ sealExchange,
110
+ sealRequest,
111
+ sealRequestWithRandomness,
112
+ sealResponse,
113
+ sealResponseWithRandomness
114
+ };
115
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/wire/condition.ts"],"sourcesContent":["/**\n * Sender-chosen ILP execution conditions (toon-client#350, rolling-swap\n * prerequisite — toon-meta#145 §3 R1/R2).\n *\n * Contract (normative: connector `docs/local-delivery-fulfillment-contract.md`,\n * connector#309):\n * - An ABSENT or ALL-ZERO (32×0x00) `executionCondition` is the LEGACY\n * class: no hashlock, no verification — today's publish/upload writes.\n * - Any NON-ZERO condition is SENDER-CHOSEN: the sender mints a fresh\n * random 32-byte preimage `P` per packet, sets `C = sha256(P)` on the\n * PREPARE, and on FULFILL MUST verify that the returned fulfillment\n * hashes back to `C` — a missing/malformed/mismatching fulfillment is a\n * hard failure (the packet is counted failed, never silently accepted).\n *\n * Isomorphic: @noble/hashes only (no Buffer, no node:crypto).\n */\n\nimport { sha256 } from '@noble/hashes/sha2.js';\nimport { randomBytes } from '@noble/hashes/utils.js';\n\n/** Exact byte length of an ILP execution condition / fulfillment preimage. */\nexport const CONDITION_LENGTH = 32;\n\n/** A freshly minted per-packet hashlock: `condition = sha256(preimage)`. */\nexport interface ExecutionConditionPair {\n /** Random 32-byte preimage `P` — reveal is the commit act; never reuse. */\n preimage: Uint8Array;\n /** `C = sha256(P)` — goes on the PREPARE's `executionCondition`. */\n condition: Uint8Array;\n}\n\n/**\n * Mint a fresh random 32-byte preimage and its sha256 condition (spec R1).\n * Mint one PER PACKET: a reused preimage lets any observer of packet *i*\n * fulfill packet *i+1* without the sender's consent.\n */\nexport function mintExecutionCondition(): ExecutionConditionPair {\n const preimage = randomBytes(CONDITION_LENGTH);\n return { preimage, condition: sha256(preimage) };\n}\n\n/**\n * True when `condition` selects the LEGACY (unverified) class: absent or\n * all-zero. The OER wire treats absent and 32×0x00 identically.\n */\nexport function isZeroCondition(condition: Uint8Array | undefined): boolean {\n if (condition === undefined) return true;\n for (const byte of condition) {\n if (byte !== 0) return false;\n }\n return true;\n}\n\n/**\n * Validate a caller-supplied execution condition before it goes on the wire.\n * @throws {Error} When the condition is not exactly 32 bytes — the OER\n * serializer would otherwise silently zero-fill it, downgrading a\n * sender-chosen packet to the legacy unverified class.\n */\nexport function assertValidCondition(condition: Uint8Array): void {\n if (condition.length !== CONDITION_LENGTH) {\n throw new Error(\n `executionCondition must be exactly ${CONDITION_LENGTH} bytes, got ${condition.length}`\n );\n }\n}\n\n/**\n * True iff `fulfillment` is exactly 32 bytes and `sha256(fulfillment)`\n * equals `condition` — the sender-side FULFILL check (spec R6's mirror).\n * Fail-closed: an undefined/short/long fulfillment never matches.\n */\nexport function fulfillmentMatchesCondition(\n fulfillment: Uint8Array | undefined,\n condition: Uint8Array\n): boolean {\n if (fulfillment === undefined || fulfillment.length !== CONDITION_LENGTH) {\n return false;\n }\n const digest = sha256(fulfillment);\n // Plain comparison is fine: both operands are locally computed/received\n // values on the sender; there is no secret to protect from timing here.\n for (let i = 0; i < CONDITION_LENGTH; i++) {\n if (digest[i] !== condition[i]) return false;\n }\n return true;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,SAAS,cAAc;AACvB,SAAS,mBAAmB;AAGrB,IAAM,mBAAmB;AAezB,SAAS,yBAAiD;AAC/D,QAAM,WAAW,YAAY,gBAAgB;AAC7C,SAAO,EAAE,UAAU,WAAW,OAAO,QAAQ,EAAE;AACjD;AAMO,SAAS,gBAAgB,WAA4C;AAC1E,MAAI,cAAc,OAAW,QAAO;AACpC,aAAW,QAAQ,WAAW;AAC5B,QAAI,SAAS,EAAG,QAAO;AAAA,EACzB;AACA,SAAO;AACT;AAQO,SAAS,qBAAqB,WAA6B;AAChE,MAAI,UAAU,WAAW,kBAAkB;AACzC,UAAM,IAAI;AAAA,MACR,sCAAsC,gBAAgB,eAAe,UAAU,MAAM;AAAA,IACvF;AAAA,EACF;AACF;AAOO,SAAS,4BACd,aACA,WACS;AACT,MAAI,gBAAgB,UAAa,YAAY,WAAW,kBAAkB;AACxE,WAAO;AAAA,EACT;AACA,QAAM,SAAS,OAAO,WAAW;AAGjC,WAAS,IAAI,GAAG,IAAI,kBAAkB,KAAK;AACzC,QAAI,OAAO,CAAC,MAAM,UAAU,CAAC,EAAG,QAAO;AAAA,EACzC;AACA,SAAO;AACT;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toon-protocol/core",
3
- "version": "3.2.1",
3
+ "version": "3.4.0",
4
4
  "description": "Core library for Nostr-based ILP peer discovery and settlement",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -18,6 +18,10 @@
18
18
  "./toon": {
19
19
  "types": "./dist/toon/index.d.ts",
20
20
  "import": "./dist/toon/index.js"
21
+ },
22
+ "./wire": {
23
+ "types": "./dist/wire/index.d.ts",
24
+ "import": "./dist/wire/index.js"
21
25
  }
22
26
  },
23
27
  "files": [
@@ -44,6 +48,8 @@
44
48
  },
45
49
  "dependencies": {
46
50
  "@ardrive/turbo-sdk": "^1.21.0",
51
+ "@noble/ciphers": "^2.0.0",
52
+ "@noble/curves": "^2.0.0",
47
53
  "@noble/hashes": "^2.0.0",
48
54
  "@scure/bip32": "^2.0.0",
49
55
  "@scure/bip39": "^2.0.0",