@certen.io/sdk 0.8.2 → 0.10.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/CHANGELOG.md +103 -0
- package/README.md +81 -0
- package/dist/agent.d.ts +8 -0
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +12 -0
- package/dist/agent.js.map +1 -1
- package/dist/browser.d.ts +34 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +43 -0
- package/dist/browser.js.map +1 -0
- package/dist/bytes.d.ts +14 -0
- package/dist/bytes.d.ts.map +1 -0
- package/dist/bytes.js +47 -0
- package/dist/bytes.js.map +1 -0
- package/dist/chains.d.ts +198 -0
- package/dist/chains.d.ts.map +1 -0
- package/dist/chains.js +261 -0
- package/dist/chains.js.map +1 -0
- package/dist/client.d.ts +2 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +38 -6
- package/dist/client.js.map +1 -1
- package/dist/defaults.d.ts +3 -0
- package/dist/defaults.d.ts.map +1 -0
- package/dist/defaults.js +3 -0
- package/dist/defaults.js.map +1 -0
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +36 -23
- package/dist/doctor.js.map +1 -1
- package/dist/error-codes.d.ts.map +1 -1
- package/dist/error-codes.js +17 -0
- package/dist/error-codes.js.map +1 -1
- package/dist/errors.d.ts +76 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +108 -0
- package/dist/errors.js.map +1 -1
- package/dist/execution-proof.d.ts +111 -0
- package/dist/execution-proof.d.ts.map +1 -0
- package/dist/execution-proof.js +311 -0
- package/dist/execution-proof.js.map +1 -0
- package/dist/funding.d.ts +43 -6
- package/dist/funding.d.ts.map +1 -1
- package/dist/funding.js +69 -29
- package/dist/funding.js.map +1 -1
- package/dist/header-fields.d.ts +68 -0
- package/dist/header-fields.d.ts.map +1 -0
- package/dist/header-fields.js +147 -0
- package/dist/header-fields.js.map +1 -0
- package/dist/index.d.ts +9 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -23
- package/dist/index.js.map +1 -1
- package/dist/intent-states.d.ts +75 -0
- package/dist/intent-states.d.ts.map +1 -0
- package/dist/intent-states.js +66 -0
- package/dist/intent-states.js.map +1 -0
- package/dist/internal.d.ts +18 -0
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +44 -0
- package/dist/internal.js.map +1 -1
- package/dist/origin.d.ts +19 -0
- package/dist/origin.d.ts.map +1 -0
- package/dist/origin.js +80 -0
- package/dist/origin.js.map +1 -0
- package/dist/random.d.ts +27 -0
- package/dist/random.d.ts.map +1 -0
- package/dist/random.js +30 -0
- package/dist/random.js.map +1 -0
- package/dist/reason-codes.d.ts +15 -0
- package/dist/reason-codes.d.ts.map +1 -0
- package/dist/reason-codes.js +30 -0
- package/dist/reason-codes.js.map +1 -0
- package/dist/resources/admin.d.ts +5 -2
- package/dist/resources/admin.d.ts.map +1 -1
- package/dist/resources/admin.js +8 -3
- package/dist/resources/admin.js.map +1 -1
- package/dist/resources/billing.d.ts.map +1 -1
- package/dist/resources/billing.js +5 -4
- package/dist/resources/billing.js.map +1 -1
- package/dist/resources/chains.d.ts +10 -0
- package/dist/resources/chains.d.ts.map +1 -1
- package/dist/resources/chains.js +15 -1
- package/dist/resources/chains.js.map +1 -1
- package/dist/resources/device.d.ts.map +1 -1
- package/dist/resources/device.js +2 -1
- package/dist/resources/device.js.map +1 -1
- package/dist/resources/execute.d.ts +49 -4
- package/dist/resources/execute.d.ts.map +1 -1
- package/dist/resources/execute.js +108 -29
- package/dist/resources/execute.js.map +1 -1
- package/dist/resources/governance.js +3 -3
- package/dist/resources/governance.js.map +1 -1
- package/dist/resources/identity.js +5 -5
- package/dist/resources/identity.js.map +1 -1
- package/dist/resources/oauth-clients.d.ts.map +1 -1
- package/dist/resources/oauth-clients.js +3 -2
- package/dist/resources/oauth-clients.js.map +1 -1
- package/dist/resources/proof.d.ts +10 -2
- package/dist/resources/proof.d.ts.map +1 -1
- package/dist/resources/proof.js +33 -11
- package/dist/resources/proof.js.map +1 -1
- package/dist/resources/registration-tokens.d.ts.map +1 -1
- package/dist/resources/registration-tokens.js +2 -1
- package/dist/resources/registration-tokens.js.map +1 -1
- package/dist/resources/sign.js +2 -2
- package/dist/resources/sign.js.map +1 -1
- package/dist/resources/transaction.d.ts.map +1 -1
- package/dist/resources/transaction.js +7 -3
- package/dist/resources/transaction.js.map +1 -1
- package/dist/resources/transparency.d.ts.map +1 -1
- package/dist/resources/transparency.js +3 -2
- package/dist/resources/transparency.js.map +1 -1
- package/dist/resources/webhooks.d.ts +5 -3
- package/dist/resources/webhooks.d.ts.map +1 -1
- package/dist/resources/webhooks.js +12 -8
- package/dist/resources/webhooks.js.map +1 -1
- package/dist/sha256.d.ts +10 -0
- package/dist/sha256.d.ts.map +1 -0
- package/dist/sha256.js +71 -0
- package/dist/sha256.js.map +1 -0
- package/dist/share-target.d.ts +10 -0
- package/dist/share-target.d.ts.map +1 -0
- package/dist/share-target.js +25 -0
- package/dist/share-target.js.map +1 -0
- package/dist/shared-proof.d.ts +7 -5
- package/dist/shared-proof.d.ts.map +1 -1
- package/dist/shared-proof.js +36 -17
- package/dist/shared-proof.js.map +1 -1
- package/dist/signing-check.d.ts +66 -0
- package/dist/signing-check.d.ts.map +1 -0
- package/dist/signing-check.js +171 -0
- package/dist/signing-check.js.map +1 -0
- package/dist/types.d.ts +139 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/verify-receipt.d.ts.map +1 -1
- package/dist/verify-receipt.js +68 -28
- package/dist/verify-receipt.js.map +1 -1
- package/dist/verify.d.ts +82 -0
- package/dist/verify.d.ts.map +1 -0
- package/dist/verify.js +180 -0
- package/dist/verify.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +4 -0
- package/dist/version.js.map +1 -0
- package/package.json +25 -7
package/dist/shared-proof.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
import { gunzipSync } from 'node:zlib';
|
|
1
2
|
import axios from 'axios';
|
|
2
|
-
import {
|
|
3
|
+
import { parseShareTarget } from './share-target.js';
|
|
3
4
|
import { CertenError } from './errors.js';
|
|
5
|
+
import { apiPath } from './internal.js';
|
|
6
|
+
// Kept importable from here (the SDK index exports it from this module); it lives in share-target.ts so the browser-safe client does not
|
|
7
|
+
// have to load this file, which needs node:zlib to gunzip a bundle.
|
|
8
|
+
export { parseShareTarget } from './share-target.js';
|
|
4
9
|
/**
|
|
5
10
|
* Read a proof someone shared with you.
|
|
6
11
|
*
|
|
@@ -27,7 +32,7 @@ import { CertenError } from './errors.js';
|
|
|
27
32
|
export async function fetchSharedProof(tokenOrUrl, options = {}) {
|
|
28
33
|
const { token, baseUrl } = parseShareTarget(tokenOrUrl, options.baseUrl);
|
|
29
34
|
try {
|
|
30
|
-
const { data } = await axios.get(`${baseUrl.replace(/\/+$/, '')}
|
|
35
|
+
const { data } = await axios.get(`${baseUrl.replace(/\/+$/, '')}${apiPath `/v1/proof/shared/${token}`}`, {
|
|
31
36
|
timeout: options.timeoutMs ?? 30_000,
|
|
32
37
|
headers: { 'Content-Type': 'application/json' },
|
|
33
38
|
// No API key. See above — sending one would be harmless but misleading about what this
|
|
@@ -39,23 +44,37 @@ export async function fetchSharedProof(tokenOrUrl, options = {}) {
|
|
|
39
44
|
throw translate(err);
|
|
40
45
|
}
|
|
41
46
|
}
|
|
42
|
-
/**
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
/**
|
|
48
|
+
* The bundle as JSON. The share endpoint returns `bundle` as the stored bytes — serialized the
|
|
49
|
+
* way Node serializes a Buffer ({ type: 'Buffer', data: [...] }), sometimes gzip-compressed —
|
|
50
|
+
* and a counterparty should not have to know that. Returns null when the bytes are not JSON.
|
|
51
|
+
*/
|
|
52
|
+
export function decodeSharedBundle(bundle) {
|
|
53
|
+
if (bundle && typeof bundle === 'object' && !('data' in bundle) && ('proof_components' in bundle || 'bundle_id' in bundle)) {
|
|
54
|
+
return bundle;
|
|
55
|
+
}
|
|
56
|
+
let bytes = null;
|
|
57
|
+
if (bundle && typeof bundle === 'object' && Array.isArray(bundle.data))
|
|
58
|
+
bytes = Buffer.from(bundle.data);
|
|
59
|
+
else if (typeof bundle === 'string')
|
|
60
|
+
bytes = /^[A-Za-z0-9+/=]+$/.test(bundle) && !bundle.trim().startsWith('{') ? Buffer.from(bundle, 'base64') : Buffer.from(bundle, 'utf8');
|
|
61
|
+
if (!bytes)
|
|
62
|
+
return null;
|
|
63
|
+
let out = bytes;
|
|
64
|
+
if (out[0] === 0x1f && out[1] === 0x8b) {
|
|
65
|
+
try {
|
|
66
|
+
out = gunzipSync(out);
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return null;
|
|
50
70
|
}
|
|
51
|
-
return {
|
|
52
|
-
token: decodeURIComponent(match[1]),
|
|
53
|
-
// The link's own origin wins over any configured default: a proof shared from one deployment
|
|
54
|
-
// must not be fetched from another, where the token means nothing.
|
|
55
|
-
baseUrl: baseUrlOverride ?? url.origin,
|
|
56
|
-
};
|
|
57
71
|
}
|
|
58
|
-
|
|
72
|
+
try {
|
|
73
|
+
return JSON.parse(out.toString('utf8'));
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
59
78
|
}
|
|
60
79
|
function translate(err) {
|
|
61
80
|
const axiosErr = err;
|
package/dist/shared-proof.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared-proof.js","sourceRoot":"","sources":["../src/shared-proof.ts"],"names":[],"mappings":"AAAA,OAAO,KAAqB,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"shared-proof.js","sourceRoot":"","sources":["../src/shared-proof.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,M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F;IAC/F,6FAA6F;IAC7F,gEAAgE;IAChE,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;QACnB,OAAO,IAAI,WAAW,CACpB,WAAW,IAAI,EAAE,KAAK,IAAI,oCAAoC,wBAAwB,EACtF,GAAG,EAAE,IAAI,EAAE,IAAI,IAAI,uBAAuB,CAC3C,CAAC;IACJ,CAAC;IACD,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;QACnB,OAAO,IAAI,WAAW,CACpB,gEAAgE,EAChE,GAAG,EAAE,WAAW,CACjB,CAAC;IACJ,CAAC;IACD,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,IAAI,WAAW,CACpB,WAAW,IAAI,EAAE,KAAK,IAAI,QAAQ,CAAC,OAAO,EAAE,EAC5C,MAAM,EAAE,IAAI,EAAE,IAAI,IAAI,YAAY,CACnC,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,WAAW,CAAC,WAAW,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,EAAE,eAAe,CAAC,CAAC;AAC5E,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check what a gateway asks you to sign, before you sign it.
|
|
3
|
+
*
|
|
4
|
+
* Every external-mode signature this SDK makes (`execute.contractCall`, `execute.transfer`, `execute.cosign`, `CertenAgent`'s governance
|
|
5
|
+
* operations, and the CLI's `--sign-with`) goes through here first. The gateway returns the unsigned transaction and the signature
|
|
6
|
+
* metadata beside `hash_to_sign`; `@certen.io/proof-verify` rebuilds the transaction, recomputes every hash, and compares what it
|
|
7
|
+
* would authorise with what the caller asked for. A disagreement throws `SIGNING_DATA_MISMATCH` naming the field; data the gateway did not
|
|
8
|
+
* send throws `SIGNING_DATA_ABSENT`; and nothing is signed either way. There is no option that signs without the check.
|
|
9
|
+
*
|
|
10
|
+
* The verifier is an OPTIONAL peer dependency, loaded on first use so the API client keeps its one runtime dependency. Signing without it
|
|
11
|
+
* installed is refused (`SIGNING_VERIFIER_UNAVAILABLE`), not waved through.
|
|
12
|
+
*/
|
|
13
|
+
import { CertenError } from './errors.js';
|
|
14
|
+
import type { Expectation, ExpectedLeg, ExpectedOperation, SigningSummary } from '@certen.io/proof-verify';
|
|
15
|
+
export type { Expectation, ExpectedLeg, ExpectedOperation, SigningSummary };
|
|
16
|
+
export declare const SIGNING_DATA_MISMATCH = "SIGNING_DATA_MISMATCH";
|
|
17
|
+
export declare const SIGNING_DATA_ABSENT = "SIGNING_DATA_ABSENT";
|
|
18
|
+
export declare const SIGNING_VERIFIER_UNAVAILABLE = "SIGNING_VERIFIER_UNAVAILABLE";
|
|
19
|
+
export declare const SIGNING_EXPECTATION_UNAVAILABLE = "SIGNING_EXPECTATION_UNAVAILABLE";
|
|
20
|
+
/** A signature was refused because what would be signed could not be shown to be what was asked for. `details` has `field`, `expected`, `actual`. */
|
|
21
|
+
export declare class CertenSigningDataError extends CertenError {
|
|
22
|
+
constructor(message: string, code: string, details?: Record<string, unknown>);
|
|
23
|
+
}
|
|
24
|
+
/** Whole units ("0.001") to base units, exactly. */
|
|
25
|
+
export declare function toBaseUnits(amount: string, decimals: number): string;
|
|
26
|
+
/** The legs a `{ legs: [...] }` intent must produce. A leg whose meaning the SDK cannot state is refused, not skipped. */
|
|
27
|
+
export declare function legsFromIntent(intent: Record<string, unknown>): Promise<ExpectedLeg[]>;
|
|
28
|
+
export interface IntentSigningContext {
|
|
29
|
+
intentId?: string;
|
|
30
|
+
adiUrl: string;
|
|
31
|
+
/** The intent as sent. */
|
|
32
|
+
intent: Record<string, unknown>;
|
|
33
|
+
signerPublicKey?: string;
|
|
34
|
+
signerKeyPage?: string;
|
|
35
|
+
additionalAuthorities?: string[];
|
|
36
|
+
expiresAt?: Date | string;
|
|
37
|
+
}
|
|
38
|
+
/** Before signing a new intent (`POST /v1/transaction`). */
|
|
39
|
+
export declare function checkIntentSigning(signingData: unknown, c: IntentSigningContext): Promise<SigningSummary>;
|
|
40
|
+
export interface CosignContext {
|
|
41
|
+
/** The existing transaction the signature is for. */
|
|
42
|
+
transactionHash: string;
|
|
43
|
+
signerPublicKey: string;
|
|
44
|
+
signerKeyPage: string;
|
|
45
|
+
vote: 'approve' | 'reject' | 'abstain';
|
|
46
|
+
}
|
|
47
|
+
/** Before co-signing a transaction that already exists (`POST /v1/sign`): its own hash, the vote, and the signer. */
|
|
48
|
+
export declare function checkCosigning(signingData: unknown, c: CosignContext): Promise<SigningSummary>;
|
|
49
|
+
export interface GovernanceSigningContext {
|
|
50
|
+
adiUrl: string;
|
|
51
|
+
operations: ExpectedOperation[];
|
|
52
|
+
signerPublicKey?: string;
|
|
53
|
+
signerKeyPage?: string;
|
|
54
|
+
}
|
|
55
|
+
/** Before signing a governance change (`POST /v1/governance`). */
|
|
56
|
+
export declare function checkGovernanceSigning(signingData: unknown, c: GovernanceSigningContext): Promise<SigningSummary>;
|
|
57
|
+
/**
|
|
58
|
+
* Rebuild and describe signing data without a request to compare it with: every hash is recomputed and must match, and the summary says what
|
|
59
|
+
* the signature would authorise. It cannot say whether that is what you meant, so it is for inspecting and for a person to read, and signing
|
|
60
|
+
* after it is the person's decision. `existing` is for a co-signature on a transaction that already exists.
|
|
61
|
+
*/
|
|
62
|
+
export declare function inspectSigningData(signingData: unknown, opts?: {
|
|
63
|
+
existing?: boolean;
|
|
64
|
+
signerPublicKey?: string;
|
|
65
|
+
}): Promise<SigningSummary>;
|
|
66
|
+
//# sourceMappingURL=signing-check.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signing-check.d.ts","sourceRoot":"","sources":["../src/signing-check.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAE3G,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,iBAAiB,EAAE,cAAc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,CAAC;CACxC;AAED,qHAAqH;AACrH,wBAAsB,cAAc,CAAC,WAAW,EAAE,OAAO,EAAE,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC,CAOpG;AAED,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,iBAAiB,EAAE,CAAC;IAChC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,kEAAkE;AAClE,wBAAsB,sBAAsB,CAAC,WAAW,EAAE,OAAO,EAAE,CAAC,EAAE,wBAAwB,GAAG,OAAO,CAAC,cAAc,CAAC,CAOvH;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,CAAC,WAAW,EAAE,OAAO,EAAE,IAAI,GAAE;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;IAAC,eAAe,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,OAAO,CAAC,cAAc,CAAC,CAEnJ"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check what a gateway asks you to sign, before you sign it.
|
|
3
|
+
*
|
|
4
|
+
* Every external-mode signature this SDK makes (`execute.contractCall`, `execute.transfer`, `execute.cosign`, `CertenAgent`'s governance
|
|
5
|
+
* operations, and the CLI's `--sign-with`) goes through here first. The gateway returns the unsigned transaction and the signature
|
|
6
|
+
* metadata beside `hash_to_sign`; `@certen.io/proof-verify` rebuilds the transaction, recomputes every hash, and compares what it
|
|
7
|
+
* would authorise with what the caller asked for. A disagreement throws `SIGNING_DATA_MISMATCH` naming the field; data the gateway did not
|
|
8
|
+
* send throws `SIGNING_DATA_ABSENT`; and nothing is signed either way. There is no option that signs without the check.
|
|
9
|
+
*
|
|
10
|
+
* The verifier is an OPTIONAL peer dependency, loaded on first use so the API client keeps its one runtime dependency. Signing without it
|
|
11
|
+
* installed is refused (`SIGNING_VERIFIER_UNAVAILABLE`), not waved through.
|
|
12
|
+
*/
|
|
13
|
+
import { CertenError } from './errors.js';
|
|
14
|
+
import { chainInfo } from './chains.js';
|
|
15
|
+
export const SIGNING_DATA_MISMATCH = 'SIGNING_DATA_MISMATCH';
|
|
16
|
+
export const SIGNING_DATA_ABSENT = 'SIGNING_DATA_ABSENT';
|
|
17
|
+
export const SIGNING_VERIFIER_UNAVAILABLE = 'SIGNING_VERIFIER_UNAVAILABLE';
|
|
18
|
+
export const SIGNING_EXPECTATION_UNAVAILABLE = 'SIGNING_EXPECTATION_UNAVAILABLE';
|
|
19
|
+
/** A signature was refused because what would be signed could not be shown to be what was asked for. `details` has `field`, `expected`, `actual`. */
|
|
20
|
+
export class CertenSigningDataError extends CertenError {
|
|
21
|
+
constructor(message, code, details) {
|
|
22
|
+
super(message, 0, code, details ? { details } : undefined);
|
|
23
|
+
this.name = 'CertenSigningDataError';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const VERIFIER_MODULE = '@certen.io/proof-verify';
|
|
27
|
+
let loaded;
|
|
28
|
+
async function verifier() {
|
|
29
|
+
// The specifier is not a literal on purpose: a browser bundle must not try to resolve the verifier (it uses node:crypto), and so does not.
|
|
30
|
+
// In a browser this fails at run time as SIGNING_VERIFIER_UNAVAILABLE: signing there is refused, not unchecked.
|
|
31
|
+
loaded ??= import(/* @vite-ignore */ VERIFIER_MODULE).catch((e) => {
|
|
32
|
+
loaded = undefined;
|
|
33
|
+
const missing = e && typeof e === 'object' && ['ERR_MODULE_NOT_FOUND', 'MODULE_NOT_FOUND'].includes(e.code ?? '');
|
|
34
|
+
throw new CertenSigningDataError(missing
|
|
35
|
+
? 'certen: refusing to sign. Checking what a gateway asks you to sign needs @certen.io/proof-verify (npm install @certen.io/proof-verify), and there is no option to sign without the check.'
|
|
36
|
+
: `certen: refusing to sign. The signing-data verifier could not be loaded: ${e instanceof Error ? e.message : String(e)}`, SIGNING_VERIFIER_UNAVAILABLE);
|
|
37
|
+
});
|
|
38
|
+
return loaded;
|
|
39
|
+
}
|
|
40
|
+
function asCertenError(v, e) {
|
|
41
|
+
if (e instanceof v.SigningDataMismatch) {
|
|
42
|
+
throw new CertenSigningDataError(`certen: ${e.message}`, SIGNING_DATA_MISMATCH, { field: e.field, expected: e.expected, actual: e.actual });
|
|
43
|
+
}
|
|
44
|
+
if (e instanceof v.SigningDataAbsent) {
|
|
45
|
+
throw new CertenSigningDataError(`certen: ${e.message}`, SIGNING_DATA_ABSENT, { missing: e.missing });
|
|
46
|
+
}
|
|
47
|
+
if (e instanceof v.AbiUnsupported) {
|
|
48
|
+
throw new CertenSigningDataError(`certen: refusing to sign. ${e.message}`, SIGNING_EXPECTATION_UNAVAILABLE);
|
|
49
|
+
}
|
|
50
|
+
throw e;
|
|
51
|
+
}
|
|
52
|
+
/** Run a check; a refusal is a CertenSigningDataError. */
|
|
53
|
+
async function run(f) {
|
|
54
|
+
const v = await verifier();
|
|
55
|
+
try {
|
|
56
|
+
return f(v);
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
return asCertenError(v, e);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const unavailable = (why) => {
|
|
63
|
+
throw new CertenSigningDataError(`certen: refusing to sign. ${why}`, SIGNING_EXPECTATION_UNAVAILABLE);
|
|
64
|
+
};
|
|
65
|
+
// ── expectations from a request ─────────────────────────────────────────────────────────────────────
|
|
66
|
+
/** Whole units ("0.001") to base units, exactly. */
|
|
67
|
+
export function toBaseUnits(amount, decimals) {
|
|
68
|
+
const m = /^(\d+)(?:\.(\d+))?$/.exec(amount);
|
|
69
|
+
if (!m)
|
|
70
|
+
return unavailable(`the amount ${JSON.stringify(amount)} is not a decimal number, so what it moves cannot be checked`);
|
|
71
|
+
const frac = m[2] ?? '';
|
|
72
|
+
if (frac.length > decimals)
|
|
73
|
+
return unavailable(`the amount ${amount} has more than ${decimals} decimal places`);
|
|
74
|
+
return (BigInt(m[1]) * 10n ** BigInt(decimals) + BigInt(frac.padEnd(decimals, '0') || '0')).toString();
|
|
75
|
+
}
|
|
76
|
+
async function legFromCall(call, chain, chainId) {
|
|
77
|
+
const id = chainId ?? chainInfo(chain)?.chainId;
|
|
78
|
+
if (id === undefined)
|
|
79
|
+
unavailable(`chain ${JSON.stringify(chain)} is not in the chain catalogue and no chainId was given, so the leg's chain cannot be checked`);
|
|
80
|
+
const v = await verifier();
|
|
81
|
+
let callData;
|
|
82
|
+
try {
|
|
83
|
+
callData = call.functionSignature ? v.encodeCall(call.functionSignature, call.args ?? []) : '0x';
|
|
84
|
+
}
|
|
85
|
+
catch (e) {
|
|
86
|
+
return asCertenError(v, e);
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
chainId: id,
|
|
90
|
+
target: call.target,
|
|
91
|
+
value: call.value ?? '0',
|
|
92
|
+
callData,
|
|
93
|
+
...(call.expectedEvents ? { expectedEvents: call.expectedEvents.map((e) => ({ contract: e.contract, topic0: e.topic0 })) } : {}),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/** The legs a `{ legs: [...] }` intent must produce. A leg whose meaning the SDK cannot state is refused, not skipped. */
|
|
97
|
+
export async function legsFromIntent(intent) {
|
|
98
|
+
const raw = intent.legs;
|
|
99
|
+
if (Array.isArray(raw)) {
|
|
100
|
+
const out = [];
|
|
101
|
+
for (const [i, l] of raw.entries()) {
|
|
102
|
+
const leg = (l ?? {});
|
|
103
|
+
const call = leg.contractCall;
|
|
104
|
+
if (call) {
|
|
105
|
+
out.push(await legFromCall(call, leg.chain, leg.chainId));
|
|
106
|
+
}
|
|
107
|
+
else if (leg.tokenAddress || leg.tokenSymbol) {
|
|
108
|
+
unavailable(`leg ${i + 1} moves a token; the token contract and its decimals are chosen downstream, so what it moves cannot be checked here`);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
const info = chainInfo((leg.chainId ?? leg.chain));
|
|
112
|
+
if (!info)
|
|
113
|
+
unavailable(`leg ${i + 1} names a chain outside the catalogue, so what it moves cannot be checked`);
|
|
114
|
+
out.push({ chainId: info.chainId, target: String(leg.toAddress ?? ''), value: toBaseUnits(String(leg.amount ?? ''), info.nativeDecimals), callData: '0x' });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return out;
|
|
118
|
+
}
|
|
119
|
+
if (intent.toChain && intent.toAddress && intent.amount !== undefined) {
|
|
120
|
+
if (intent.tokenSymbol && String(intent.tokenSymbol).toUpperCase() !== chainInfo(intent.toChain)?.nativeSymbol.toUpperCase()) {
|
|
121
|
+
unavailable('a token transfer\'s contract and decimals are chosen downstream, so what it moves cannot be checked here');
|
|
122
|
+
}
|
|
123
|
+
const info = chainInfo((intent.toChainId ?? intent.toChain));
|
|
124
|
+
if (!info)
|
|
125
|
+
return unavailable(`chain ${JSON.stringify(intent.toChain)} is not in the chain catalogue, so what the transfer moves cannot be checked`);
|
|
126
|
+
return [{ chainId: info.chainId, target: String(intent.toAddress), value: toBaseUnits(String(intent.amount), info.nativeDecimals), callData: '0x' }];
|
|
127
|
+
}
|
|
128
|
+
return unavailable('the intent has neither legs nor a transfer shape the SDK can state the meaning of');
|
|
129
|
+
}
|
|
130
|
+
/** Before signing a new intent (`POST /v1/transaction`). */
|
|
131
|
+
export async function checkIntentSigning(signingData, c) {
|
|
132
|
+
if (!c.adiUrl)
|
|
133
|
+
unavailable('the identity\'s ADI is not known, so where the intent must be written cannot be checked');
|
|
134
|
+
const legs = await legsFromIntent(c.intent);
|
|
135
|
+
return run((v) => v.verifySigningData(signingData, {
|
|
136
|
+
...(c.intentId ? { intentId: c.intentId } : {}),
|
|
137
|
+
adiUrl: c.adiUrl,
|
|
138
|
+
legs,
|
|
139
|
+
...(c.signerPublicKey ? { signerPublicKey: c.signerPublicKey } : {}),
|
|
140
|
+
...(c.signerKeyPage ? { signerKeyPage: c.signerKeyPage } : {}),
|
|
141
|
+
additionalAuthorities: c.additionalAuthorities ?? [],
|
|
142
|
+
...(c.expiresAt ? { expiresAt: c.expiresAt } : {}),
|
|
143
|
+
}));
|
|
144
|
+
}
|
|
145
|
+
/** Before co-signing a transaction that already exists (`POST /v1/sign`): its own hash, the vote, and the signer. */
|
|
146
|
+
export async function checkCosigning(signingData, c) {
|
|
147
|
+
return run((v) => v.verifySigningData(signingData, {
|
|
148
|
+
transactionHash: c.transactionHash.replace(/^acc:\/\//, '').match(/[0-9a-f]{64}/i)?.[0] ?? c.transactionHash,
|
|
149
|
+
signerPublicKey: c.signerPublicKey,
|
|
150
|
+
signerKeyPage: c.signerKeyPage,
|
|
151
|
+
vote: c.vote,
|
|
152
|
+
}, { existing: true }));
|
|
153
|
+
}
|
|
154
|
+
/** Before signing a governance change (`POST /v1/governance`). */
|
|
155
|
+
export async function checkGovernanceSigning(signingData, c) {
|
|
156
|
+
return run((v) => v.verifySigningData(signingData, {
|
|
157
|
+
adiUrl: c.adiUrl,
|
|
158
|
+
governance: c.operations,
|
|
159
|
+
...(c.signerPublicKey ? { signerPublicKey: c.signerPublicKey } : {}),
|
|
160
|
+
...(c.signerKeyPage ? { signerKeyPage: c.signerKeyPage } : {}),
|
|
161
|
+
}));
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Rebuild and describe signing data without a request to compare it with: every hash is recomputed and must match, and the summary says what
|
|
165
|
+
* the signature would authorise. It cannot say whether that is what you meant, so it is for inspecting and for a person to read, and signing
|
|
166
|
+
* after it is the person's decision. `existing` is for a co-signature on a transaction that already exists.
|
|
167
|
+
*/
|
|
168
|
+
export async function inspectSigningData(signingData, opts = {}) {
|
|
169
|
+
return run((v) => v.verifySigningData(signingData, opts.signerPublicKey ? { signerPublicKey: opts.signerPublicKey } : {}, { existing: opts.existing === true }));
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=signing-check.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signing-check.js","sourceRoot":"","sources":["../src/signing-check.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;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AE,CAAC,CAAC,CAAC;AACnK,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -272,8 +272,118 @@ export interface CreateTransactionParams {
|
|
|
272
272
|
signerKeyPage?: string;
|
|
273
273
|
/** Which SEAT on the page signs, 64 hex. Defaults to the identity's bound key. */
|
|
274
274
|
signerPublicKey?: string;
|
|
275
|
+
/** Extra header authorities (`acc://` key books, at most 8). Refused by default — see `HeaderFields`. */
|
|
276
|
+
additionalAuthorities?: string[];
|
|
277
|
+
/** Accumulate deadline. See `HeaderFields.expiresAt`. */
|
|
278
|
+
expiresAt?: string | Date;
|
|
275
279
|
idempotencyKey?: string;
|
|
276
280
|
}
|
|
281
|
+
/**
|
|
282
|
+
* Optional transaction-header fields accepted by every intent-opening call.
|
|
283
|
+
*
|
|
284
|
+
* Sent as `additional_authorities` and `expires_at`.
|
|
285
|
+
*/
|
|
286
|
+
export interface HeaderFields {
|
|
287
|
+
/**
|
|
288
|
+
* Key books (`acc://…`, at most 8) added to the Accumulate transaction header as authorities that
|
|
289
|
+
* must also sign. Lowercased and de-duplicated before sending.
|
|
290
|
+
*
|
|
291
|
+
* **The gateway refuses this by default** with HTTP 422 `HEADER_AUTHORITY_NOT_EXECUTABLE`
|
|
292
|
+
* (`CertenHeaderAuthorityNotExecutableError`): validators do not yet count a header authority's
|
|
293
|
+
* signature, so the intent would collect every signature and still never execute. Make a party
|
|
294
|
+
* that must co-sign an authority on the ACCOUNT instead.
|
|
295
|
+
*/
|
|
296
|
+
additionalAuthorities?: string[];
|
|
297
|
+
/**
|
|
298
|
+
* Deadline for the Accumulate transaction: a `Date`, or an RFC 3339 string with an offset. Must be
|
|
299
|
+
* 90 s to 7 days from now (the gateway's window is 60 s to 7 days; the SDK keeps a margin). If signatures are still missing when it passes, the intent ends
|
|
300
|
+
* `failed` with `reason_code: expired` and nothing executes, so no gas is spent. `expiresIn('30m')`
|
|
301
|
+
* builds one.
|
|
302
|
+
*/
|
|
303
|
+
expiresAt?: string | Date;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Why an intent ended where it did — `TransactionResponse.reason_code`.
|
|
307
|
+
*
|
|
308
|
+
* - `target_reverted` — CERTEN did everything; the destination contract rejected the call. A
|
|
309
|
+
* business outcome: retrying the identical call reverts again.
|
|
310
|
+
* - `policy_denied` — a required policy seat refused to sign.
|
|
311
|
+
* - `network_failed` — Accumulate or the execution network failed the transaction.
|
|
312
|
+
* - `post_submission_timeout` — submitted, but no outcome was observed in time.
|
|
313
|
+
* - `pre_submission_error` — the intent failed before it reached the network.
|
|
314
|
+
* - `expired` — the Accumulate deadline (`expires_at`) passed before every signature arrived.
|
|
315
|
+
* Nothing executed; no fee or gas is charged.
|
|
316
|
+
* - `expectation_unmet` — the call executed, but events it committed to (`expectedEvents`) are
|
|
317
|
+
* missing from the destination receipt. It is NOT a success.
|
|
318
|
+
*
|
|
319
|
+
* The response type also admits other strings: the gateway may add a value before this SDK knows
|
|
320
|
+
* it, and treating an unknown reason as impossible would be the wrong failure.
|
|
321
|
+
*/
|
|
322
|
+
export type TransactionReasonCode = 'target_reverted' | 'policy_denied' | 'network_failed' | 'post_submission_timeout' | 'pre_submission_error' | 'expired' | 'expectation_unmet';
|
|
323
|
+
/**
|
|
324
|
+
* What a `completed` intent's success rests on.
|
|
325
|
+
*
|
|
326
|
+
* - `proof_artifact` — the proof service returned an indexed CERTEN proof artifact.
|
|
327
|
+
* - `execution_observed` — execution was measured on the destination chain. For a contract call the
|
|
328
|
+
* gateway also checked the committed `expectedEvents` against the destination receipt; a mismatch
|
|
329
|
+
* ends `failed/expectation_unmet` instead of completing.
|
|
330
|
+
*
|
|
331
|
+
* Other strings are admitted for rows written by an older gateway.
|
|
332
|
+
*/
|
|
333
|
+
/**
|
|
334
|
+
* What a `completed` status rests on. `proof_artifact`: the validators produced an indexed proof
|
|
335
|
+
* (`proof_id`). `execution_observed`: the gateway observed the destination-chain settlement.
|
|
336
|
+
* `chain_receipt` appears only on legacy rows. Treat an unknown value as "completed" and read
|
|
337
|
+
* `proof_id` rather than branching on it.
|
|
338
|
+
*/
|
|
339
|
+
export type CompletionBasis = 'proof_artifact' | 'execution_observed' | 'chain_receipt';
|
|
340
|
+
/**
|
|
341
|
+
* Present on a read that looked the proof id up because it was not yet recorded. A null `proof_id`
|
|
342
|
+
* with `unavailable` is NOT "not anchored yet": the proof service failed to answer.
|
|
343
|
+
*/
|
|
344
|
+
export interface ProofLookup {
|
|
345
|
+
state: 'resolved' | 'not_found' | 'unavailable';
|
|
346
|
+
/** The proof service's HTTP status; null when it was unreachable. */
|
|
347
|
+
status?: number | null;
|
|
348
|
+
reason?: string;
|
|
349
|
+
}
|
|
350
|
+
/** One chain member's proof, as the validators recorded it. */
|
|
351
|
+
export interface ChainMemberProof {
|
|
352
|
+
chain_id: number;
|
|
353
|
+
/** For an intent on several chains: the indices of its request legs on this chain. */
|
|
354
|
+
legs?: number[];
|
|
355
|
+
proof_id: string;
|
|
356
|
+
proof_bundle_url?: string | null;
|
|
357
|
+
write_back_tx?: string | null;
|
|
358
|
+
}
|
|
359
|
+
export type ValidatorState = 'not_discovered' | 'in_progress' | 'awaiting_signatures' | 'settling' | 'settled' | 'refused' | 'failed' | 'unavailable' | 'executed_proof_pending' | 'executed_proof_unavailable';
|
|
360
|
+
/** One chain member as the validators recorded it. */
|
|
361
|
+
export interface ValidatorMember {
|
|
362
|
+
chain_id: number;
|
|
363
|
+
recorded?: boolean;
|
|
364
|
+
settlement?: 'settled' | 'reverted' | 'unobserved' | 'none' | null;
|
|
365
|
+
proof_cycle?: 'written' | 'failed' | 'proof_pending' | 'proof_unavailable' | 'refused' | null;
|
|
366
|
+
settlement_tx?: string | null;
|
|
367
|
+
write_back_tx?: string | null;
|
|
368
|
+
proof_id?: string | null;
|
|
369
|
+
proof_bundle_url?: string | null;
|
|
370
|
+
effects_proven?: boolean | null;
|
|
371
|
+
}
|
|
372
|
+
/** What the CERTEN validators recorded for an intent, followed until it is final. */
|
|
373
|
+
export interface ValidatorView {
|
|
374
|
+
state: ValidatorState;
|
|
375
|
+
/** When the validators entered this state, RFC 3339. */
|
|
376
|
+
since?: string;
|
|
377
|
+
/** Delivered on Accumulate and not discovered by the validators within the overdue window. */
|
|
378
|
+
overdue?: boolean;
|
|
379
|
+
/** Every chain member; null when the validators reported none. */
|
|
380
|
+
members?: ValidatorMember[] | null;
|
|
381
|
+
/** Set when the validators' final outcome contradicts how the gateway ended the intent. */
|
|
382
|
+
disagreement?: {
|
|
383
|
+
what: string;
|
|
384
|
+
since?: string;
|
|
385
|
+
} | null;
|
|
386
|
+
}
|
|
277
387
|
/** @deprecated The flat shape this described was never accepted by POST /v1/transaction. Use `intent`. */
|
|
278
388
|
export interface LegacyFlatTransactionParams {
|
|
279
389
|
identityId: string;
|
|
@@ -347,6 +457,23 @@ export interface TransactionResponse {
|
|
|
347
457
|
proof_id?: string | null;
|
|
348
458
|
proof_bundle_url?: string | null;
|
|
349
459
|
error_message?: string | null;
|
|
460
|
+
/**
|
|
461
|
+
* Why the intent ended where it did. Null while in flight or when no reason was recorded; absent
|
|
462
|
+
* on an older gateway. `describeReasonCode()` renders it for a person.
|
|
463
|
+
*/
|
|
464
|
+
reason_code?: TransactionReasonCode | (string & {}) | null;
|
|
465
|
+
/** Header authorities the intent was opened with, normalised by the gateway. */
|
|
466
|
+
additional_authorities?: string[] | null;
|
|
467
|
+
/** The Accumulate deadline the intent was opened with, RFC 3339. */
|
|
468
|
+
expires_at?: string | null;
|
|
469
|
+
/** What a `completed` status rests on. Null until completed. */
|
|
470
|
+
completion_basis?: CompletionBasis | (string & {}) | null;
|
|
471
|
+
/** Present when this read had to look the proof id up; tells "not anchored yet" from "proof service down". */
|
|
472
|
+
proof_lookup?: ProofLookup | null;
|
|
473
|
+
/** Every chain member's proof, one per chain the intent settles on. Empty until the validators produced one. */
|
|
474
|
+
proofs?: ChainMemberProof[];
|
|
475
|
+
/** What the validators recorded for this intent. Null until first observed. */
|
|
476
|
+
validator?: ValidatorView | null;
|
|
350
477
|
created_at: string;
|
|
351
478
|
updated_at?: string;
|
|
352
479
|
/** Null while the transaction is still in flight — the gateway has always sent a real null here. */
|
|
@@ -1297,6 +1424,18 @@ export interface ChainEntry {
|
|
|
1297
1424
|
explorer: string;
|
|
1298
1425
|
status: string;
|
|
1299
1426
|
contracts: Record<string, ContractEntry>;
|
|
1427
|
+
/**
|
|
1428
|
+
* The gateway's enable switch for this network, once it publishes one. `false` means listed but
|
|
1429
|
+
* not served; the SDK never offers such a chain. Absent on a gateway that predates the switch,
|
|
1430
|
+
* where being listed is what serving means.
|
|
1431
|
+
*/
|
|
1432
|
+
enabled?: boolean;
|
|
1433
|
+
/** Native gas token symbol (`ETH`, `TEL`), when the gateway publishes it. */
|
|
1434
|
+
nativeSymbol?: string;
|
|
1435
|
+
/** Native gas token decimals, when the gateway publishes it. */
|
|
1436
|
+
nativeDecimals?: number;
|
|
1437
|
+
/** Typical seconds per block, when the gateway publishes it. */
|
|
1438
|
+
blockSeconds?: number;
|
|
1300
1439
|
[key: string]: unknown;
|
|
1301
1440
|
}
|
|
1302
1441
|
export interface ChainsListResponse {
|