@warda_protocol/vendor 0.1.0 → 0.2.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.
- package/dist/node.d.ts +12 -1
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +40 -4
- package/dist/node.js.map +1 -1
- package/package.json +10 -2
package/dist/node.d.ts
CHANGED
|
@@ -26,9 +26,20 @@ export interface NodeSource {
|
|
|
26
26
|
resolver?: string;
|
|
27
27
|
/** Which chain, as kaspad names it: `mainnet`, `testnet-10`. */
|
|
28
28
|
network: string;
|
|
29
|
+
/**
|
|
30
|
+
* Whether to fall back to a node this vendor does not control.
|
|
31
|
+
*
|
|
32
|
+
* `auto` (the default) tries a resolver, then borsh if it is installed.
|
|
33
|
+
* `none` refuses, and the refusal is a legitimate position rather than a
|
|
34
|
+
* test seam: the doc above names the trade honestly — a dishonest node
|
|
35
|
+
* could report a payment that does not exist, and the loss is the
|
|
36
|
+
* SELLER's — so a seller who would rather answer 503 than hand goods over
|
|
37
|
+
* on a stranger's word should be able to say so.
|
|
38
|
+
*/
|
|
39
|
+
fallback?: "auto" | "none";
|
|
29
40
|
}
|
|
30
41
|
export interface OpenedNode {
|
|
31
|
-
client: NodeClient
|
|
42
|
+
client: Pick<NodeClient, "getUtxosByAddresses" | "close">;
|
|
32
43
|
/** Sentence for the receipt: which node's word this is. */
|
|
33
44
|
readFrom: string;
|
|
34
45
|
}
|
package/dist/node.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,UAAU,EAA6B,MAAM,uBAAuB,CAAC;AAE9E,MAAM,WAAW,UAAU;IACzB,sDAAsD;IACtD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,qEAAqE;IACrE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gEAAgE;IAChE,OAAO,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,UAAU,EAA6B,MAAM,uBAAuB,CAAC;AAE9E,MAAM,WAAW,UAAU;IACzB,sDAAsD;IACtD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,qEAAqE;IACrE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gEAAgE;IAChE,OAAO,EAAE,MAAM,CAAC;IAChB;;;;;;;;;OASG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,UAAU;IAGzB,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,qBAAqB,GAAG,OAAO,CAAC,CAAC;IAC1D,2DAA2D;IAC3D,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,wBAAsB,QAAQ,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAsEtE"}
|
package/dist/node.js
CHANGED
|
@@ -32,7 +32,8 @@ export async function openNode(source) {
|
|
|
32
32
|
firstFailure = e.message;
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
const
|
|
35
|
+
const allowFallback = (source.fallback ?? "auto") === "auto";
|
|
36
|
+
const resolver = allowFallback ? source.resolver ?? resolverFrom({}) : null;
|
|
36
37
|
if (resolver) {
|
|
37
38
|
/**
|
|
38
39
|
* `resolveNode` then `open`, not `open` alone.
|
|
@@ -57,8 +58,43 @@ export async function openNode(source) {
|
|
|
57
58
|
`answering whether you paid it.`,
|
|
58
59
|
};
|
|
59
60
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
/**
|
|
62
|
+
* Borsh, last, and only if it is installed.
|
|
63
|
+
*
|
|
64
|
+
* Optional rather than a dependency: it pulls a wasm binary, and a vendor
|
|
65
|
+
* running its own JSON node should not have to download one to decline it.
|
|
66
|
+
* The import is lazy for the same reason.
|
|
67
|
+
*/
|
|
68
|
+
const borsh = allowFallback ? await loadBorsh() : null;
|
|
69
|
+
if (borsh) {
|
|
70
|
+
const client = await borsh.BorshReader.open({ networkId: source.network });
|
|
71
|
+
return {
|
|
72
|
+
client,
|
|
73
|
+
readFrom: `a public node found by a resolver, over borsh, because this vendor's own node ` +
|
|
74
|
+
`could not be reached. A node this vendor does not control is answering whether ` +
|
|
75
|
+
`you paid it.`,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
throw new Error((firstFailure ? `${firstFailure}\n\n` : "") +
|
|
79
|
+
`This vendor has no node it can read.\n\n` +
|
|
80
|
+
` A seller never submits a transaction — it only asks whether a coin is at its own\n` +
|
|
81
|
+
` address — so it does not need a JSON node. Installing @warda_protocol/borsh lets\n` +
|
|
82
|
+
` this fall back to the public resolvers, which serve borsh and not JSON.\n\n` +
|
|
83
|
+
` npm install @warda_protocol/borsh kaspa-wasm32-sdk`);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* `@warda_protocol/borsh` if it is there, and nothing if it is not.
|
|
87
|
+
*
|
|
88
|
+
* A missing optional dependency is a configuration fact, not an error: the
|
|
89
|
+
* caller gets a message naming the install, rather than a module-resolution
|
|
90
|
+
* stack trace from inside a payment.
|
|
91
|
+
*/
|
|
92
|
+
async function loadBorsh() {
|
|
93
|
+
try {
|
|
94
|
+
return (await import("@warda_protocol/borsh"));
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
63
99
|
}
|
|
64
100
|
//# sourceMappingURL=node.js.map
|
package/dist/node.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,M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AAiF;gBACjF,gCAAgC;SACnC,CAAC;IACJ,CAAC;IAED;;;;;;OAMG;IACH,MAAM,KAAK,GAAG,aAAa,CAAC,CAAC,CAAC,MAAM,SAAS,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IACvD,IAAI,KAAK,EAAE,CAAC;QACV,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;QAC3E,OAAO;YACL,MAAM;YACN,QAAQ,EACN,gFAAgF;gBAChF,iFAAiF;gBACjF,cAAc;SACjB,CAAC;IACJ,CAAC;IAED,MAAM,IAAI,KAAK,CACb,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,YAAY,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;QACzC,0CAA0C;QAC1C,sFAAsF;QACtF,sFAAsF;QACtF,+EAA+E;QAC/E,wDAAwD,CAC3D,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,KAAK,UAAU,SAAS;IACtB,IAAI,CAAC;QACH,OAAO,CAAC,MAAM,MAAM,CAAC,uBAAuB,CAAC,CAAU,CAAC;IAC1D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@warda_protocol/vendor",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Sell an API for Kaspa over HTTP 402. Quotes a price, then verifies the payment is in the UTXO set before serving \u2014 it never trusts the payment header.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -51,5 +51,13 @@
|
|
|
51
51
|
"bugs": {
|
|
52
52
|
"url": "https://github.com/ArtyKOMarkets/warda/issues"
|
|
53
53
|
},
|
|
54
|
-
"sideEffects": false
|
|
54
|
+
"sideEffects": false,
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"@warda_protocol/borsh": "^0.1.0"
|
|
57
|
+
},
|
|
58
|
+
"peerDependenciesMeta": {
|
|
59
|
+
"@warda_protocol/borsh": {
|
|
60
|
+
"optional": true
|
|
61
|
+
}
|
|
62
|
+
}
|
|
55
63
|
}
|