@codespar/sdk 0.10.11 → 0.12.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/README.md +72 -1
- package/dist/__tests__/abort.test.d.ts +2 -0
- package/dist/__tests__/abort.test.d.ts.map +1 -0
- package/dist/__tests__/abort.test.js +70 -0
- package/dist/__tests__/abort.test.js.map +1 -0
- package/dist/__tests__/api-client.test.d.ts +7 -0
- package/dist/__tests__/api-client.test.d.ts.map +1 -0
- package/dist/__tests__/api-client.test.js +286 -0
- package/dist/__tests__/api-client.test.js.map +1 -0
- package/dist/__tests__/close-timeout.test.d.ts +2 -0
- package/dist/__tests__/close-timeout.test.d.ts.map +1 -0
- package/dist/__tests__/close-timeout.test.js +57 -0
- package/dist/__tests__/close-timeout.test.js.map +1 -0
- package/dist/__tests__/codespar.test.js +32 -0
- package/dist/__tests__/codespar.test.js.map +1 -1
- package/dist/__tests__/connections-timeout.test.d.ts +2 -0
- package/dist/__tests__/connections-timeout.test.d.ts.map +1 -0
- package/dist/__tests__/connections-timeout.test.js +58 -0
- package/dist/__tests__/connections-timeout.test.js.map +1 -0
- package/dist/__tests__/fetch-timeout.test.d.ts +2 -0
- package/dist/__tests__/fetch-timeout.test.d.ts.map +1 -0
- package/dist/__tests__/fetch-timeout.test.js +137 -0
- package/dist/__tests__/fetch-timeout.test.js.map +1 -0
- package/dist/__tests__/loop.test.d.ts +2 -0
- package/dist/__tests__/loop.test.d.ts.map +1 -0
- package/dist/__tests__/loop.test.js +237 -0
- package/dist/__tests__/loop.test.js.map +1 -0
- package/dist/__tests__/mandate.test.d.ts +2 -0
- package/dist/__tests__/mandate.test.d.ts.map +1 -0
- package/dist/__tests__/mandate.test.js +141 -0
- package/dist/__tests__/mandate.test.js.map +1 -0
- package/dist/__tests__/openapi-snapshot.test.d.ts +13 -0
- package/dist/__tests__/openapi-snapshot.test.d.ts.map +1 -0
- package/dist/__tests__/openapi-snapshot.test.js +79 -0
- package/dist/__tests__/openapi-snapshot.test.js.map +1 -0
- package/dist/__tests__/shop.test.js +1 -1
- package/dist/__tests__/shop.test.js.map +1 -1
- package/dist/__tests__/stream-timeout.test.d.ts +2 -0
- package/dist/__tests__/stream-timeout.test.d.ts.map +1 -0
- package/dist/__tests__/stream-timeout.test.js +335 -0
- package/dist/__tests__/stream-timeout.test.js.map +1 -0
- package/dist/__tests__/wait-for-connections.test.d.ts +2 -0
- package/dist/__tests__/wait-for-connections.test.d.ts.map +1 -0
- package/dist/__tests__/wait-for-connections.test.js +94 -0
- package/dist/__tests__/wait-for-connections.test.js.map +1 -0
- package/dist/api/client.d.ts +56 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +221 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/types.d.ts +110 -0
- package/dist/api/types.d.ts.map +1 -0
- package/dist/api/types.js +10 -0
- package/dist/api/types.js.map +1 -0
- package/dist/errors.d.ts +5 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +9 -0
- package/dist/errors.js.map +1 -1
- package/dist/generated/openapi.d.ts +22004 -0
- package/dist/generated/openapi.d.ts.map +1 -0
- package/dist/generated/openapi.js +2 -0
- package/dist/generated/openapi.js.map +1 -0
- package/dist/generated/operations.d.ts +1084 -0
- package/dist/generated/operations.d.ts.map +1 -0
- package/dist/generated/operations.js +225 -0
- package/dist/generated/operations.js.map +1 -0
- package/dist/index.d.ts +24 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +46 -4
- package/dist/index.js.map +1 -1
- package/dist/internal/abort.d.ts +18 -0
- package/dist/internal/abort.d.ts.map +1 -0
- package/dist/internal/abort.js +42 -0
- package/dist/internal/abort.js.map +1 -0
- package/dist/internal/fetch.d.ts +23 -0
- package/dist/internal/fetch.d.ts.map +1 -0
- package/dist/internal/fetch.js +57 -0
- package/dist/internal/fetch.js.map +1 -0
- package/dist/mandate/index.d.ts +111 -0
- package/dist/mandate/index.d.ts.map +1 -0
- package/dist/mandate/index.js +217 -0
- package/dist/mandate/index.js.map +1 -0
- package/dist/session.d.ts +3 -2
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +343 -162
- package/dist/session.js.map +1 -1
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +4 -1
- package/dist/types.js.map +1 -1
- package/package.json +11 -3
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// LIMITATION: aborting/timing out only closes the client connection.
|
|
2
|
+
// It does NOT undo an upstream side effect the backend already
|
|
3
|
+
// dispatched (e.g. a Pix transfer / NF-e issuance). HTTP has no
|
|
4
|
+
// out-of-band cancel; the server only learns the socket closed. True
|
|
5
|
+
// cancellation of a side-effecting call needs a backend cancel
|
|
6
|
+
// endpoint or idempotency key. Tracked separately (not in R3).
|
|
7
|
+
import { mergeSignals, timeoutSignal } from "./abort.js";
|
|
8
|
+
import { TimeoutError } from "../errors.js";
|
|
9
|
+
/**
|
|
10
|
+
* Fail-fast validation for an effective per-call timeout (ms). Mirrors
|
|
11
|
+
* the Python client's normalize_timeout so both SDKs reject the same
|
|
12
|
+
* bad inputs (0, negative, NaN, Infinity, non-number) before a request
|
|
13
|
+
* starts, instead of producing an unpredictable timer.
|
|
14
|
+
*/
|
|
15
|
+
export function validateTimeout(ms) {
|
|
16
|
+
if (typeof ms !== "number" ||
|
|
17
|
+
Number.isNaN(ms) ||
|
|
18
|
+
!Number.isFinite(ms) ||
|
|
19
|
+
ms <= 0) {
|
|
20
|
+
throw new Error(`timeout must be a positive, finite number of milliseconds, got ${String(ms)}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* fetch() with a TOTAL timeout that covers body consumption too.
|
|
25
|
+
*
|
|
26
|
+
* The `consume` callback reads the body (`res.json()`/`res.text()`)
|
|
27
|
+
* while the timeout signal is still armed — a backend that returns
|
|
28
|
+
* headers and then stalls the body still hits the timeout instead of
|
|
29
|
+
* hanging forever. The timeout fires a TimeoutError; the caller's own
|
|
30
|
+
* signal aborting re-throws that signal's reason verbatim (a standard
|
|
31
|
+
* AbortError), so the two causes stay distinguishable.
|
|
32
|
+
*/
|
|
33
|
+
export async function fetchWithTimeout(url, init, opts, consume) {
|
|
34
|
+
validateTimeout(opts.timeout);
|
|
35
|
+
const t = timeoutSignal(opts.timeout);
|
|
36
|
+
const merged = mergeSignals([t.signal, opts.signal]);
|
|
37
|
+
try {
|
|
38
|
+
const res = await fetch(url, { ...init, signal: merged.signal });
|
|
39
|
+
// Body read stays inside the timeout/abort budget.
|
|
40
|
+
return await consume(res);
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
// Caller cancellation takes priority and propagates verbatim.
|
|
44
|
+
if (opts.signal?.aborted)
|
|
45
|
+
throw opts.signal.reason;
|
|
46
|
+
// Otherwise, if our timeout fired, surface a typed TimeoutError.
|
|
47
|
+
if (t.signal.aborted)
|
|
48
|
+
throw new TimeoutError(opts.timeout);
|
|
49
|
+
// Unrelated failure (network/DNS/etc.) — rethrow as-is.
|
|
50
|
+
throw err;
|
|
51
|
+
}
|
|
52
|
+
finally {
|
|
53
|
+
t.clear();
|
|
54
|
+
merged.cleanup();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../src/internal/fetch.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,+DAA+D;AAC/D,gEAAgE;AAChE,qEAAqE;AACrE,+DAA+D;AAC/D,+DAA+D;AAE/D,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAI5C;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,EAAU;IACxC,IACE,OAAO,EAAE,KAAK,QAAQ;QACtB,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAChB,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|
3
|
+
* `agent_kid`) are absent on V2 mandates and required on V3.
|
|
4
|
+
*/
|
|
5
|
+
export interface MandateFields {
|
|
6
|
+
format_version: number;
|
|
7
|
+
id: string;
|
|
8
|
+
agent_id: string;
|
|
9
|
+
type: "payment" | "subscription" | "delegation";
|
|
10
|
+
/** Decimal string without trailing zeros (e.g. "5000", "99.5"). */
|
|
11
|
+
amount: string;
|
|
12
|
+
currency: string;
|
|
13
|
+
/** ASCII-only, sorted lexicographically before encoding. */
|
|
14
|
+
purposes: string[];
|
|
15
|
+
/** UNIX seconds. */
|
|
16
|
+
expires_at: number;
|
|
17
|
+
max_amount?: string | null;
|
|
18
|
+
parent_id?: string | null;
|
|
19
|
+
denomination?: string | null;
|
|
20
|
+
secret_version: number;
|
|
21
|
+
/** V3-only. Reference to the proofed CPF/CNPJ (Celcoin KYC) the agent acts for. */
|
|
22
|
+
principal_kyc_ref?: string | null;
|
|
23
|
+
/** V3-only. The agent key id (`<agent_did>#<n>`) that signed this mandate. */
|
|
24
|
+
agent_kid?: string | null;
|
|
25
|
+
}
|
|
26
|
+
/** A decoded presentation token: the signed fields plus the signature envelope. */
|
|
27
|
+
export interface DecodedMandateToken {
|
|
28
|
+
mandate: MandateFields;
|
|
29
|
+
/** The org-HMAC hex digest. Present on every version; NOT offline-verifiable
|
|
30
|
+
* (it needs the org secret) — carried through for completeness. */
|
|
31
|
+
signature: string;
|
|
32
|
+
/** V3 envelope: Ed25519 signature by the agent key (base64url). */
|
|
33
|
+
agent_sig?: string;
|
|
34
|
+
/** V3 envelope: Ed25519 signature by the platform issuer key (base64url). */
|
|
35
|
+
issuer_sig?: string;
|
|
36
|
+
/** V3 envelope: the agent key id (`<agent_did>#<n>`) that produced agent_sig. */
|
|
37
|
+
kid?: string;
|
|
38
|
+
}
|
|
39
|
+
export type MandateDecodeResult = {
|
|
40
|
+
ok: true;
|
|
41
|
+
token: DecodedMandateToken;
|
|
42
|
+
} | {
|
|
43
|
+
ok: false;
|
|
44
|
+
error: "invalid_payload" | "mandate_format_unsupported";
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Decode a signed presentation token: base64url UTF-8 JSON of the mandate fields
|
|
48
|
+
* plus `signature` and — for V3 — the `agent_sig` / `issuer_sig` / `kid`
|
|
49
|
+
* envelope. Splits the envelope from the signed fields so `mandate` is exactly
|
|
50
|
+
* the field set the signatures cover. Does not verify anything.
|
|
51
|
+
*/
|
|
52
|
+
export declare function decodeMandateToken(token: string): MandateDecodeResult;
|
|
53
|
+
/**
|
|
54
|
+
* Reconstruct the canonical signing string the Ed25519 signatures cover.
|
|
55
|
+
*
|
|
56
|
+
* Field order (V3 = 14 fields, 13 `:` separators): V2's 12 fields then the two
|
|
57
|
+
* V3-only fields (principal_kyc_ref, agent_kid). Absent optionals render empty
|
|
58
|
+
* so the separator count is invariant. `purposes` is comma-joined after a
|
|
59
|
+
* lexicographic sort with escaping (`\` → `\\` first, then `,` → `\,`). Colons
|
|
60
|
+
* inside `agent_kid` (from `did:web`) are emitted verbatim — the string is a
|
|
61
|
+
* one-way serialization, never re-split. The V3 tail is appended only for
|
|
62
|
+
* `format_version >= 3`, so a V2 mandate reconstructs to its 12-field form.
|
|
63
|
+
*/
|
|
64
|
+
export declare function reconstructSigningString(f: Record<string, unknown>): string;
|
|
65
|
+
/**
|
|
66
|
+
* Verify an Ed25519 signature (base64url) over a signing string with only the
|
|
67
|
+
* raw 32-byte public key. Returns false — never throws — on malformed input.
|
|
68
|
+
*/
|
|
69
|
+
export declare function verifyEd25519(signingString: string, signatureB64url: string, pub: Buffer): boolean;
|
|
70
|
+
/** Strip the `#<fragment>` from an agent key id to recover the bare agent DID. */
|
|
71
|
+
export declare function agentDidFromKid(kid: string): string;
|
|
72
|
+
/** Per-signature outcome. `skipped` = present but no key supplied to check it. */
|
|
73
|
+
export type SignatureStatus = "verified" | "failed" | "skipped" | "absent";
|
|
74
|
+
export interface SignatureCheck {
|
|
75
|
+
present: boolean;
|
|
76
|
+
status: SignatureStatus;
|
|
77
|
+
/** The key id associated with the signature (agent kid; issuer has none). */
|
|
78
|
+
kid?: string;
|
|
79
|
+
}
|
|
80
|
+
export interface VerifyMandateOptions {
|
|
81
|
+
/** Raw 32-byte Ed25519 agent public key — hex string or bytes. */
|
|
82
|
+
agentPublicKey?: string | Uint8Array;
|
|
83
|
+
/** Raw 32-byte Ed25519 issuer (platform) public key — hex string or bytes. */
|
|
84
|
+
issuerPublicKey?: string | Uint8Array;
|
|
85
|
+
}
|
|
86
|
+
export interface MandateVerification {
|
|
87
|
+
/** True iff at least one carried signature verified and none failed. */
|
|
88
|
+
verified: boolean;
|
|
89
|
+
mandate: MandateFields;
|
|
90
|
+
/** The bare agent DID (kid without its `#fragment`), when present. */
|
|
91
|
+
agentDid?: string;
|
|
92
|
+
/** The agent key id from the envelope, when present. */
|
|
93
|
+
kid?: string;
|
|
94
|
+
agent: SignatureCheck;
|
|
95
|
+
issuer: SignatureCheck;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Offline-verify a V3 mandate presentation token against supplied public keys.
|
|
99
|
+
*
|
|
100
|
+
* Pure and network-free: you pass the agent and/or issuer public keys (from
|
|
101
|
+
* their did:web documents) and it checks the signatures the token carries. A
|
|
102
|
+
* signature with a supplied key that validates is `verified`; a supplied key
|
|
103
|
+
* that fails is `failed`; a carried signature with no supplied key is `skipped`;
|
|
104
|
+
* a signature the token doesn't carry is `absent`. `verified` is true iff at
|
|
105
|
+
* least one signature verified and none failed.
|
|
106
|
+
*
|
|
107
|
+
* Throws only on a token that cannot be decoded (so a caller can distinguish a
|
|
108
|
+
* malformed token from a well-formed but unverified one).
|
|
109
|
+
*/
|
|
110
|
+
export declare function verifyMandateToken(token: string, opts?: VerifyMandateOptions): MandateVerification;
|
|
111
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mandate/index.ts"],"names":[],"mappings":"AAw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;;;;;GAUG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CA0B3E;AAiBD;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,aAAa,EAAE,MAAM,EACrB,eAAe,EAAE,MAAM,EACvB,GAAG,EAAE,MAAM,GACV,OAAO,CAWT;AAcD,kFAAkF;AAClF,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAGnD;AAED,kFAAkF;AAClF,MAAM,MAAM,eAAe,GAAG,UAAU,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE3E,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,eAAe,CAAC;IACxB,6EAA6E;IAC7E,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,oBAAoB;IACnC,kEAAkE;IAClE,cAAc,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;IACrC,8EAA8E;IAC9E,eAAe,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;CACvC;AAED,MAAM,WAAW,mBAAmB;IAClC,wEAAwE;IACxE,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,aAAa,CAAC;IACvB,sEAAsE;IACtE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wDAAwD;IACxD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,cAAc,CAAC;IACtB,MAAM,EAAE,cAAc,CAAC;CACxB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,MAAM,EACb,IAAI,GAAE,oBAAyB,GAC9B,mBAAmB,CA2BrB"}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@codespar/sdk/mandate` — offline V3 mandate verification.
|
|
3
|
+
*
|
|
4
|
+
* A third party holding only a presentation token and a raw Ed25519 public key
|
|
5
|
+
* (from the agent's did:web document) can reconstruct the exact signing string
|
|
6
|
+
* and verify the agent + issuer signatures with `node:crypto` alone — no
|
|
7
|
+
* CodeSpar API call. This is the programmatic form of `codespar mandate verify`.
|
|
8
|
+
*
|
|
9
|
+
* Isolation: this lives on its own subpath export so the main SDK client stays
|
|
10
|
+
* free of `node:crypto` (edge/bundler safe). Import it explicitly:
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { verifyMandateToken } from "@codespar/sdk/mandate";
|
|
14
|
+
* const res = verifyMandateToken(token, { agentPublicKey, issuerPublicKey });
|
|
15
|
+
* if (!res.verified) throw new Error("mandate signature invalid");
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* The byte format is frozen by the shared `canonical.v3.fixture.json` (the same
|
|
19
|
+
* freeze the enterprise codec and the CLI pin), so all three impls stay in lock
|
|
20
|
+
* step. `node:crypto` is a Node builtin, not an npm dependency — the SDK's
|
|
21
|
+
* zero-runtime-dependency guarantee is intact.
|
|
22
|
+
*/
|
|
23
|
+
import { createPublicKey, verify as nodeVerify } from "node:crypto";
|
|
24
|
+
/**
|
|
25
|
+
* Decode a signed presentation token: base64url UTF-8 JSON of the mandate fields
|
|
26
|
+
* plus `signature` and — for V3 — the `agent_sig` / `issuer_sig` / `kid`
|
|
27
|
+
* envelope. Splits the envelope from the signed fields so `mandate` is exactly
|
|
28
|
+
* the field set the signatures cover. Does not verify anything.
|
|
29
|
+
*/
|
|
30
|
+
export function decodeMandateToken(token) {
|
|
31
|
+
let raw;
|
|
32
|
+
try {
|
|
33
|
+
raw = JSON.parse(Buffer.from(token, "base64url").toString("utf8"));
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return { ok: false, error: "invalid_payload" };
|
|
37
|
+
}
|
|
38
|
+
if (!raw || typeof raw !== "object") {
|
|
39
|
+
return { ok: false, error: "invalid_payload" };
|
|
40
|
+
}
|
|
41
|
+
const r = raw;
|
|
42
|
+
const version = r["format_version"];
|
|
43
|
+
if (typeof version !== "number" || !Number.isInteger(version) || version < 2) {
|
|
44
|
+
return { ok: false, error: "mandate_format_unsupported" };
|
|
45
|
+
}
|
|
46
|
+
if (!isValidMandateFields(r)) {
|
|
47
|
+
return { ok: false, error: "invalid_payload" };
|
|
48
|
+
}
|
|
49
|
+
const { signature, agent_sig, issuer_sig, kid, ...fields } = r;
|
|
50
|
+
if (typeof signature !== "string") {
|
|
51
|
+
return { ok: false, error: "invalid_payload" };
|
|
52
|
+
}
|
|
53
|
+
const decoded = { mandate: fields, signature };
|
|
54
|
+
if (typeof agent_sig === "string")
|
|
55
|
+
decoded.agent_sig = agent_sig;
|
|
56
|
+
if (typeof issuer_sig === "string")
|
|
57
|
+
decoded.issuer_sig = issuer_sig;
|
|
58
|
+
if (typeof kid === "string")
|
|
59
|
+
decoded.kid = kid;
|
|
60
|
+
return { ok: true, token: decoded };
|
|
61
|
+
}
|
|
62
|
+
function isValidMandateFields(r) {
|
|
63
|
+
if (typeof r["format_version"] !== "number")
|
|
64
|
+
return false;
|
|
65
|
+
if (typeof r["id"] !== "string")
|
|
66
|
+
return false;
|
|
67
|
+
if (typeof r["agent_id"] !== "string")
|
|
68
|
+
return false;
|
|
69
|
+
if (!["payment", "subscription", "delegation"].includes(r["type"]))
|
|
70
|
+
return false;
|
|
71
|
+
if (typeof r["amount"] !== "string")
|
|
72
|
+
return false;
|
|
73
|
+
if (typeof r["currency"] !== "string")
|
|
74
|
+
return false;
|
|
75
|
+
if (!Array.isArray(r["purposes"]))
|
|
76
|
+
return false;
|
|
77
|
+
if (typeof r["expires_at"] !== "number")
|
|
78
|
+
return false;
|
|
79
|
+
if (typeof r["secret_version"] !== "number")
|
|
80
|
+
return false;
|
|
81
|
+
if (r["format_version"] === 3) {
|
|
82
|
+
if (typeof r["principal_kyc_ref"] !== "string")
|
|
83
|
+
return false;
|
|
84
|
+
if (typeof r["agent_kid"] !== "string")
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Reconstruct the canonical signing string the Ed25519 signatures cover.
|
|
91
|
+
*
|
|
92
|
+
* Field order (V3 = 14 fields, 13 `:` separators): V2's 12 fields then the two
|
|
93
|
+
* V3-only fields (principal_kyc_ref, agent_kid). Absent optionals render empty
|
|
94
|
+
* so the separator count is invariant. `purposes` is comma-joined after a
|
|
95
|
+
* lexicographic sort with escaping (`\` → `\\` first, then `,` → `\,`). Colons
|
|
96
|
+
* inside `agent_kid` (from `did:web`) are emitted verbatim — the string is a
|
|
97
|
+
* one-way serialization, never re-split. The V3 tail is appended only for
|
|
98
|
+
* `format_version >= 3`, so a V2 mandate reconstructs to its 12-field form.
|
|
99
|
+
*/
|
|
100
|
+
export function reconstructSigningString(f) {
|
|
101
|
+
const esc = (s) => s.replace(/\\/g, "\\\\").replace(/,/g, "\\,");
|
|
102
|
+
const purposes = (f["purposes"] ?? [])
|
|
103
|
+
.slice()
|
|
104
|
+
.sort()
|
|
105
|
+
.map(esc)
|
|
106
|
+
.join(",");
|
|
107
|
+
const version = Number(f["format_version"]);
|
|
108
|
+
const parts = [
|
|
109
|
+
String(f["format_version"]),
|
|
110
|
+
f["id"],
|
|
111
|
+
f["agent_id"],
|
|
112
|
+
f["type"],
|
|
113
|
+
f["amount"],
|
|
114
|
+
f["currency"],
|
|
115
|
+
purposes,
|
|
116
|
+
String(f["expires_at"]),
|
|
117
|
+
f["max_amount"] ?? "",
|
|
118
|
+
f["parent_id"] ?? "",
|
|
119
|
+
f["denomination"] ?? "",
|
|
120
|
+
String(f["secret_version"]),
|
|
121
|
+
];
|
|
122
|
+
if (version >= 3) {
|
|
123
|
+
parts.push(f["principal_kyc_ref"] ?? "", f["agent_kid"] ?? "");
|
|
124
|
+
}
|
|
125
|
+
return parts.join(":");
|
|
126
|
+
}
|
|
127
|
+
// A raw Ed25519 public key becomes an SPKI KeyObject by prefixing the fixed
|
|
128
|
+
// RFC 8410 header. This is the exact wrapper a bare third-party verifier uses.
|
|
129
|
+
const ED25519_SPKI_PREFIX = Buffer.from("302a300506032b6570032100", "hex");
|
|
130
|
+
function publicKeyFromRaw(pub) {
|
|
131
|
+
if (pub.length !== 32) {
|
|
132
|
+
throw new Error(`Ed25519 public key must be 32 bytes, got ${pub.length}`);
|
|
133
|
+
}
|
|
134
|
+
return createPublicKey({
|
|
135
|
+
key: Buffer.concat([ED25519_SPKI_PREFIX, pub]),
|
|
136
|
+
format: "der",
|
|
137
|
+
type: "spki",
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Verify an Ed25519 signature (base64url) over a signing string with only the
|
|
142
|
+
* raw 32-byte public key. Returns false — never throws — on malformed input.
|
|
143
|
+
*/
|
|
144
|
+
export function verifyEd25519(signingString, signatureB64url, pub) {
|
|
145
|
+
try {
|
|
146
|
+
return nodeVerify(null, Buffer.from(signingString, "utf8"), publicKeyFromRaw(pub), Buffer.from(signatureB64url, "base64url"));
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/** Coerce a hex string (with/without 0x) or raw bytes into a 32-byte key, or null. */
|
|
153
|
+
function toPubkey(key) {
|
|
154
|
+
if (key === undefined)
|
|
155
|
+
return null;
|
|
156
|
+
if (typeof key === "string") {
|
|
157
|
+
const clean = key.trim().toLowerCase().replace(/^0x/, "");
|
|
158
|
+
if (clean.length !== 64 || !/^[0-9a-f]+$/.test(clean))
|
|
159
|
+
return null;
|
|
160
|
+
return Buffer.from(clean, "hex");
|
|
161
|
+
}
|
|
162
|
+
const buf = Buffer.from(key);
|
|
163
|
+
return buf.length === 32 ? buf : null;
|
|
164
|
+
}
|
|
165
|
+
/** Strip the `#<fragment>` from an agent key id to recover the bare agent DID. */
|
|
166
|
+
export function agentDidFromKid(kid) {
|
|
167
|
+
const hash = kid.indexOf("#");
|
|
168
|
+
return hash === -1 ? kid : kid.slice(0, hash);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Offline-verify a V3 mandate presentation token against supplied public keys.
|
|
172
|
+
*
|
|
173
|
+
* Pure and network-free: you pass the agent and/or issuer public keys (from
|
|
174
|
+
* their did:web documents) and it checks the signatures the token carries. A
|
|
175
|
+
* signature with a supplied key that validates is `verified`; a supplied key
|
|
176
|
+
* that fails is `failed`; a carried signature with no supplied key is `skipped`;
|
|
177
|
+
* a signature the token doesn't carry is `absent`. `verified` is true iff at
|
|
178
|
+
* least one signature verified and none failed.
|
|
179
|
+
*
|
|
180
|
+
* Throws only on a token that cannot be decoded (so a caller can distinguish a
|
|
181
|
+
* malformed token from a well-formed but unverified one).
|
|
182
|
+
*/
|
|
183
|
+
export function verifyMandateToken(token, opts = {}) {
|
|
184
|
+
const decoded = decodeMandateToken(token);
|
|
185
|
+
if (!decoded.ok) {
|
|
186
|
+
throw new Error(`cannot decode mandate token: ${decoded.error}`);
|
|
187
|
+
}
|
|
188
|
+
const t = decoded.token;
|
|
189
|
+
const m = t.mandate;
|
|
190
|
+
const signingString = reconstructSigningString(m);
|
|
191
|
+
const kid = t.kid ?? m.agent_kid ?? undefined;
|
|
192
|
+
const agentDid = kid ? agentDidFromKid(kid) : undefined;
|
|
193
|
+
const agent = checkSignature(signingString, t.agent_sig, toPubkey(opts.agentPublicKey), kid);
|
|
194
|
+
const issuer = checkSignature(signingString, t.issuer_sig, toPubkey(opts.issuerPublicKey), undefined);
|
|
195
|
+
const anyVerified = agent.status === "verified" || issuer.status === "verified";
|
|
196
|
+
const anyFailed = agent.status === "failed" || issuer.status === "failed";
|
|
197
|
+
const result = {
|
|
198
|
+
verified: anyVerified && !anyFailed,
|
|
199
|
+
mandate: m,
|
|
200
|
+
agent,
|
|
201
|
+
issuer,
|
|
202
|
+
};
|
|
203
|
+
if (agentDid)
|
|
204
|
+
result.agentDid = agentDid;
|
|
205
|
+
if (kid)
|
|
206
|
+
result.kid = kid;
|
|
207
|
+
return result;
|
|
208
|
+
}
|
|
209
|
+
function checkSignature(signingString, sig, pub, kid) {
|
|
210
|
+
if (!sig)
|
|
211
|
+
return { present: false, status: "absent", ...(kid ? { kid } : {}) };
|
|
212
|
+
if (!pub)
|
|
213
|
+
return { present: true, status: "skipped", ...(kid ? { kid } : {}) };
|
|
214
|
+
const ok = verifyEd25519(signingString, sig, pub);
|
|
215
|
+
return { present: true, status: ok ? "verified" : "failed", ...(kid ? { kid } : {}) };
|
|
216
|
+
}
|
|
217
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mandate/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,IAAI,UAAU,EAAkB,MAAM,aAAa,CAAC;AA8CpF;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAa;IAC9C,IAAI,GAAY,CAAC;IACjB,IAAI,CAAC;QACH,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;IACrE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,iBAAiB,EAAE,CAAC;IACjD,CAAC;IACD,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QACpC,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,iBAAiB,EAAE,CAAC;IACjD,CAAC;IAED,MAAM,CAAC,GAAG,GAA8B,CAAC;IACzC,MAAM,OAAO,GAAG,CAAC,CAAC,gBAAgB,CAAC,CAAC;IACpC,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,OAAO,G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QAAE,MAAM,CAAC,GAAG,GAAG,GAAG,CAAC;IAC1B,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,cAAc,CACrB,aAAqB,EACrB,GAAuB,EACvB,GAAkB,EAClB,GAAuB;IAEvB,IAAI,CAAC,GAAG;QAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;IAC/E,IAAI,CAAC,GAAG;QAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;IAC/E,MAAM,EAAE,GAAG,aAAa,CAAC,aAAa,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IAClD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;AACxF,CAAC"}
|
package/dist/session.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Session implementation for the CodeSpar managed runtime.
|
|
3
3
|
*/
|
|
4
|
-
import type { SessionConfig } from "./types.js";
|
|
4
|
+
import type { SessionConfig, CallOptions } from "./types.js";
|
|
5
5
|
import type { Session } from "@codespar/types";
|
|
6
6
|
interface SessionDeps {
|
|
7
7
|
baseUrl: string;
|
|
8
8
|
apiKey: string;
|
|
9
9
|
projectId?: string;
|
|
10
|
+
timeout: number;
|
|
10
11
|
}
|
|
11
|
-
export declare function createSession(userId: string, config: SessionConfig, deps: SessionDeps): Promise<Session>;
|
|
12
|
+
export declare function createSession(userId: string, config: SessionConfig, deps: SessionDeps, createOpts?: CallOptions): Promise<Session>;
|
|
12
13
|
export {};
|
|
13
14
|
//# sourceMappingURL=session.d.ts.map
|
package/dist/session.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAQ,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAQ,WAAW,EAAE,MAAM,YAAY,CAAC;AAGnE,OAAO,KAAK,EACV,OAAO,EA4BR,MAAM,iBAAiB,CAAC;AAEzB,UAAU,WAAW;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CACjB;AA6CD,wBAAsB,aAAa,CACjC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,aAAa,EACrB,IAAI,EAAE,WAAW,EACjB,UAAU,CAAC,EAAE,WAAW,GACvB,OAAO,CAAC,OAAO,CAAC,CA6iBlB"}
|