@ninsei-labs/sdk 0.55.4 → 0.57.2
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 +60 -0
- package/LICENSE-POLICY.md +9 -2
- package/README.md +51 -24
- package/THIRD_PARTY_NOTICES.md +174 -0
- package/assets/vendors/MANIFEST.json +18 -0
- package/assets/vendors/sdk/sdk-browser.js +2059 -2
- package/engine/atomic/dleq2.js +187 -22
- package/engine/atomic/order.js +21 -3
- package/engine/core/config.js +17 -24
- package/engine/core/deployments.generated.js +103 -0
- package/engine/core/store.js +25 -4
- package/engine/core/swap.js +54 -52
- package/engine/evm/asyncRoute.js +1 -1
- package/engine/evm/claimGas.js +2 -1
- package/engine/evm/escrow.js +13 -8
- package/engine/evm/factory.js +24 -26
- package/engine/evm/funding.js +8 -3
- package/engine/evm/index.js +2 -4
- package/engine/evm/session.js +3 -3
- package/engine/monero/scan.js +101 -22
- package/engine/recovery/restore.js +8 -8
- package/engine/sdk/bridge.js +3 -6
- package/index.d.ts +57 -27
- package/package.json +25 -8
- package/src/actions.mjs +52 -9
- package/src/adapters/evm-wallet.mjs +24 -5
- package/src/adapters/index.d.ts +66 -0
- package/src/adapters/index.mjs +0 -6
- package/src/codes.mjs +14 -0
- package/src/config.mjs +1 -0
- package/src/engine.mjs +6 -6
- package/src/feeEstimate.mjs +11 -4
- package/src/http.mjs +4 -1
- package/src/index.mjs +4 -3
- package/src/legs/kyber.mjs +23 -0
- package/src/lock.mjs +2 -1
- package/src/order.mjs +108 -20
- package/src/primitives.mjs +4 -5
- package/src/probes.mjs +9 -3
- package/src/provider/envFile.mjs +11 -1
- package/src/public/networks.d.ts +45 -0
- package/src/public/networks.mjs +10 -1
- package/src/public/order.d.ts +4 -0
- package/src/public/recovery.d.ts +40 -54
- package/src/public/recovery.mjs +2 -8
- package/src/public/xmr.d.ts +14 -3
- package/src/public/xmr.mjs +1 -1
- package/src/quoteEip712Spec.mjs +9 -1
- package/src/quotes.mjs +118 -49
- package/src/record.mjs +3 -3
- package/src/recovery-key.mjs +161 -237
- package/src/relayFeatures.mjs +25 -13
- package/src/relayFirmClient.mjs +69 -6
- package/src/relayQuote.mjs +87 -10
- package/src/relayRequest.mjs +12 -3
- package/src/relayView.mjs +3 -3
- package/src/swap-flow.mjs +153 -67
- package/src/swaps.mjs +346 -174
- package/src/sweep-restore.mjs +14 -6
- package/src/sweep.mjs +34 -11
- package/src/version.mjs +1 -1
- package/src/xmr-arrival.mjs +55 -24
- package/assets/vendors/atomic/atomic-browser.js +0 -24
- package/engine/atomic/order-client.js +0 -56
- package/engine/atomic/order-worker.js +0 -156
- package/engine/evm/asyncExec.js +0 -577
- package/engine/evm/asyncLegs.js +0 -308
- package/src/adapters/node-test-evm-wallet.mjs +0 -357
package/src/actions.mjs
CHANGED
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
// claiming it is revealing your own half (irreversible), for refunding the same reveal. The transaction still
|
|
10
10
|
// looks successful.
|
|
11
11
|
import { SdkError } from "./errors.mjs";
|
|
12
|
-
import * as engine from "./engine.mjs";
|
|
13
12
|
// THE DEAL FLOW IS NOW A PACKAGE MODULE, NOT AN ENGINE FILE (#32, wave 3): www/js/core/swap-flow.js moved to
|
|
14
13
|
// sdk/src/swap-flow.mjs. The actions therefore call the module directly instead of reaching it through the
|
|
15
14
|
// mirror - there is exactly one implementation, and it lives here.
|
|
@@ -54,38 +53,82 @@ const withCodes = async (step, work) => {
|
|
|
54
53
|
}
|
|
55
54
|
};
|
|
56
55
|
|
|
57
|
-
export function createActions({ call = null } = {}) {
|
|
56
|
+
export function createActions({ call = null, blockTime = null } = {}) {
|
|
58
57
|
// WHAT READS THE CHAIN IS ALSO A SEAM, and not only for the checks: the slot check and the signature must go
|
|
59
|
-
// ONE way, otherwise part of the check goes past the wallet and part does not.
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
// ONE way, otherwise part of the check goes past the wallet and part does not. The caller's seam wins; otherwise
|
|
59
|
+
// the action reads through the provider of THE WALLET IT WAS GIVEN, never through the process-wide engine
|
|
60
|
+
// provider of another client.
|
|
61
|
+
const providerOf = (wallet) => {
|
|
62
|
+
try { return wallet && typeof wallet.driver === "function" ? wallet.driver() : null; }
|
|
63
|
+
catch { return null; }
|
|
64
|
+
};
|
|
65
|
+
const readerFor = (wallet) => {
|
|
66
|
+
if (typeof call === "function") return call;
|
|
67
|
+
const provider = providerOf(wallet);
|
|
68
|
+
if (!provider || typeof provider.request !== "function") {
|
|
69
|
+
return async () => { throw new SdkError("wallet-not-connected", { surface: "actions.read" }); };
|
|
70
|
+
}
|
|
71
|
+
return async ({ to, data, from }) => {
|
|
72
|
+
// The simulation needs the same sender as the transaction: mark-ready and claim are sender-bound. For a
|
|
73
|
+
// plain read the field is simply absent.
|
|
74
|
+
const tx = from ? { to, data, from } : { to, data };
|
|
75
|
+
const result = await provider.request({ method: "eth_call", params: [tx, "latest"] });
|
|
76
|
+
if (typeof result !== "string" || !result.startsWith("0x")) {
|
|
77
|
+
throw new SdkError("contract-reverted", { surface: "actions.read" });
|
|
78
|
+
}
|
|
79
|
+
return result;
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
// THE LATEST BLOCK TIMESTAMP IS THE CLOCK THE CONTRACT USES. It comes from the same provider as the contract
|
|
83
|
+
// reads; an absent provider or an unreadable block leaves it null, and the half-revealing action refuses with
|
|
84
|
+
// `clock-unreadable` rather than signing without a time verdict.
|
|
85
|
+
const clockFor = (wallet) => typeof blockTime === "function" ? blockTime : async () => {
|
|
86
|
+
try {
|
|
87
|
+
const provider = providerOf(wallet);
|
|
88
|
+
if (!provider || typeof provider.request !== "function") return null;
|
|
89
|
+
const block = await provider.request({ method: "eth_getBlockByNumber", params: ["latest", false] });
|
|
90
|
+
const at = Number(block && block.timestamp);
|
|
91
|
+
return Number.isSafeInteger(at) && at > 0 ? at : null;
|
|
92
|
+
} catch { return null; }
|
|
93
|
+
};
|
|
94
|
+
// THE SENDER IS CAPTURED WITH THE OTHER ACTION INPUTS. The adapter reads eth_accounts again at the send boundary,
|
|
95
|
+
// so a wallet switch between this guard and the transaction is a refusal rather than a claim from a foreign
|
|
96
|
+
// account. A wallet that cannot name its account cannot prove which key will reveal the half.
|
|
97
|
+
const senderOf = async (wallet, step) => {
|
|
98
|
+
const sender = typeof wallet.address === "function" ? await wallet.address() : null;
|
|
99
|
+
if (typeof sender !== "string" || !sender.trim()) throw new SdkError("bad-input", { field: "wallet.address", step });
|
|
100
|
+
return sender;
|
|
101
|
+
};
|
|
102
|
+
const deps = (wallet, chainId, from) => ({ call: readerFor(wallet), from, send: (tx) => wallet.send({ ...tx, chainId, from }), receipt: (h) => wallet.receipt(h), blockTime: clockFor(wallet) });
|
|
62
103
|
return {
|
|
63
104
|
/** Marking "I saw the XMR on the shared address". Without it, claiming is forbidden by the contract. */
|
|
64
105
|
async markReady(request, wallet) {
|
|
65
106
|
requestOrFail(request, []);
|
|
66
107
|
walletOrFail(wallet);
|
|
67
108
|
const { escrow, expect, onStep } = request;
|
|
109
|
+
const sender = await senderOf(wallet, "mark-ready");
|
|
68
110
|
await assertWalletChain(wallet, expect.chainId, "mark-ready");
|
|
69
|
-
return await withCodes("mark-ready", () => flow.markReadyOrder({ escrow, expect, onStep, deps: deps(wallet) }));
|
|
111
|
+
return await withCodes("mark-ready", () => flow.markReadyOrder({ escrow, expect, onStep, deps: deps(wallet, expect.chainId, sender) }));
|
|
70
112
|
},
|
|
71
113
|
/** Claiming: it reveals your own half, so expectations are mandatory. */
|
|
72
114
|
async claim(request, wallet) {
|
|
73
115
|
requestOrFail(request, ["halfClaimer"]);
|
|
74
116
|
walletOrFail(wallet);
|
|
75
117
|
const { escrow, halfClaimer, expect, onStep } = request;
|
|
76
|
-
const sender =
|
|
118
|
+
const sender = await senderOf(wallet, "claim");
|
|
77
119
|
const verdict = claimSenderVerdict({ sender, claimer: request.claimer || (expect && expect.claimer) });
|
|
78
120
|
if (!verdict.ok) throw new SdkError(verdict.code, { field: verdict.field, why: verdict.why, surface: "actions.claim" });
|
|
79
121
|
await assertWalletChain(wallet, expect.chainId, "claim");
|
|
80
|
-
return await withCodes("claim", () => flow.claimOrder({ escrow, halfClaimer, expect, onStep, deps: deps(wallet) }));
|
|
122
|
+
return await withCodes("claim", () => flow.claimOrder({ escrow, halfClaimer, expect, onStep, deps: deps(wallet, expect.chainId, sender) }));
|
|
81
123
|
},
|
|
82
124
|
/** Refunding: it also reveals a half. The core passes the expectations ALWAYS, though the engine does not require them. */
|
|
83
125
|
async refund(request, wallet) {
|
|
84
126
|
requestOrFail(request, ["halfLocker"]);
|
|
85
127
|
walletOrFail(wallet);
|
|
86
128
|
const { escrow, halfLocker, expect, onStep } = request;
|
|
129
|
+
const sender = await senderOf(wallet, "refund");
|
|
87
130
|
await assertWalletChain(wallet, expect.chainId, "refund");
|
|
88
|
-
return await withCodes("refund", () => flow.refundOrder({ escrow, halfLocker, expect, onStep, deps: deps(wallet) }));
|
|
131
|
+
return await withCodes("refund", () => flow.refundOrder({ escrow, halfLocker, expect, onStep, deps: deps(wallet, expect.chainId, sender) }));
|
|
89
132
|
},
|
|
90
133
|
};
|
|
91
134
|
}
|
|
@@ -103,15 +103,34 @@ export function evmWallet(provider, { id = "evm" } = {}) {
|
|
|
103
103
|
// THERE IS DELIBERATELY NO POLLING HERE: `receipt` asks once and returns the receipt, or null if the transaction
|
|
104
104
|
// is not in a block yet. The waiting policy (how long, how often, what on refusal) is set by the caller: a
|
|
105
105
|
// policy of its own inside the adapter would mean two calls wait differently.
|
|
106
|
-
async send({ to, data = "0x", value = 0n, gas = null }) {
|
|
106
|
+
async send({ to, data = "0x", value = 0n, gas = null, chainId = null, from: expectedFrom = null }) {
|
|
107
107
|
if (typeof to !== "string" || !to) throw new SdkError("bad-input", { field: "send.to" });
|
|
108
|
-
const accounts = await provider.request({ method: "eth_accounts" });
|
|
109
|
-
const from = Array.isArray(accounts) ? accounts[0] : null;
|
|
110
|
-
if (!from) throw new SdkError("wallet-not-connected", { step: "send" });
|
|
111
108
|
const hex = (v) => "0x" + BigInt(v).toString(16);
|
|
109
|
+
// THE CHAIN AND THE SENDER ARE READ AT THE SEND BOUNDARY, NOT ONLY AT THE START OF THE ACTION. A wallet can
|
|
110
|
+
// switch networks or accounts between the action's guard and this call; reading both here, refusing a
|
|
111
|
+
// mismatch and putting the values into the transaction makes that switch a refusal instead of a signature
|
|
112
|
+
// from the wrong key or on the wrong chain.
|
|
113
|
+
const gotChain = hexToInt(await provider.request({ method: "eth_chainId" }).catch(() => null));
|
|
114
|
+
if (!Number.isSafeInteger(gotChain) || gotChain <= 0) {
|
|
115
|
+
throw new SdkError("wrong-chain", { vm: "evm", step: "send", want: chainId === null || chainId === undefined ? null : Number(chainId), got: null, why: "unreadable" });
|
|
116
|
+
}
|
|
117
|
+
const wantChain = chainId === null || chainId === undefined ? gotChain : Number(chainId);
|
|
118
|
+
if (!Number.isSafeInteger(wantChain) || wantChain <= 0 || gotChain !== wantChain) {
|
|
119
|
+
throw new SdkError("wrong-chain", { vm: "evm", step: "send", want: wantChain, got: gotChain });
|
|
120
|
+
}
|
|
121
|
+
const accounts = await provider.request({ method: "eth_accounts" });
|
|
122
|
+
const account = Array.isArray(accounts) ? accounts[0] : null;
|
|
123
|
+
if (typeof account !== "string" || !ADDRESS_RE.test(account)) throw new SdkError("wallet-not-connected", { step: "send" });
|
|
124
|
+
if (expectedFrom !== null && expectedFrom !== undefined) {
|
|
125
|
+
const wantFrom = String(expectedFrom).toLowerCase();
|
|
126
|
+
if (!ADDRESS_RE.test(wantFrom)) throw new SdkError("bad-input", { field: "send.from" });
|
|
127
|
+
if (account.toLowerCase() !== wantFrom) {
|
|
128
|
+
throw new SdkError("wrong-account", { vm: "evm", step: "send", want: wantFrom, got: account });
|
|
129
|
+
}
|
|
130
|
+
}
|
|
112
131
|
// GAS IS PASSED IF THE CALLER SET IT: every contract call has its own estimate (marking ready, claiming,
|
|
113
132
|
// refunding), and it comes from the same place as the calldata - the engine's EVM layer.
|
|
114
|
-
const tx = { from, to, data, value: hex(value) };
|
|
133
|
+
const tx = { from: account, to, data, value: hex(value), chainId: hexChainId(gotChain) };
|
|
115
134
|
if (gas !== null && gas !== undefined) tx.gas = hex(gas);
|
|
116
135
|
return await provider.request({ method: "eth_sendTransaction", params: [tx] });
|
|
117
136
|
},
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// DECLARATIONS FOR THE `./adapters` ENTRY.
|
|
2
|
+
//
|
|
3
|
+
// This is the environment seam the interface wires in itself: an EIP-1193 wallet, browser or memory storage, and
|
|
4
|
+
// the two Monero wallet roles. The declarations name exactly what src/adapters/index.mjs re-exports; the test-only
|
|
5
|
+
// Node wallet is intentionally not exported here (it lives in tools/ and is not part of the package contract).
|
|
6
|
+
|
|
7
|
+
import type {
|
|
8
|
+
Eip1193Provider,
|
|
9
|
+
MoneroWalletAdapter,
|
|
10
|
+
StorageAdapter,
|
|
11
|
+
WalletAdapter,
|
|
12
|
+
} from "@ninsei-labs/sdk";
|
|
13
|
+
|
|
14
|
+
export interface EvmWalletOptions {
|
|
15
|
+
/** A short adapter name for the interface; not user-facing text. */
|
|
16
|
+
id?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Wrap an EIP-1193 provider as the SDK's EVM wallet adapter. */
|
|
20
|
+
export declare function evmWallet(provider: Eip1193Provider, options?: EvmWalletOptions): WalletAdapter;
|
|
21
|
+
|
|
22
|
+
/** Browser storage adapter; the scope prefix is the interface's namespace. */
|
|
23
|
+
export declare function localStorageAdapter(scope?: string): StorageAdapter;
|
|
24
|
+
|
|
25
|
+
/** In-memory storage, used by tests and non-browser hosts. */
|
|
26
|
+
export declare function memoryAdapter(initial?: Record<string, string>): StorageAdapter;
|
|
27
|
+
|
|
28
|
+
export interface MoneroWalletOptions {
|
|
29
|
+
/** The monero-ts wallet factory (`createWalletFull` in the browser bundle). */
|
|
30
|
+
createWallet?: (config: Record<string, unknown>) => Promise<unknown>;
|
|
31
|
+
/** A network name accepted by the core: mainnet, stagenet, testnet or fakechain. */
|
|
32
|
+
networkType?: string;
|
|
33
|
+
/** The Monero node or proxy URI. */
|
|
34
|
+
serverUri?: string;
|
|
35
|
+
/** Session password; it protects the in-memory wallet session, not the keys. */
|
|
36
|
+
password?: string;
|
|
37
|
+
/** Extra fields passed to the wallet factory. */
|
|
38
|
+
fields?: Record<string, unknown>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The XMR withdrawal role: sign separately from relay. */
|
|
42
|
+
export interface MoneroWithdrawalWallet {
|
|
43
|
+
open(plan: { readonly address?: string; readonly restoreHeight?: number; readonly networkType?: string } | unknown): Promise<void>;
|
|
44
|
+
sync(): Promise<void>;
|
|
45
|
+
unlockedBalance(): Promise<bigint | number | string>;
|
|
46
|
+
sweepUnlocked(request: { readonly address: string; readonly relay: boolean }): Promise<unknown>;
|
|
47
|
+
fee?(signed: unknown): Promise<string | null>;
|
|
48
|
+
relay(signed: unknown): Promise<readonly string[]>;
|
|
49
|
+
close(): Promise<void>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Build the XMR withdrawal wallet over the caller's monero-ts factory. */
|
|
53
|
+
export declare function moneroWallet(options?: MoneroWalletOptions): MoneroWithdrawalWallet;
|
|
54
|
+
|
|
55
|
+
export interface MoneroWalletAdapterOptions {
|
|
56
|
+
createWallet?: (config: Record<string, unknown>) => Promise<unknown> | null;
|
|
57
|
+
network?: string | null;
|
|
58
|
+
serverUri?: string | null;
|
|
59
|
+
password?: string;
|
|
60
|
+
keys?: Record<string, unknown>;
|
|
61
|
+
restoreHeight?: number;
|
|
62
|
+
expectedAddress?: string | null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Build the SDK wallet adapter over a Monero wallet; it also carries the withdrawal methods. */
|
|
66
|
+
export declare function moneroWalletAdapter(options?: MoneroWalletAdapterOptions): WalletAdapter & Partial<MoneroWalletAdapter>;
|
package/src/adapters/index.mjs
CHANGED
|
@@ -13,9 +13,3 @@ export { moneroWallet } from "./monero.mjs";
|
|
|
13
13
|
// withdrawal role (open/sync/sweepUnlocked/relay); `moneroWalletAdapter` plays the SDK wallet role (vm/connect/
|
|
14
14
|
// address/chainId/unlockedBalance/subscribe/driver). One file for two roles would mix their surfaces.
|
|
15
15
|
export { moneroWalletAdapter } from "./monero-wallet.mjs";
|
|
16
|
-
// A TOOL OF THE TEST CONTOUR - SEPARATE FROM THE PAGE'S WALLET. It signs with its own key (the key comes only
|
|
17
|
-
// from the environment or a file) and refuses to sign on a production network by the engine's marker, so it is
|
|
18
|
-
// only good for local runs. A separate line here also because every file in the directory must be reachable
|
|
19
|
-
// through the package's map: otherwise the adapter exists but cannot be imported.
|
|
20
|
-
export { nodeTestEvmWallet, evmRpcReader, evmRpcProvider, testPrivateKeyFromEnv, isProductionChain, addressOfPrivateKey }
|
|
21
|
-
from "./node-test-evm-wallet.mjs";
|
package/src/codes.mjs
CHANGED
|
@@ -46,6 +46,9 @@ export const ERROR_CODES = [
|
|
|
46
46
|
"wallet-not-connected",
|
|
47
47
|
"wallet-rejected",
|
|
48
48
|
"wrong-chain",
|
|
49
|
+
// THE SENDER CHANGED BETWEEN THE ACTION GUARD AND eth_sendTransaction. A claim or refund reveals a half, so
|
|
50
|
+
// signing from another account would publish the half without paying the claimer; the adapter refuses first.
|
|
51
|
+
"wrong-account",
|
|
49
52
|
"quote-unavailable",
|
|
50
53
|
"quote-refused",
|
|
51
54
|
// A NODE'S ADDRESS DENYLIST REFUSAL (issue #16): the maker's node answers {ok:false, code:"denied-address", why}
|
|
@@ -80,10 +83,12 @@ export const ERROR_CODES = [
|
|
|
80
83
|
// quote-factory-unknown - the record names no factory (zero);
|
|
81
84
|
// quote-factory-mismatch - the signed quote names a DIFFERENT factory than the record;
|
|
82
85
|
// quote-factory-code-unknown - the factory's code is not a build this interface knows.
|
|
86
|
+
// quote-cashier-mismatch - the signed quote names a cashier other than the network's vault.
|
|
83
87
|
"quote-factory-unchecked",
|
|
84
88
|
"quote-factory-unknown",
|
|
85
89
|
"quote-factory-mismatch",
|
|
86
90
|
"quote-factory-code-unknown",
|
|
91
|
+
"quote-cashier-mismatch",
|
|
87
92
|
"recovery-declined",
|
|
88
93
|
"recovery-failed",
|
|
89
94
|
"storage-unavailable",
|
|
@@ -116,6 +121,11 @@ export const ERROR_CODES = [
|
|
|
116
121
|
"xmr-too-late",
|
|
117
122
|
"contract-reverted",
|
|
118
123
|
"insufficient-funds",
|
|
124
|
+
// A FEE REPORTED BY A WALLET/NODE IS DATA, NOT AN INSTRUCTION. Without a ceiling a malicious node can take
|
|
125
|
+
// most of the withdrawal. The refusal names the fee and the limit so the interface does not present it as a
|
|
126
|
+
// normal transfer.
|
|
127
|
+
"sweep-fee-too-high",
|
|
128
|
+
"sweep-fee-unknown",
|
|
119
129
|
// CLAIM GAS FOR THE XMR SELLER (issue #78). The seller comes from Monero and has no coin on the EVM side to pay
|
|
120
130
|
// for the claim, so the maker may send it - but only when asked for, and only after the core has CONFIRMED the
|
|
121
131
|
// gas actually arrived. The three codes name the three states the interface must not blur together:
|
|
@@ -149,6 +159,7 @@ export const ERROR_META = Object.freeze({
|
|
|
149
159
|
"wallet-not-connected": { retryable: false, side: "wallet" },
|
|
150
160
|
"wallet-rejected": { retryable: false, side: "wallet" },
|
|
151
161
|
"wrong-chain": { retryable: false, side: "wallet" },
|
|
162
|
+
"wrong-account": { retryable: false, side: "wallet" },
|
|
152
163
|
"quote-unavailable": { retryable: true, side: "provider" },
|
|
153
164
|
"quote-refused": { retryable: false, side: "provider" },
|
|
154
165
|
"address-denied": { retryable: false, side: "caller" },
|
|
@@ -165,6 +176,7 @@ export const ERROR_META = Object.freeze({
|
|
|
165
176
|
"quote-factory-unknown": { retryable: false, side: "chain" },
|
|
166
177
|
"quote-factory-mismatch": { retryable: false, side: "chain" },
|
|
167
178
|
"quote-factory-code-unknown": { retryable: false, side: "chain" },
|
|
179
|
+
"quote-cashier-mismatch": { retryable: false, side: "chain" },
|
|
168
180
|
"recovery-declined": { retryable: false, side: "wallet" },
|
|
169
181
|
"recovery-failed": { retryable: false, side: "wallet" },
|
|
170
182
|
"storage-unavailable": { retryable: true, side: "service" },
|
|
@@ -179,6 +191,8 @@ export const ERROR_META = Object.freeze({
|
|
|
179
191
|
"xmr-too-late": { retryable: false, side: "chain" },
|
|
180
192
|
"contract-reverted": { retryable: false, side: "chain" },
|
|
181
193
|
"insufficient-funds": { retryable: false, side: "wallet" },
|
|
194
|
+
"sweep-fee-too-high": { retryable: false, side: "chain" },
|
|
195
|
+
"sweep-fee-unknown": { retryable: true, side: "chain" },
|
|
182
196
|
"gas-refused-by-maker": { retryable: false, side: "provider" },
|
|
183
197
|
"gas-not-arrived": { retryable: true, side: "chain" },
|
|
184
198
|
"gas-too-little": { retryable: false, side: "provider" },
|
package/src/config.mjs
CHANGED
|
@@ -59,6 +59,7 @@ const chainConfig = (chain) => ({
|
|
|
59
59
|
escrow: chain.escrow ? {
|
|
60
60
|
address: chain.escrow.address || null,
|
|
61
61
|
mode: chain.escrow.mode || null,
|
|
62
|
+
registry: chain.escrow.registry || null,
|
|
62
63
|
deploymentBlock: Number.isSafeInteger(chain.escrow.deploymentBlock) ? chain.escrow.deploymentBlock : null,
|
|
63
64
|
} : null,
|
|
64
65
|
});
|
package/src/engine.mjs
CHANGED
|
@@ -25,9 +25,9 @@ export * as recoveryFile from "../engine/recovery/recoveryFile.js";
|
|
|
25
25
|
export * as halves from "../engine/atomic/halves.js";
|
|
26
26
|
export * as orderContext from "../engine/atomic/orderContext.js";
|
|
27
27
|
export * as order from "../engine/atomic/order.js";
|
|
28
|
-
// HALF TRANSFER: the byte format and opening are the very same ones the
|
|
29
|
-
//
|
|
30
|
-
//
|
|
28
|
+
// HALF TRANSFER: the byte format and opening are the very same ones the engine's order builder uses. The core
|
|
29
|
+
// keeps no copy of the format: the commitment is computed over those exact bytes, and a second copy would
|
|
30
|
+
// silently drift from the calldata.
|
|
31
31
|
export * as halfenc from "../engine/atomic/halfenc.js";
|
|
32
32
|
// The engine's EVM layer: talking to the chain (order terms, sending, reading) - through this seam.
|
|
33
33
|
export * as evm from "../engine/evm/index.js";
|
|
@@ -37,9 +37,9 @@ export * as evm from "../engine/evm/index.js";
|
|
|
37
37
|
export * as dex from "../engine/evm/dex.js";
|
|
38
38
|
// THE DEAL ENGINE NO LONGER LIVES IN www/js (#32, wave 3): the order flow moved into the package
|
|
39
39
|
// (sdk/src/swap-flow.mjs) and is declared in sdk/index.d.ts. The page reaches it through the bridge, so the
|
|
40
|
-
// mirror no longer carries core/swap-flow.js - what stays in the seam is the ORDER
|
|
41
|
-
//
|
|
42
|
-
|
|
40
|
+
// mirror no longer carries core/swap-flow.js - what stays in the seam is the ORDER QUOTE source and the shared
|
|
41
|
+
// CLAIM GAS LIMIT that the moved flow reads through this same seam. The order side is built by engine/atomic/order.js.
|
|
42
|
+
|
|
43
43
|
export * as rfqSource from "../engine/core/rfqSource.js";
|
|
44
44
|
export * as claimGas from "../engine/evm/claimGas.js";
|
|
45
45
|
export * as escrow from "../engine/evm/escrow.js";
|
package/src/feeEstimate.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
//
|
|
3
3
|
// THE FEE = THE PRICE OF A BYTE × THE SIZE OF THE TRANSACTION. The price belongs to the network, not to the wallet:
|
|
4
4
|
// on Monero it moves with the median block load, so it is not set but ASKED - `get_fee_estimate` returns a price per
|
|
5
|
-
//
|
|
5
|
+
// byte for several priorities. The size is known only after the transaction is assembled (rings, inputs, outputs),
|
|
6
6
|
// so this module answers the PRICE, and `feeForBytes` is the only arithmetic that turns it into a sum.
|
|
7
7
|
//
|
|
8
8
|
// The page used to learn the fee only after signing; a person deciding whether to withdraw should see it before.
|
|
@@ -59,14 +59,21 @@ export async function moneroFeeEstimate({ url, fetchImpl = globalThis.fetch, tim
|
|
|
59
59
|
signal: controller ? controller.signal : undefined,
|
|
60
60
|
});
|
|
61
61
|
} catch (error) {
|
|
62
|
+
if (timer) clearTimeout(timer);
|
|
62
63
|
const aborted = error && (error.name === "AbortError" || error.code === "ABORT_ERR");
|
|
63
64
|
return { ok: false, why: aborted ? "timeout" : "unreachable" };
|
|
64
|
-
}
|
|
65
|
+
}
|
|
66
|
+
if (!response || !response.ok) {
|
|
65
67
|
if (timer) clearTimeout(timer);
|
|
68
|
+
return { ok: false, why: "http", status: response ? response.status : null };
|
|
66
69
|
}
|
|
67
|
-
if (!response || !response.ok) return { ok: false, why: "http", status: response ? response.status : null };
|
|
68
70
|
let body = null;
|
|
69
|
-
|
|
71
|
+
// THE TIMER COVERS THE BODY TOO. The headers do not make the answer complete.
|
|
72
|
+
try { body = await response.json(); } catch {
|
|
73
|
+
if (timer) clearTimeout(timer);
|
|
74
|
+
return { ok: false, why: "not-json" };
|
|
75
|
+
}
|
|
76
|
+
if (timer) clearTimeout(timer);
|
|
70
77
|
if (!body || body.error) return { ok: false, why: "rpc", rpc: body && body.error ? body.error.code ?? null : null };
|
|
71
78
|
const result = body.result || {};
|
|
72
79
|
// THE DAEMON'S OWN UNITS. `fee` and each entry of `fees` are atomic units PER BYTE; `quantization_mask` is the
|
package/src/http.mjs
CHANGED
|
@@ -60,7 +60,10 @@ export function createHttp({ apiBase, fetchImpl = null, timeoutMs = 20_000 }) {
|
|
|
60
60
|
const res = await impl(apiBase + path, init);
|
|
61
61
|
if (!res || typeof res.ok !== "boolean") throw new SdkError("server-unavailable", { why: "bad-response" });
|
|
62
62
|
let parsed = null;
|
|
63
|
-
|
|
63
|
+
// A BODY CUT BY THE TIMEOUT IS NOT AN EMPTY ANSWER. Returning null made a broken response look like a
|
|
64
|
+
// service that answered with no data; the caller then reported the wrong refusal.
|
|
65
|
+
try { parsed = await res.json(); }
|
|
66
|
+
catch { throw new SdkError("server-unavailable", { why: "body" }); }
|
|
64
67
|
return { ok: res.ok, status: res.status, body: parsed };
|
|
65
68
|
} catch (error) {
|
|
66
69
|
if (error instanceof SdkError) throw error;
|
package/src/index.mjs
CHANGED
|
@@ -206,8 +206,9 @@ export function createNinsei(options) {
|
|
|
206
206
|
// ONE CLIENT, ONE STORE. A second client with another adapter used to replace the module-wide store, so the
|
|
207
207
|
// first client listed the second's swaps and could delete them. Even a client that brought no adapter binds the
|
|
208
208
|
// current one, so a later explicit store cannot take it over.
|
|
209
|
-
|
|
210
|
-
|
|
209
|
+
// ONE CLIENT, ONE STORE - WITHOUT A PROCESS-WIDE EXCLUSIVE BINDING. Each facade gets a store over its own
|
|
210
|
+
// adapter; two clients with different storages coexist and neither can take over the other's records.
|
|
211
|
+
const store = engine.store.createStore(o.storage || engine.store.storage());
|
|
211
212
|
const http = createHttp({ apiBase: config.apiBase, fetchImpl: o.fetch, timeoutMs: config.limits.httpTimeoutMs });
|
|
212
213
|
// THE CHAIN READ AND THE ALLOW-LIST GO INTO THE QUOTE CHECK: without the read the signature certifies itself,
|
|
213
214
|
// so the same evmCall seam the lock and the actions use is handed to the quotes too.
|
|
@@ -294,7 +295,7 @@ export function createNinsei(options) {
|
|
|
294
295
|
// THE PATHS, THE POLL TIMINGS AND THE PASS GO INTO THE START: without the configuration the "server" step
|
|
295
296
|
// would not know where to knock, and without the pass there is nothing to present to the service (and that
|
|
296
297
|
// is a refusal with a CODE, not an invented path).
|
|
297
|
-
swaps: createSwaps({ preflight, http, mode: o.mode, xmrNetwork: o.xmrNetwork, call: o.evmCall,
|
|
298
|
+
swaps: createSwaps({ preflight, http, mode: o.mode, xmrNetwork: o.xmrNetwork, call: o.evmCall, now: o.now || null, evmBlock: o.evmBlock || null, store,
|
|
298
299
|
// THE LOG SEAM FOR THE DECLINE CHECK: the watch asks the escrow for its `Declined` event on every tick, so
|
|
299
300
|
// a declined order stops the wait at once instead of running to `xmr-timeout`.
|
|
300
301
|
logs: o.evmLogs || null,
|
package/src/legs/kyber.mjs
CHANGED
|
@@ -229,6 +229,29 @@ export async function kyberUnsignedOrder({ params, chainId = null, fetchImpl = n
|
|
|
229
229
|
if (typeNames !== expectedNames) return refusal("kyber-bad-response", { where: "sign-message", field: "types" });
|
|
230
230
|
const missing = kyberOrderMissingFields(message);
|
|
231
231
|
if (missing.length) return refusal("kyber-bad-response", { where: "sign-message", missing });
|
|
232
|
+
// THE SERVICE MUST SIGN THE ORDER WE ASKED FOR. A receiver, maker or asset it chooses for us is a valid order
|
|
233
|
+
// for someone else; compare every field the request fixed before the typed data reaches the wallet.
|
|
234
|
+
const addresses = ["maker", "makerAsset", "takerAsset", "receiver"];
|
|
235
|
+
for (const field of addresses) {
|
|
236
|
+
if (String(message[field] || "").toLowerCase() !== String(params[field] || "").toLowerCase()) {
|
|
237
|
+
return refusal("kyber-bad-response", { where: "sign-message", field });
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
for (const field of ["makingAmount", "takingAmount"]) {
|
|
241
|
+
if (String(message[field]) !== String(params[field])) {
|
|
242
|
+
return refusal("kyber-bad-response", { where: "sign-message", field });
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
// A REQUEST THAT LIMITS WHO MAY FILL THE ORDER MUST NOT BE WIDENED. The signed field is one address; zero means
|
|
246
|
+
// anyone. When the request fixed a list, the service must name one of its members (a narrower choice is fine,
|
|
247
|
+
// "anyone" is not).
|
|
248
|
+
const allowed = params.allowedSenders === undefined || params.allowedSenders === null
|
|
249
|
+
? null
|
|
250
|
+
: (Array.isArray(params.allowedSenders) ? params.allowedSenders : [params.allowedSenders])
|
|
251
|
+
.map((value) => String(value || "").toLowerCase());
|
|
252
|
+
if (allowed && allowed.length && !allowed.includes(String(message.allowedSender || "").toLowerCase())) {
|
|
253
|
+
return refusal("kyber-bad-response", { where: "sign-message", field: "allowedSender" });
|
|
254
|
+
}
|
|
232
255
|
let digest;
|
|
233
256
|
try {
|
|
234
257
|
digest = kyberOrderDigestHex({ order: message, chainId: id, contract });
|
package/src/lock.mjs
CHANGED
|
@@ -98,7 +98,8 @@ export async function send(request, wallet, deps = {}) {
|
|
|
98
98
|
return await evm.fundOrder({
|
|
99
99
|
...canonical,
|
|
100
100
|
call: reader,
|
|
101
|
-
|
|
101
|
+
onPredicted: deps.onPredicted,
|
|
102
|
+
send: (tx) => wallet.send({ ...tx, chainId: canonical.chainId, from: canonical.locker }),
|
|
102
103
|
// NORMALISING THE RECEIPT ARGUMENT'S SHAPE - HERE, AT THE CORE'S BOUNDARY, NOT AT EVERY CALLER.
|
|
103
104
|
//
|
|
104
105
|
// funding.js calls the receipt with an OBJECT { hash } (waitReceipt), while the adapter contract declares
|
package/src/order.mjs
CHANGED
|
@@ -137,27 +137,73 @@ export function buildOwnSide(order, onBit) {
|
|
|
137
137
|
return { context, side, spendPoint: norm(side.pub.ed), viewPoint: norm(side.viewPub), encPub: norm(side.enc.pub) };
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
+
/**
|
|
141
|
+
* The same side, with the proof yielding between chunks. The synchronous `buildOwnSide` remains the entry for
|
|
142
|
+
* callers that cannot await; both drain the same engine builder.
|
|
143
|
+
*/
|
|
144
|
+
export async function buildOwnSideChunked(order, options = {}) {
|
|
145
|
+
const context = contextOf(order);
|
|
146
|
+
const side = await builder().newSideChunked(context, false, options);
|
|
147
|
+
return { context, side, spendPoint: norm(side.pub.ed), viewPoint: norm(side.viewPub), encPub: norm(side.enc.pub) };
|
|
148
|
+
}
|
|
149
|
+
|
|
140
150
|
/**
|
|
141
151
|
* OUR SIDE FROM HALVES WE ALREADY HAVE - the one recovery key case. A random side would be a second secret,
|
|
142
152
|
* which is exactly what one key removes. The proof is still bound to this order and built by the same engine
|
|
143
153
|
* builder; only the source of the two numbers changes.
|
|
144
154
|
*/
|
|
145
|
-
|
|
146
|
-
const context = contextOf(order);
|
|
147
|
-
const b = builder();
|
|
155
|
+
function knownHalves(builderInstance, { spendHalf, viewHalf } = {}) {
|
|
148
156
|
const scalar = (value, name) => {
|
|
149
157
|
const n = BigInt(value);
|
|
150
|
-
if (n <= 0n || n >= BigInt(
|
|
158
|
+
if (n <= 0n || n >= BigInt(builderInstance.halves.LIMIT)) throw new SdkError("bad-input", { field: name });
|
|
151
159
|
return n;
|
|
152
160
|
};
|
|
153
161
|
const half = scalar(spendHalf, "spendHalf");
|
|
154
162
|
const view = scalar(viewHalf, "viewHalf");
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
163
|
+
return {
|
|
164
|
+
half, view,
|
|
165
|
+
pub: builderInstance.halves.publicHalves(half),
|
|
166
|
+
viewPub: builderInstance.halves.publicHalves(view).ed,
|
|
167
|
+
encPair: builderInstance.enc.recipientKeyPair(),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function sideFromKnown({ half, view, pub, viewPub, encPair }, proof) {
|
|
159
172
|
const side = { half, pub, viewHalf: view, viewPub, enc: encPair, proof, standIn: false };
|
|
160
|
-
return {
|
|
173
|
+
return { side, spendPoint: norm(pub.ed), viewPoint: norm(viewPub), encPub: norm(encPair.pub) };
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function buildOwnSideFromHalves(order, { spendHalf, viewHalf } = {}) {
|
|
177
|
+
const context = contextOf(order);
|
|
178
|
+
const b = builder();
|
|
179
|
+
const inputs = knownHalves(b, { spendHalf, viewHalf });
|
|
180
|
+
const proof = b.dleq.prove(inputs.half, context);
|
|
181
|
+
const { side, spendPoint, viewPoint, encPub } = sideFromKnown(inputs, proof);
|
|
182
|
+
return { context, side, spendPoint, viewPoint, encPub };
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** The same known-halves side, with the DLEQ proof yielding between chunks. */
|
|
186
|
+
export async function buildOwnSideFromHalvesChunked(order, { spendHalf, viewHalf } = {}, options = {}) {
|
|
187
|
+
const context = contextOf(order);
|
|
188
|
+
const b = builder();
|
|
189
|
+
const inputs = knownHalves(b, { spendHalf, viewHalf });
|
|
190
|
+
const proof = await b.dleq.proveChunked(inputs.half, context, options);
|
|
191
|
+
const { side, spendPoint, viewPoint, encPub } = sideFromKnown(inputs, proof);
|
|
192
|
+
return { context, side, spendPoint, viewPoint, encPub, commitHalf: norm(b.halfCommitment(inputs.half)) };
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* THE SAME LOCAL SIDE WITHOUT A SECOND PROOF. A path that already received a verified proof in the firm request
|
|
197
|
+
* (or in the quote) only needs this side's points, view point, encryption key and half for the record and the
|
|
198
|
+
* commitment. Running `prove` again costs ~3 s and its result is never sent. The returned side deliberately has
|
|
199
|
+
* `proof: null`: callers that need a proof must build it, not receive a plausible-looking empty object.
|
|
200
|
+
*/
|
|
201
|
+
export function buildOwnSideFromHalvesKnown(order, { spendHalf, viewHalf } = {}) {
|
|
202
|
+
const context = contextOf(order);
|
|
203
|
+
const b = builder();
|
|
204
|
+
const inputs = knownHalves(b, { spendHalf, viewHalf });
|
|
205
|
+
const { side, spendPoint, viewPoint, encPub } = sideFromKnown(inputs, null);
|
|
206
|
+
return { context, side, spendPoint, viewPoint, encPub, commitHalf: norm(b.halfCommitment(inputs.half)) };
|
|
161
207
|
}
|
|
162
208
|
|
|
163
209
|
/**
|
|
@@ -167,7 +213,7 @@ export function buildOwnSideFromHalves(order, { spendHalf, viewHalf } = {}) {
|
|
|
167
213
|
* against its point. The sandbox stand-in is built here too and marked: it must not be passed off as a real
|
|
168
214
|
* provider.
|
|
169
215
|
*/
|
|
170
|
-
|
|
216
|
+
function acceptedCounterparty({ context, side = null, counterparty = null, standIn = false, mock = null }) {
|
|
171
217
|
let accepted = null;
|
|
172
218
|
if (counterparty && typeof counterparty === "object") {
|
|
173
219
|
const pub = counterparty.pub && typeof counterparty.pub === "object" ? counterparty.pub : {};
|
|
@@ -192,14 +238,14 @@ export function acceptCounterparty({ context, side = null, counterparty = null,
|
|
|
192
238
|
};
|
|
193
239
|
} else if (standIn === true) {
|
|
194
240
|
// THE STAND-IN IS COMPUTED IN THE SAME CONTEXT AS THE ORDER: the string gets nothing appended. The same path
|
|
195
|
-
// as the
|
|
196
|
-
// not what the page runs on.
|
|
197
|
-
const
|
|
198
|
-
accepted = { proof: sameFormAsPoint(
|
|
199
|
-
viewHalf:
|
|
241
|
+
// as the flow (sdk/src/swap-flow.mjs, buildOwnSide) and the check - otherwise what would be checked is
|
|
242
|
+
// not what the page runs on. A chunked caller passes the mock it already built.
|
|
243
|
+
const built = mock || builder().newSide(context, true);
|
|
244
|
+
accepted = { proof: sameFormAsPoint(built.proof), edPub: norm(built.pub.ed), viewPoint: norm(built.viewPub),
|
|
245
|
+
viewHalf: built.viewHalf, half: built.half,
|
|
200
246
|
// THE STAND-IN DOES CARRY A COMMITMENT: it is derived from the half it just built, by the same formula
|
|
201
247
|
// the contract uses. The proof check below is therefore the real one, not a path that skips it.
|
|
202
|
-
commitHalfClaimer: norm(builder().halfCommitment(
|
|
248
|
+
commitHalfClaimer: norm(builder().halfCommitment(built.half)), sealed: null, providerId: null, standIn: true, mock: built };
|
|
203
249
|
} else {
|
|
204
250
|
throw new SdkError("bad-input", { field: "counterparty" });
|
|
205
251
|
}
|
|
@@ -214,6 +260,11 @@ export function acceptCounterparty({ context, side = null, counterparty = null,
|
|
|
214
260
|
// flow the half arrives from the chain via the commit/reveal mechanism, so a locked package honestly answers
|
|
215
261
|
// with a refusal rather than passing itself off as a working key handover.
|
|
216
262
|
const ownEncPriv = accepted.sealed && side && side.enc ? side.enc.priv : null;
|
|
263
|
+
return { accepted, ownEncPriv };
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export function acceptCounterparty({ context, side = null, counterparty = null, standIn = false }) {
|
|
267
|
+
const { accepted, ownEncPriv } = acceptedCounterparty({ context, side, counterparty, standIn });
|
|
217
268
|
let verdict = null;
|
|
218
269
|
try { verdict = builder().verifySide({ proof: accepted.proof, pub: { ed: accepted.edPub }, commitHalfClaimer: accepted.commitHalfClaimer }, context, accepted.sealed, ownEncPriv); }
|
|
219
270
|
catch { throw new SdkError("bad-input", { field: "counterparty" }); }
|
|
@@ -223,25 +274,40 @@ export function acceptCounterparty({ context, side = null, counterparty = null,
|
|
|
223
274
|
return accepted;
|
|
224
275
|
}
|
|
225
276
|
|
|
277
|
+
export async function acceptCounterpartyChunked({ context, side = null, counterparty = null, standIn = false, options = {} }) {
|
|
278
|
+
const mock = (counterparty || standIn !== true) ? null : await builder().newSideChunked(context, true, options);
|
|
279
|
+
const { accepted, ownEncPriv } = acceptedCounterparty({ context, side, counterparty, standIn, mock });
|
|
280
|
+
let verdict = null;
|
|
281
|
+
try { verdict = await builder().verifySideChunked({ proof: accepted.proof, pub: { ed: accepted.edPub }, commitHalfClaimer: accepted.commitHalfClaimer }, context, accepted.sealed, ownEncPriv, options); }
|
|
282
|
+
catch { throw new SdkError("bad-input", { field: "counterparty" }); }
|
|
283
|
+
if (!verdict || verdict.ok !== true) {
|
|
284
|
+
throw new SdkError("quote-refused", { step: "proof", why: verdict && verdict.reason ? "rejected" : "unknown" });
|
|
285
|
+
}
|
|
286
|
+
return accepted;
|
|
287
|
+
}
|
|
288
|
+
|
|
226
289
|
/**
|
|
227
290
|
* THE ORDER STEP AS A WHOLE: your own side (or one already built by the record), the counterparty's side and the
|
|
228
291
|
* joint address. It hands out the fields the record and the recovery file are assembled from; NOT A SINGLE empty
|
|
229
292
|
* value: an address is not assembled without the other's point, and that is a refusal, not an empty string.
|
|
230
293
|
*/
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
const own = side
|
|
294
|
+
function ownSideOf({ order, side, context }) {
|
|
295
|
+
return side
|
|
234
296
|
? { context, side, spendPoint: norm(side.pub && side.pub.ed), viewPoint: norm(side.viewPub),
|
|
235
297
|
encPub: norm(side.enc && side.enc.pub ? side.enc.pub : null) }
|
|
236
298
|
: buildOwnSide(order);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function checkOwnSide(own) {
|
|
237
302
|
const lack = [];
|
|
238
303
|
if (own.side.half === undefined || own.side.half === null) lack.push("half");
|
|
239
304
|
if (own.side.viewHalf === undefined || own.side.viewHalf === null) lack.push("viewHalf");
|
|
240
305
|
if (!isPoint(own.spendPoint)) lack.push("spendPoint");
|
|
241
306
|
if (!isPoint(own.viewPoint)) lack.push("viewPoint");
|
|
242
307
|
if (lack.length) throw new SdkError("bad-input", { field: "side", missing: lack });
|
|
308
|
+
}
|
|
243
309
|
|
|
244
|
-
|
|
310
|
+
function orderStepResult({ own, other, network }) {
|
|
245
311
|
const otherViewPoint = other.viewPoint || (other.viewHalf ? norm(builder().pointOf(other.viewHalf)) : null);
|
|
246
312
|
if (!otherViewPoint) throw new SdkError("bad-input", { field: "counterparty", missing: ["viewPoint"] });
|
|
247
313
|
|
|
@@ -279,3 +345,25 @@ export function orderStep({ order, side = null, counterparty = null, standIn = f
|
|
|
279
345
|
},
|
|
280
346
|
};
|
|
281
347
|
}
|
|
348
|
+
|
|
349
|
+
export function orderStep({ order, side = null, counterparty = null, standIn = false, network = null }) {
|
|
350
|
+
const context = contextOf(order);
|
|
351
|
+
const own = ownSideOf({ order, side, context });
|
|
352
|
+
checkOwnSide(own);
|
|
353
|
+
const other = acceptCounterparty({ context: own.context, side: own.side, counterparty, standIn });
|
|
354
|
+
return orderStepResult({ own, other, network });
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* THE CHUNKED ORDER STEP. Same steps and same result object as `orderStep`, but the proof and the verification
|
|
359
|
+
* yield to the event loop. It exists for a browser that must keep painting; it is not a second rule set.
|
|
360
|
+
*/
|
|
361
|
+
export async function orderStepChunked({ order, side = null, counterparty = null, standIn = false, network = null, options = {} }) {
|
|
362
|
+
const context = contextOf(order);
|
|
363
|
+
const own = side
|
|
364
|
+
? ownSideOf({ order, side, context })
|
|
365
|
+
: await buildOwnSideChunked(order, options);
|
|
366
|
+
checkOwnSide(own);
|
|
367
|
+
const other = await acceptCounterpartyChunked({ context: own.context, side: own.side, counterparty, standIn, options });
|
|
368
|
+
return orderStepResult({ own, other, network });
|
|
369
|
+
}
|