@certen.io/sdk 0.5.0 → 0.7.1
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 +599 -0
- package/README.md +133 -119
- package/dist/client.d.ts +96 -6
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +258 -20
- package/dist/client.js.map +1 -1
- package/dist/doctor.d.ts +53 -0
- package/dist/doctor.d.ts.map +1 -0
- package/dist/doctor.js +451 -0
- package/dist/doctor.js.map +1 -0
- package/dist/error-codes.d.ts +14 -0
- package/dist/error-codes.d.ts.map +1 -0
- package/dist/error-codes.js +55 -0
- package/dist/error-codes.js.map +1 -0
- package/dist/errors.d.ts +13 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +18 -1
- package/dist/errors.js.map +1 -1
- package/dist/funding.d.ts +43 -0
- package/dist/funding.d.ts.map +1 -0
- package/dist/funding.js +116 -0
- package/dist/funding.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -1
- package/dist/oauth.d.ts +56 -0
- package/dist/oauth.d.ts.map +1 -0
- package/dist/oauth.js +68 -0
- package/dist/oauth.js.map +1 -0
- package/dist/registration.d.ts +33 -0
- package/dist/registration.d.ts.map +1 -0
- package/dist/registration.js +49 -0
- package/dist/registration.js.map +1 -0
- package/dist/resources/admin.d.ts +52 -1
- package/dist/resources/admin.d.ts.map +1 -1
- package/dist/resources/admin.js +55 -0
- package/dist/resources/admin.js.map +1 -1
- package/dist/resources/billing.d.ts +198 -19
- package/dist/resources/billing.d.ts.map +1 -1
- package/dist/resources/billing.js +297 -7
- package/dist/resources/billing.js.map +1 -1
- package/dist/resources/chains.d.ts +38 -0
- package/dist/resources/chains.d.ts.map +1 -0
- package/dist/resources/chains.js +46 -0
- package/dist/resources/chains.js.map +1 -0
- package/dist/resources/device.d.ts +43 -0
- package/dist/resources/device.d.ts.map +1 -0
- package/dist/resources/device.js +49 -0
- package/dist/resources/device.js.map +1 -0
- package/dist/resources/execute.d.ts +10 -0
- package/dist/resources/execute.d.ts.map +1 -1
- package/dist/resources/execute.js +28 -6
- package/dist/resources/execute.js.map +1 -1
- package/dist/resources/health.d.ts +34 -0
- package/dist/resources/health.d.ts.map +1 -0
- package/dist/resources/health.js +43 -0
- package/dist/resources/health.js.map +1 -0
- package/dist/resources/identity.d.ts +83 -2
- package/dist/resources/identity.d.ts.map +1 -1
- package/dist/resources/identity.js +154 -2
- package/dist/resources/identity.js.map +1 -1
- package/dist/resources/oauth-clients.d.ts +71 -0
- package/dist/resources/oauth-clients.d.ts.map +1 -0
- package/dist/resources/oauth-clients.js +75 -0
- package/dist/resources/oauth-clients.js.map +1 -0
- package/dist/resources/pending.d.ts +13 -1
- package/dist/resources/pending.d.ts.map +1 -1
- package/dist/resources/pending.js +15 -0
- package/dist/resources/pending.js.map +1 -1
- package/dist/resources/proof.d.ts +82 -0
- package/dist/resources/proof.d.ts.map +1 -0
- package/dist/resources/proof.js +112 -0
- package/dist/resources/proof.js.map +1 -0
- package/dist/resources/registration-tokens.d.ts +51 -0
- package/dist/resources/registration-tokens.d.ts.map +1 -0
- package/dist/resources/registration-tokens.js +54 -0
- package/dist/resources/registration-tokens.js.map +1 -0
- package/dist/resources/sign.d.ts.map +1 -1
- package/dist/resources/sign.js +12 -7
- package/dist/resources/sign.js.map +1 -1
- package/dist/resources/transaction.d.ts +20 -0
- package/dist/resources/transaction.d.ts.map +1 -1
- package/dist/resources/transaction.js +28 -0
- package/dist/resources/transaction.js.map +1 -1
- package/dist/resources/transparency.d.ts +68 -0
- package/dist/resources/transparency.d.ts.map +1 -0
- package/dist/resources/transparency.js +83 -0
- package/dist/resources/transparency.js.map +1 -0
- package/dist/resources/webhooks.d.ts +97 -0
- package/dist/resources/webhooks.d.ts.map +1 -0
- package/dist/resources/webhooks.js +112 -0
- package/dist/resources/webhooks.js.map +1 -0
- package/dist/self-signup.d.ts +66 -0
- package/dist/self-signup.d.ts.map +1 -0
- package/dist/self-signup.js +76 -0
- package/dist/self-signup.js.map +1 -0
- package/dist/shared-proof.d.ts +34 -0
- package/dist/shared-proof.d.ts.map +1 -0
- package/dist/shared-proof.js +78 -0
- package/dist/shared-proof.js.map +1 -0
- package/dist/sign-target.d.ts +34 -0
- package/dist/sign-target.d.ts.map +1 -0
- package/dist/sign-target.js +41 -0
- package/dist/sign-target.js.map +1 -0
- package/dist/types.d.ts +831 -22
- package/dist/types.d.ts.map +1 -1
- package/dist/verify-receipt.d.ts +32 -0
- package/dist/verify-receipt.d.ts.map +1 -0
- package/dist/verify-receipt.js +176 -0
- package/dist/verify-receipt.js.map +1 -0
- package/package.json +4 -3
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { SignupChallenge, RedeemedRegistration } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Provisioning an organization by proving you hold a key — no browser, no email, nobody at CERTEN.
|
|
4
|
+
*
|
|
5
|
+
* CERTEN is non-custodial: we never hold a customer's keys. A signup that required a human — ours
|
|
6
|
+
* in an approvals queue, theirs in a browser, or an existing customer handing over a registration
|
|
7
|
+
* token — contradicted that, and made CERTEN a friction point in the one flow where it should be
|
|
8
|
+
* invisible.
|
|
9
|
+
*
|
|
10
|
+
* The anchor is an Ed25519 keypair, which is free to create, impossible for us to hold, needs no
|
|
11
|
+
* inbox, and is a credential the caller needs anyway: every CERTEN identity is an Ed25519 key. One
|
|
12
|
+
* step does two jobs.
|
|
13
|
+
*
|
|
14
|
+
* Standalone rather than client methods, for the reason that recurs across this SDK: the caller
|
|
15
|
+
* holds no credential, and obtaining the first one is the entire purpose.
|
|
16
|
+
*/
|
|
17
|
+
interface Endpoint {
|
|
18
|
+
/** Defaults to the SDK's configured gateway. */
|
|
19
|
+
baseUrl?: string;
|
|
20
|
+
timeoutMs?: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Ask for a nonce to sign.
|
|
24
|
+
*
|
|
25
|
+
* Pass `publicKey` — it binds the challenge to your key, so nobody who observes the nonce in flight
|
|
26
|
+
* can answer it with their own.
|
|
27
|
+
*/
|
|
28
|
+
export declare function requestSignupChallenge(publicKey?: string, options?: Endpoint): Promise<SignupChallenge>;
|
|
29
|
+
/**
|
|
30
|
+
* Answer a challenge and receive a new organization with its first API key.
|
|
31
|
+
*
|
|
32
|
+
* `signature` is a DETACHED Ed25519 signature over the raw bytes of the nonce — decode the hex
|
|
33
|
+
* first. Signing the hex text instead is the one mistake worth calling out, and the gateway says so
|
|
34
|
+
* explicitly when it happens.
|
|
35
|
+
*
|
|
36
|
+
* **The API key is returned once.** The nonce is spent by this call whether or not it succeeded, so
|
|
37
|
+
* a retry needs a fresh challenge.
|
|
38
|
+
*/
|
|
39
|
+
export declare function completeSignup(params: {
|
|
40
|
+
publicKey: string;
|
|
41
|
+
nonce: string;
|
|
42
|
+
signature: string;
|
|
43
|
+
orgName?: string;
|
|
44
|
+
}, options?: Endpoint): Promise<RedeemedRegistration>;
|
|
45
|
+
/**
|
|
46
|
+
* Both steps, for a caller that can sign.
|
|
47
|
+
*
|
|
48
|
+
* ```ts
|
|
49
|
+
* const { org, api_key } = await selfSignup({
|
|
50
|
+
* publicKey: myPublicKeyHex,
|
|
51
|
+
* sign: (nonceHex) => signWithMyKey(nonceHex), // detached ed25519 over the nonce BYTES
|
|
52
|
+
* orgName: 'my-agent',
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* `sign` receives the nonce as hex and must return the signature as hex. That signature is made
|
|
57
|
+
* with a private key this SDK never sees — which is the point, and why signing is a callback rather
|
|
58
|
+
* than a key parameter.
|
|
59
|
+
*/
|
|
60
|
+
export declare function selfSignup(params: {
|
|
61
|
+
publicKey: string;
|
|
62
|
+
sign: (nonceHex: string) => string | Promise<string>;
|
|
63
|
+
orgName?: string;
|
|
64
|
+
}, options?: Endpoint): Promise<RedeemedRegistration>;
|
|
65
|
+
export {};
|
|
66
|
+
//# sourceMappingURL=self-signup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"self-signup.d.ts","sourceRoot":"","sources":["../src/self-signup.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAExE;;;;;;;;;;;;;;GAcG;AAEH,UAAU,QAAQ;IAChB,gDAAgD;IAChD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAcD;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAC1C,SAAS,CAAC,EAAE,MAAM,EAClB,OAAO,GAAE,QAAa,GACrB,OAAO,CAAC,eAAe,CAAC,CAY1B;AAED;;;;;;;;;GASG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,EACjF,OAAO,GAAE,QAAa,GACrB,OAAO,CAAC,oBAAoB,CAAC,CAiB/B;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,UAAU,CAC9B,MAAM,EAAE;IACN,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACrD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,EACD,OAAO,GAAE,QAAa,GACrB,OAAO,CAAC,oBAAoB,CAAC,CAY/B"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { DEFAULT_BASE_URL } from './client.js';
|
|
3
|
+
import { CertenError } from './errors.js';
|
|
4
|
+
function fail(err, fallbackCode) {
|
|
5
|
+
const e = err;
|
|
6
|
+
const status = e.response?.status ?? 0;
|
|
7
|
+
const payload = e.response?.data;
|
|
8
|
+
throw new CertenError(`certen: ${payload?.error ?? e.message}`, status, payload?.code ?? (status ? fallbackCode : 'NETWORK_ERROR'), { body: payload });
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Ask for a nonce to sign.
|
|
12
|
+
*
|
|
13
|
+
* Pass `publicKey` — it binds the challenge to your key, so nobody who observes the nonce in flight
|
|
14
|
+
* can answer it with their own.
|
|
15
|
+
*/
|
|
16
|
+
export async function requestSignupChallenge(publicKey, options = {}) {
|
|
17
|
+
const base = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, '');
|
|
18
|
+
try {
|
|
19
|
+
const { data } = await axios.post(`${base}/v1/signup/challenge`, publicKey ? { public_key: publicKey } : {}, { timeout: options.timeoutMs ?? 30_000, headers: { 'Content-Type': 'application/json' } });
|
|
20
|
+
return data;
|
|
21
|
+
}
|
|
22
|
+
catch (err) {
|
|
23
|
+
return fail(err, 'SIGNUP_CHALLENGE_FAILED');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Answer a challenge and receive a new organization with its first API key.
|
|
28
|
+
*
|
|
29
|
+
* `signature` is a DETACHED Ed25519 signature over the raw bytes of the nonce — decode the hex
|
|
30
|
+
* first. Signing the hex text instead is the one mistake worth calling out, and the gateway says so
|
|
31
|
+
* explicitly when it happens.
|
|
32
|
+
*
|
|
33
|
+
* **The API key is returned once.** The nonce is spent by this call whether or not it succeeded, so
|
|
34
|
+
* a retry needs a fresh challenge.
|
|
35
|
+
*/
|
|
36
|
+
export async function completeSignup(params, options = {}) {
|
|
37
|
+
const base = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, '');
|
|
38
|
+
try {
|
|
39
|
+
const { data } = await axios.post(`${base}/v1/signup`, {
|
|
40
|
+
public_key: params.publicKey,
|
|
41
|
+
nonce: params.nonce,
|
|
42
|
+
signature: params.signature,
|
|
43
|
+
...(params.orgName ? { org_name: params.orgName } : {}),
|
|
44
|
+
}, { timeout: options.timeoutMs ?? 30_000, headers: { 'Content-Type': 'application/json' } });
|
|
45
|
+
return data;
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
return fail(err, 'SIGNUP_FAILED');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Both steps, for a caller that can sign.
|
|
53
|
+
*
|
|
54
|
+
* ```ts
|
|
55
|
+
* const { org, api_key } = await selfSignup({
|
|
56
|
+
* publicKey: myPublicKeyHex,
|
|
57
|
+
* sign: (nonceHex) => signWithMyKey(nonceHex), // detached ed25519 over the nonce BYTES
|
|
58
|
+
* orgName: 'my-agent',
|
|
59
|
+
* });
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* `sign` receives the nonce as hex and must return the signature as hex. That signature is made
|
|
63
|
+
* with a private key this SDK never sees — which is the point, and why signing is a callback rather
|
|
64
|
+
* than a key parameter.
|
|
65
|
+
*/
|
|
66
|
+
export async function selfSignup(params, options = {}) {
|
|
67
|
+
const challenge = await requestSignupChallenge(params.publicKey, options);
|
|
68
|
+
const signature = await params.sign(challenge.nonce);
|
|
69
|
+
return completeSignup({
|
|
70
|
+
publicKey: params.publicKey,
|
|
71
|
+
nonce: challenge.nonce,
|
|
72
|
+
signature,
|
|
73
|
+
orgName: params.orgName,
|
|
74
|
+
}, options);
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=self-signup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"self-signup.js","sourceRoot":"","sources":["../src/self-signup.ts"],"names":[],"mappings":"AAAA,OAAO,KAAqB,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAyB1C,SAAS,IAAI,CAAC,GAAY,EAAE,YAAoB;IAC9C,MAAM,CAAC,GAAG,GAAoD,CAAC;IAC/D,MA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AAE,CAAC,CAAC;IACvE,IAAI,CAAC;QACH,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,KAAK,CAAC,IAAI,CAC/B,GAAG,IAAI,YAAY,EACnB;YACE,UAAU,EAAE,MAAM,CAAC,SAAS;YAC5B,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACxD,EACD,EAAE,OAAO,EAAE,OAAO,CAAC,SAAS,IAAI,MAAM,EAAE,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,EAAE,CAC1F,CAAC;QACF,OAAO,IAA4B,CAAC;IACtC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,IAAI,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC;IACpC,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,MAIC,EACD,UAAoB,EAAE;IAEtB,MAAM,SAAS,GAAG,MAAM,sBAAsB,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IAC1E,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACrD,OAAO,cAAc,CACnB;QACE,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,KAAK,EAAE,SAAS,CAAC,KAAK;QACtB,SAAS;QACT,OAAO,EAAE,MAAM,CAAC,OAAO;KACxB,EACD,OAAO,CACR,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { SharedProof } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Read a proof someone shared with you.
|
|
4
|
+
*
|
|
5
|
+
* **Deliberately not a method on `CertenClient`.** The whole point of a share link is that the
|
|
6
|
+
* person redeeming it is a counterparty with no CERTEN relationship — the endpoint takes no API key
|
|
7
|
+
* precisely because "requiring a Certen credential to verify a Certen proof would defeat the
|
|
8
|
+
* purpose". Putting the only client-side way to redeem behind a constructor that demands an
|
|
9
|
+
* `apiKey` would have reimposed exactly the requirement the endpoint exists to avoid.
|
|
10
|
+
*
|
|
11
|
+
* This was the asymmetry: the SDK could create a share, list shares and revoke a share — every
|
|
12
|
+
* operation for the person SENDING — and had nothing at all for the person receiving, who is the
|
|
13
|
+
* one the feature is for.
|
|
14
|
+
*
|
|
15
|
+
* Takes the share URL as handed over, or the bare token:
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* const { bundle } = await fetchSharedProof('https://gateway.kompendium.co/v1/proof/shared/abc123');
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* When given a URL the origin comes from it, so a counterparty configures nothing. Asking them to
|
|
22
|
+
* separate the token from the link they were sent, and then tell the SDK which gateway it came
|
|
23
|
+
* from, would be work created for no reason.
|
|
24
|
+
*/
|
|
25
|
+
export declare function fetchSharedProof(tokenOrUrl: string, options?: {
|
|
26
|
+
baseUrl?: string;
|
|
27
|
+
timeoutMs?: number;
|
|
28
|
+
}): Promise<SharedProof>;
|
|
29
|
+
/** `https://host/v1/proof/shared/<token>`, or the token on its own. */
|
|
30
|
+
export declare function parseShareTarget(tokenOrUrl: string, baseUrlOverride?: string): {
|
|
31
|
+
token: string;
|
|
32
|
+
baseUrl: string;
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=shared-proof.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-proof.d.ts","sourceRoot":"","sources":["../src/shared-proof.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,gBAAgB,CACpC,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAO,GACrD,OAAO,CAAC,WAAW,CAAC,CAiBtB;AAED,uEAAuE;AACvE,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,MAAM,EAClB,eAAe,CAAC,EAAE,MAAM,GACvB;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAmBpC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { DEFAULT_BASE_URL } from './client.js';
|
|
3
|
+
import { CertenError } from './errors.js';
|
|
4
|
+
/**
|
|
5
|
+
* Read a proof someone shared with you.
|
|
6
|
+
*
|
|
7
|
+
* **Deliberately not a method on `CertenClient`.** The whole point of a share link is that the
|
|
8
|
+
* person redeeming it is a counterparty with no CERTEN relationship — the endpoint takes no API key
|
|
9
|
+
* precisely because "requiring a Certen credential to verify a Certen proof would defeat the
|
|
10
|
+
* purpose". Putting the only client-side way to redeem behind a constructor that demands an
|
|
11
|
+
* `apiKey` would have reimposed exactly the requirement the endpoint exists to avoid.
|
|
12
|
+
*
|
|
13
|
+
* This was the asymmetry: the SDK could create a share, list shares and revoke a share — every
|
|
14
|
+
* operation for the person SENDING — and had nothing at all for the person receiving, who is the
|
|
15
|
+
* one the feature is for.
|
|
16
|
+
*
|
|
17
|
+
* Takes the share URL as handed over, or the bare token:
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* const { bundle } = await fetchSharedProof('https://gateway.kompendium.co/v1/proof/shared/abc123');
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* When given a URL the origin comes from it, so a counterparty configures nothing. Asking them to
|
|
24
|
+
* separate the token from the link they were sent, and then tell the SDK which gateway it came
|
|
25
|
+
* from, would be work created for no reason.
|
|
26
|
+
*/
|
|
27
|
+
export async function fetchSharedProof(tokenOrUrl, options = {}) {
|
|
28
|
+
const { token, baseUrl } = parseShareTarget(tokenOrUrl, options.baseUrl);
|
|
29
|
+
try {
|
|
30
|
+
const { data } = await axios.get(`${baseUrl.replace(/\/+$/, '')}/v1/proof/shared/${encodeURIComponent(token)}`, {
|
|
31
|
+
timeout: options.timeoutMs ?? 30_000,
|
|
32
|
+
headers: { 'Content-Type': 'application/json' },
|
|
33
|
+
// No API key. See above — sending one would be harmless but misleading about what this
|
|
34
|
+
// endpoint requires.
|
|
35
|
+
});
|
|
36
|
+
return data;
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
throw translate(err);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** `https://host/v1/proof/shared/<token>`, or the token on its own. */
|
|
43
|
+
export function parseShareTarget(tokenOrUrl, baseUrlOverride) {
|
|
44
|
+
const trimmed = tokenOrUrl.trim();
|
|
45
|
+
if (/^https?:\/\//i.test(trimmed)) {
|
|
46
|
+
const url = new URL(trimmed);
|
|
47
|
+
const match = url.pathname.match(/\/v1\/proof\/shared\/([^/]+)\/?$/);
|
|
48
|
+
if (!match) {
|
|
49
|
+
throw new CertenError(`certen: ${trimmed} is not a share link — expected a path ending /v1/proof/shared/<token>`, 0, 'INVALID_SHARE_LINK');
|
|
50
|
+
}
|
|
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
|
+
}
|
|
58
|
+
return { token: trimmed, baseUrl: baseUrlOverride ?? DEFAULT_BASE_URL };
|
|
59
|
+
}
|
|
60
|
+
function translate(err) {
|
|
61
|
+
const axiosErr = err;
|
|
62
|
+
const status = axiosErr.response?.status;
|
|
63
|
+
const body = axiosErr.response?.data;
|
|
64
|
+
// 410 is the case worth naming. It means the link WAS real and is now revoked, expired, or out
|
|
65
|
+
// of views — so the right response is to ask for a fresh one. Collapsing it into "not found"
|
|
66
|
+
// would leave a counterparty believing the proof never existed.
|
|
67
|
+
if (status === 410) {
|
|
68
|
+
return new CertenError(`certen: ${body?.error ?? 'This share link is no longer valid'} — ask for a new link.`, 410, body?.code ?? 'SHARE_NO_LONGER_VALID');
|
|
69
|
+
}
|
|
70
|
+
if (status === 404) {
|
|
71
|
+
return new CertenError('certen: no such share link. Check the link was copied in full.', 404, 'NOT_FOUND');
|
|
72
|
+
}
|
|
73
|
+
if (status) {
|
|
74
|
+
return new CertenError(`certen: ${body?.error ?? axiosErr.message}`, status, body?.code ?? 'HTTP_ERROR');
|
|
75
|
+
}
|
|
76
|
+
return new CertenError(`certen: ${axiosErr.message}`, 0, 'NETWORK_ERROR');
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=shared-proof.js.map
|
|
@@ -0,0 +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,aAAa,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1C;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,UAAkB,EAClB,UAAoD,EAAE;IAEtD,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,gBAAgB,CAAC,UAAU,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IAEzE,IAAI,CAAC;QACH,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,KAAK,CAAC,GAAG,CAC9B,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,oBAAoB,kBAAkB,CAAC,KAAK,CAAC,EAAE,EAC7E;YACE,OAAO,EAAE,OAAO,CAAC,SAAS,I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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,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What `POST /v1/sign` should be told about a target the user named.
|
|
3
|
+
*
|
|
4
|
+
* `transaction` is deliberately absent: the gateway rejects that type and points the caller at
|
|
5
|
+
* `POST /v1/transaction/{id}/signature`, so there is no user-supplied string that should resolve
|
|
6
|
+
* to it.
|
|
7
|
+
*/
|
|
8
|
+
export type SignTarget = {
|
|
9
|
+
type: 'pending_action';
|
|
10
|
+
targetId: string;
|
|
11
|
+
} | {
|
|
12
|
+
type: 'pending_tx';
|
|
13
|
+
targetId: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Resolve a user-supplied target into a `/v1/sign` type and `target_id`.
|
|
17
|
+
*
|
|
18
|
+
* The two id formats are disjoint, so the type can be inferred and neither the CLI nor MCP needs a
|
|
19
|
+
* `--type` flag that would only be a new way to get it wrong:
|
|
20
|
+
*
|
|
21
|
+
* - a UUID is a `pending_actions` row id — the gateway derives identity, signer and key from it
|
|
22
|
+
* - a 64-hex hash is an Accumulate transaction — the caller must supply those three itself
|
|
23
|
+
*
|
|
24
|
+
* The TxID form is accepted because that is what the explorer, `queryTx` and our own `/v1/sign`
|
|
25
|
+
* responses hand people. Requiring a manual strip would fail as an opaque gateway 400.
|
|
26
|
+
*
|
|
27
|
+
* ONE implementation, in the SDK, imported by both clients. Two copies would drift, and the failure
|
|
28
|
+
* mode of a drifted resolver is a signature over the wrong preimage — valid, and attached to
|
|
29
|
+
* nothing.
|
|
30
|
+
*
|
|
31
|
+
* @throws {CertenError} code `INVALID_SIGN_TARGET` — never guesses at an unrecognised form.
|
|
32
|
+
*/
|
|
33
|
+
export declare function resolveSignTarget(input: string): SignTarget;
|
|
34
|
+
//# sourceMappingURL=sign-target.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sign-target.d.ts","sourceRoot":"","sources":["../src/sign-target.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAClB;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAC5C;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAU7C;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAwB3D"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { CertenError } from './errors.js';
|
|
2
|
+
const UUID_RE = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
|
|
3
|
+
const TXID_RE = /^acc:\/\/([0-9a-fA-F]{64})@/;
|
|
4
|
+
const HASH_RE = /^(?:0x)?([0-9a-fA-F]{64})$/;
|
|
5
|
+
const ACCEPTED = 'accepted forms: a pending-action inbox id (UUID), a 64-character transaction hash, '
|
|
6
|
+
+ 'the same hash with a 0x prefix, or a TxID (acc://<hash>@<account>)';
|
|
7
|
+
/**
|
|
8
|
+
* Resolve a user-supplied target into a `/v1/sign` type and `target_id`.
|
|
9
|
+
*
|
|
10
|
+
* The two id formats are disjoint, so the type can be inferred and neither the CLI nor MCP needs a
|
|
11
|
+
* `--type` flag that would only be a new way to get it wrong:
|
|
12
|
+
*
|
|
13
|
+
* - a UUID is a `pending_actions` row id — the gateway derives identity, signer and key from it
|
|
14
|
+
* - a 64-hex hash is an Accumulate transaction — the caller must supply those three itself
|
|
15
|
+
*
|
|
16
|
+
* The TxID form is accepted because that is what the explorer, `queryTx` and our own `/v1/sign`
|
|
17
|
+
* responses hand people. Requiring a manual strip would fail as an opaque gateway 400.
|
|
18
|
+
*
|
|
19
|
+
* ONE implementation, in the SDK, imported by both clients. Two copies would drift, and the failure
|
|
20
|
+
* mode of a drifted resolver is a signature over the wrong preimage — valid, and attached to
|
|
21
|
+
* nothing.
|
|
22
|
+
*
|
|
23
|
+
* @throws {CertenError} code `INVALID_SIGN_TARGET` — never guesses at an unrecognised form.
|
|
24
|
+
*/
|
|
25
|
+
export function resolveSignTarget(input) {
|
|
26
|
+
const raw = typeof input === 'string' ? input.trim() : '';
|
|
27
|
+
if (!raw) {
|
|
28
|
+
throw new CertenError(`certen: no sign target given (${ACCEPTED})`, 0, 'INVALID_SIGN_TARGET');
|
|
29
|
+
}
|
|
30
|
+
// UUID first: it cannot collide with either hash form (different length, and it contains dashes).
|
|
31
|
+
if (UUID_RE.test(raw))
|
|
32
|
+
return { type: 'pending_action', targetId: raw };
|
|
33
|
+
const txid = TXID_RE.exec(raw);
|
|
34
|
+
if (txid)
|
|
35
|
+
return { type: 'pending_tx', targetId: txid[1].toLowerCase() };
|
|
36
|
+
const hash = HASH_RE.exec(raw);
|
|
37
|
+
if (hash)
|
|
38
|
+
return { type: 'pending_tx', targetId: hash[1].toLowerCase() };
|
|
39
|
+
throw new CertenError(`certen: "${raw}" is not a sign target (${ACCEP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