@ninsei-labs/sdk 0.55.3 → 0.55.4
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/CHANGELOG.md +17 -0
- package/package.json +1 -1
- package/src/factoryPolicy.mjs +24 -0
- package/src/index.mjs +6 -1
- package/src/version.mjs +1 -1
- package/src/xmr-arrival.mjs +22 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
## 0.55.4 — 2026-11-01
|
|
2
|
+
|
|
3
|
+
- `createNinsei` now defaults the factory and escrow-implementation pins from the settlement network; a caller's
|
|
4
|
+
explicit list still wins. A browser caller with default options no longer funds whatever factory the maker's
|
|
5
|
+
registry names. An unknown network keeps no implementation policy instead of inheriting the default chain's pin.
|
|
6
|
+
- `verifyArrival` classifies a browser `TimeoutError` as `timeout` (not `network`) and a body cut by the same
|
|
7
|
+
timeout as `timeout` (not `bad-answer`); every answered witness carries its height, and `xmr-locked`,
|
|
8
|
+
`xmr-underpaid` and the observation disagreement carry the failed nodes.
|
|
9
|
+
|
|
1
10
|
## 0.55.3 — 2026-10-31
|
|
2
11
|
|
|
3
12
|
- Relay ask carries both view scalars: 64 bytes of plaintext and an 80-byte ciphertext, the same shape as bid.
|
|
@@ -6,6 +15,14 @@
|
|
|
6
15
|
`contracts-testnet-2026.10.26` build. A quote through an unknown factory is refused before signing.
|
|
7
16
|
- `verifyArrival` reports why each Monero node failed (`timeout`, `network`, `http` with status, `bad-answer`)
|
|
8
17
|
and keeps a completed walk pending when another node was unreachable.
|
|
18
|
+
- `swaps.startSell` reads the funded escrow before it returns `send-xmr`: code at the predicted address, an open
|
|
19
|
+
`funded` status, the slots matching the verified halves, and the deadlines by chain time. A missing or late
|
|
20
|
+
escrow is refused instead of handing out the XMR address.
|
|
21
|
+
- The registry read happens before view material is sealed to the features' HPKE key, and the quote's factory is
|
|
22
|
+
checked against the network's pinned build. A relay cannot substitute its own keys or factory.
|
|
23
|
+
- `order.fund` builds the commitment from the verified proof, not from a counterparty-provided `half` field.
|
|
24
|
+
- The wallet's chain is read before funding, claim and refund. **Breaking:** `actions.refund` now requires
|
|
25
|
+
`expect.chainId` and refuses with `bad-input {field: "chainId"}` without it.
|
|
9
26
|
|
|
10
27
|
## 0.55.2 — 2026-10-30
|
|
11
28
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// THE DEFAULT FACTORY POLICY, AT THE ONE DOOR EVERY CALLER COMES THROUGH.
|
|
2
|
+
//
|
|
3
|
+
// The engine's network registry pins the deployed factory build by code hash. `engine/sdk/bridge.js` passed that
|
|
4
|
+
// list explicitly, but `createNinsei` did not: a browser caller with default options got no policy, so a quote
|
|
5
|
+
// naming any factory from the maker's registry was funded. The pin has to reach the core, not only the bridge.
|
|
6
|
+
//
|
|
7
|
+
// An explicit list from the caller still wins, including an empty array ("no policy" on purpose). Only absent or
|
|
8
|
+
// null is replaced by the network's list; a network with no deployed factory keeps null.
|
|
9
|
+
import * as engine from "./engine.mjs";
|
|
10
|
+
|
|
11
|
+
export function factoryCodesForChain({ chain, knownFactoryCodes } = {}) {
|
|
12
|
+
if (knownFactoryCodes !== undefined && knownFactoryCodes !== null) return knownFactoryCodes;
|
|
13
|
+
return engine.config.knownFactoryCodesFor(chain);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function implementationCodesForChain({ chain, knownImplementationCodes } = {}) {
|
|
17
|
+
if (knownImplementationCodes !== undefined && knownImplementationCodes !== null) return knownImplementationCodes;
|
|
18
|
+
// `knownImplementationCodesFor` falls back to the default chain for an unknown id; a policy from another
|
|
19
|
+
// network must not be applied here. Only an exact network record gets its pin.
|
|
20
|
+
const id = typeof chain === "string" ? chain : chain && chain.id;
|
|
21
|
+
const record = id ? engine.config.chainById(id) : null;
|
|
22
|
+
if (!record || String(record.id) !== String(id)) return null;
|
|
23
|
+
return engine.config.knownImplementationCodesFor(chain);
|
|
24
|
+
}
|
package/src/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// THE SDK ENTRY POINT. Assembles the facades and holds rules common to all: no DOM, no texts, no windows.
|
|
2
2
|
import { buildConfig } from "./config.mjs";
|
|
3
|
+
import { factoryCodesForChain, implementationCodesForChain } from "./factoryPolicy.mjs";
|
|
3
4
|
import { createHttp } from "./http.mjs";
|
|
4
5
|
import { createQuotes } from "./quotes.mjs";
|
|
5
6
|
import { createPreflight } from "./preflight.mjs";
|
|
@@ -185,6 +186,10 @@ export function createNinsei(options) {
|
|
|
185
186
|
nodes: o.nodes,
|
|
186
187
|
addNodes: o.addNodes,
|
|
187
188
|
});
|
|
189
|
+
// THE NETWORK'S PINS REACH THE CORE. The bridge passed them explicitly; a caller with default options did not,
|
|
190
|
+
// so the factory policy was null and the quote could name any factory. An explicit caller list still wins.
|
|
191
|
+
const knownFactoryCodes = factoryCodesForChain({ chain: config.settlement.chain, knownFactoryCodes: o.knownFactoryCodes });
|
|
192
|
+
const knownImplementationCodes = implementationCodesForChain({ chain: config.settlement.chain, knownImplementationCodes: o.knownImplementationCodes });
|
|
188
193
|
const leg = legFor(config.settlement.vm);
|
|
189
194
|
const wallet = createWallet({ settlement: config.settlement.chain, leg });
|
|
190
195
|
// THE GUARDS READ THE NETWORK UNDER THE NAME evmNetwork, WHILE THE CONFIGURATION BUILDER RETURNS IT AS
|
|
@@ -221,7 +226,7 @@ export function createNinsei(options) {
|
|
|
221
226
|
: null;
|
|
222
227
|
const quotes = createQuotes({ config, http, now: o.now || (() => Date.now()), evmCall: o.evmCall || null,
|
|
223
228
|
evmCode: o.evmCode || null, evmBlock: o.evmBlock || null,
|
|
224
|
-
providerAllowed, knownFactoryCodes
|
|
229
|
+
providerAllowed, knownFactoryCodes, knownImplementationCodes,
|
|
225
230
|
denylist });
|
|
226
231
|
// THE SAME CHAIN-READ SEAM AS THE LOCK AND THE CORE: checking the slots and signing must go one way, otherwise
|
|
227
232
|
// part of the check goes past the wallet and part does not.
|
package/src/version.mjs
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
// tools/sync-version.mjs. Do not edit it by hand - set the version in package.json and run `npm run sync:version`.
|
|
7
7
|
// The `version` check in tools/check.mjs refuses a mismatch, and refuses a runtime read of package.json here.
|
|
8
8
|
|
|
9
|
-
export const SDK_VERSION = "0.55.
|
|
9
|
+
export const SDK_VERSION = "0.55.4";
|
package/src/xmr-arrival.mjs
CHANGED
|
@@ -41,9 +41,13 @@ const failureOf = (error, node) => {
|
|
|
41
41
|
const params = (error && error.params) || {};
|
|
42
42
|
let code = "network";
|
|
43
43
|
const why = params.why === undefined || params.why === null ? "" : String(params.why);
|
|
44
|
+
// A BROWSER NAMES A TIMEOUT BY THE ERROR'S NAME, NOT ITS MESSAGE. Chromium says "signal timed out" where Node
|
|
45
|
+
// says "The operation was aborted due to timeout"; the name is the one stable word. Check it before rewrapping
|
|
46
|
+
// the answer as a bad one.
|
|
47
|
+
const name = String(params.name || (error && error.name) || "");
|
|
44
48
|
if (params.status !== undefined && params.status !== null) code = "http";
|
|
49
|
+
else if (/^(TimeoutError|AbortError)$/.test(name) || /timeout|abort/i.test(why) || /timeout|abort/i.test(name)) code = "timeout";
|
|
45
50
|
else if (why === "bad-json" || why === "no-height" || why === "no-block") code = "bad-answer";
|
|
46
|
-
else if (/timeout|abort/i.test(why) || /timeout|abort/i.test(String((error && error.name) || ""))) code = "timeout";
|
|
47
51
|
const out = { url: node.url, operator: node.operator, code };
|
|
48
52
|
if (params.status !== undefined && params.status !== null) out.status = params.status;
|
|
49
53
|
if (why) out.why = why;
|
|
@@ -83,10 +87,19 @@ async function call(node, path, body, fetchImpl, timeoutMs) {
|
|
|
83
87
|
signal: typeof AbortSignal !== "undefined" && AbortSignal.timeout ? AbortSignal.timeout(timeoutMs) : undefined,
|
|
84
88
|
});
|
|
85
89
|
} catch (error) {
|
|
86
|
-
|
|
90
|
+
// KEEP THE NAME: `AbortSignal.timeout` is "TimeoutError" in a browser and "AbortError" in Node; the message
|
|
91
|
+
// alone is not portable, and the arrival report has to say timeout rather than network.
|
|
92
|
+
throw new SdkError("xmr-no-nodes", { node: node.url, name: String((error && error.name) || ""),
|
|
93
|
+
why: String((error && error.message) || error).slice(0, 120) });
|
|
87
94
|
}
|
|
88
95
|
if (!res || res.ok !== true) throw new SdkError("xmr-no-nodes", { node: node.url, status: res ? res.status : null });
|
|
89
|
-
try { return await res.json(); } catch
|
|
96
|
+
try { return await res.json(); } catch (error) {
|
|
97
|
+
// A BODY CUT BY THE TIMEOUT IS STILL A TIMEOUT. `res.json()` rejects after the signal fired; in Node and in
|
|
98
|
+
// browsers that is a TimeoutError/AbortError, not a malformed answer.
|
|
99
|
+
const name = String((error && error.name) || "");
|
|
100
|
+
const timedOut = /^(TimeoutError|AbortError)$/.test(name) || /timeout|abort/i.test(name);
|
|
101
|
+
throw new SdkError("xmr-no-nodes", { node: node.url, name, why: timedOut ? "timeout" : "bad-json" });
|
|
102
|
+
}
|
|
90
103
|
}
|
|
91
104
|
|
|
92
105
|
async function getInfo(node, fetchImpl, timeoutMs) {
|
|
@@ -226,6 +239,9 @@ export async function verifyArrival(request) {
|
|
|
226
239
|
catch (error) { record.state = "down"; record.failure = failureOf(error, node); failed.push(record.failure); seen.push(record); continue; }
|
|
227
240
|
// A LAGGING NODE IS NOT A WITNESS and is not a disagreement: it simply cannot see the block yet.
|
|
228
241
|
if (!info.synced || info.height < located.height) { record.state = "stale"; record.height = info.height; seen.push(record); continue; }
|
|
242
|
+
// A WITNESS THAT ANSWERED HAS A HEIGHT, whether it is still confirming or already arrived; the caller can say
|
|
243
|
+
// "answered, height N" without inferring it from the block only when the state is stale.
|
|
244
|
+
record.height = info.height;
|
|
229
245
|
let block;
|
|
230
246
|
try { block = await getBlock(node, located.height, fetchImpl, timeoutMs); }
|
|
231
247
|
catch (error) { record.state = "down"; record.failure = failureOf(error, node); failed.push(record.failure); seen.push(record); continue; }
|
|
@@ -303,7 +319,7 @@ export async function verifyArrival(request) {
|
|
|
303
319
|
throw new SdkError("xmr-nodes-disagree", {
|
|
304
320
|
txid: located.txid, height: located.height,
|
|
305
321
|
nodes: okay.map((r) => ({ url: r.url, operator: r.operator, blockHash: r.blockHash || null, outputs: r.outputs, why: "observation" })),
|
|
306
|
-
agreed: [],
|
|
322
|
+
agreed: [], failed,
|
|
307
323
|
});
|
|
308
324
|
}
|
|
309
325
|
const best = [...byObservation.values()][0];
|
|
@@ -318,13 +334,13 @@ export async function verifyArrival(request) {
|
|
|
318
334
|
if (locked) {
|
|
319
335
|
const until = locked.unlock;
|
|
320
336
|
throw new SdkError("xmr-locked", { txid: located.txid, height: located.height, address: request.address,
|
|
321
|
-
untilHeight: until.untilHeight ?? null, untilTime: until.untilTime ?? null });
|
|
337
|
+
untilHeight: until.untilHeight ?? null, untilTime: until.untilTime ?? null, failed });
|
|
322
338
|
}
|
|
323
339
|
|
|
324
340
|
// THE AMOUNT IS NOT LESS THAN EXPECTED. A shortfall is named rather than shown as a completed swap. The figure
|
|
325
341
|
// comes from the agreed observation, never from the largest answer of one node: that maximum was the defect.
|
|
326
342
|
if (amountAtomic < expectedAtomic) {
|
|
327
|
-
throw new SdkError("xmr-underpaid", { txid: located.txid, height: located.height, got: amountAtomic.toString(), want: expectedAtomic.toString() });
|
|
343
|
+
throw new SdkError("xmr-underpaid", { txid: located.txid, height: located.height, got: amountAtomic.toString(), want: expectedAtomic.toString(), failed });
|
|
328
344
|
}
|
|
329
345
|
|
|
330
346
|
if (best.operators.size < 2) {
|