@certen.io/sdk 0.4.0 → 0.7.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.
Files changed (105) hide show
  1. package/CHANGELOG.md +874 -185
  2. package/README.md +133 -119
  3. package/dist/client.d.ts +99 -6
  4. package/dist/client.d.ts.map +1 -1
  5. package/dist/client.js +269 -20
  6. package/dist/client.js.map +1 -1
  7. package/dist/doctor.d.ts +53 -0
  8. package/dist/doctor.d.ts.map +1 -0
  9. package/dist/doctor.js +451 -0
  10. package/dist/doctor.js.map +1 -0
  11. package/dist/error-codes.d.ts +14 -0
  12. package/dist/error-codes.d.ts.map +1 -0
  13. package/dist/error-codes.js +55 -0
  14. package/dist/error-codes.js.map +1 -0
  15. package/dist/errors.d.ts +91 -1
  16. package/dist/errors.d.ts.map +1 -1
  17. package/dist/errors.js +130 -1
  18. package/dist/errors.js.map +1 -1
  19. package/dist/funding.d.ts +43 -0
  20. package/dist/funding.d.ts.map +1 -0
  21. package/dist/funding.js +116 -0
  22. package/dist/funding.js.map +1 -0
  23. package/dist/index.d.ts +10 -1
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +18 -1
  26. package/dist/index.js.map +1 -1
  27. package/dist/oauth.d.ts +56 -0
  28. package/dist/oauth.d.ts.map +1 -0
  29. package/dist/oauth.js +68 -0
  30. package/dist/oauth.js.map +1 -0
  31. package/dist/registration.d.ts +33 -0
  32. package/dist/registration.d.ts.map +1 -0
  33. package/dist/registration.js +49 -0
  34. package/dist/registration.js.map +1 -0
  35. package/dist/resources/admin.d.ts +52 -1
  36. package/dist/resources/admin.d.ts.map +1 -1
  37. package/dist/resources/admin.js +55 -0
  38. package/dist/resources/admin.js.map +1 -1
  39. package/dist/resources/billing.d.ts +242 -0
  40. package/dist/resources/billing.d.ts.map +1 -0
  41. package/dist/resources/billing.js +376 -0
  42. package/dist/resources/billing.js.map +1 -0
  43. package/dist/resources/chains.d.ts +38 -0
  44. package/dist/resources/chains.d.ts.map +1 -0
  45. package/dist/resources/chains.js +46 -0
  46. package/dist/resources/chains.js.map +1 -0
  47. package/dist/resources/device.d.ts +43 -0
  48. package/dist/resources/device.d.ts.map +1 -0
  49. package/dist/resources/device.js +49 -0
  50. package/dist/resources/device.js.map +1 -0
  51. package/dist/resources/execute.d.ts +39 -1
  52. package/dist/resources/execute.d.ts.map +1 -1
  53. package/dist/resources/execute.js +41 -1
  54. package/dist/resources/execute.js.map +1 -1
  55. package/dist/resources/health.d.ts +34 -0
  56. package/dist/resources/health.d.ts.map +1 -0
  57. package/dist/resources/health.js +43 -0
  58. package/dist/resources/health.js.map +1 -0
  59. package/dist/resources/identity.d.ts +83 -2
  60. package/dist/resources/identity.d.ts.map +1 -1
  61. package/dist/resources/identity.js +154 -2
  62. package/dist/resources/identity.js.map +1 -1
  63. package/dist/resources/oauth-clients.d.ts +71 -0
  64. package/dist/resources/oauth-clients.d.ts.map +1 -0
  65. package/dist/resources/oauth-clients.js +75 -0
  66. package/dist/resources/oauth-clients.js.map +1 -0
  67. package/dist/resources/pending.d.ts +13 -1
  68. package/dist/resources/pending.d.ts.map +1 -1
  69. package/dist/resources/pending.js +15 -0
  70. package/dist/resources/pending.js.map +1 -1
  71. package/dist/resources/proof.d.ts +75 -0
  72. package/dist/resources/proof.d.ts.map +1 -0
  73. package/dist/resources/proof.js +103 -0
  74. package/dist/resources/proof.js.map +1 -0
  75. package/dist/resources/registration-tokens.d.ts +51 -0
  76. package/dist/resources/registration-tokens.d.ts.map +1 -0
  77. package/dist/resources/registration-tokens.js +54 -0
  78. package/dist/resources/registration-tokens.js.map +1 -0
  79. package/dist/resources/transaction.d.ts +20 -0
  80. package/dist/resources/transaction.d.ts.map +1 -1
  81. package/dist/resources/transaction.js +28 -0
  82. package/dist/resources/transaction.js.map +1 -1
  83. package/dist/resources/transparency.d.ts +68 -0
  84. package/dist/resources/transparency.d.ts.map +1 -0
  85. package/dist/resources/transparency.js +83 -0
  86. package/dist/resources/transparency.js.map +1 -0
  87. package/dist/resources/webhooks.d.ts +97 -0
  88. package/dist/resources/webhooks.d.ts.map +1 -0
  89. package/dist/resources/webhooks.js +112 -0
  90. package/dist/resources/webhooks.js.map +1 -0
  91. package/dist/self-signup.d.ts +66 -0
  92. package/dist/self-signup.d.ts.map +1 -0
  93. package/dist/self-signup.js +76 -0
  94. package/dist/self-signup.js.map +1 -0
  95. package/dist/shared-proof.d.ts +34 -0
  96. package/dist/shared-proof.d.ts.map +1 -0
  97. package/dist/shared-proof.js +78 -0
  98. package/dist/shared-proof.js.map +1 -0
  99. package/dist/types.d.ts +901 -24
  100. package/dist/types.d.ts.map +1 -1
  101. package/dist/verify-receipt.d.ts +32 -0
  102. package/dist/verify-receipt.d.ts.map +1 -0
  103. package/dist/verify-receipt.js +176 -0
  104. package/dist/verify-receipt.js.map +1 -0
  105. package/package.json +6 -5
@@ -0,0 +1,83 @@
1
+ /**
2
+ * The public transparency log.
3
+ *
4
+ * This is what turns a receipt from an assertion into evidence. A receipt's signature says CERTEN
5
+ * issued it; the log says CERTEN did not later hide or edit it, because every receipt is a leaf of
6
+ * an append-only Merkle tree whose roots are signed and written to Accumulate.
7
+ *
8
+ * The receipt's own verification instructions name these endpoints — "check root_hash against the
9
+ * signed head at this tree size" — and none of them had a client surface, so the instruction could
10
+ * not be followed without hand-rolling HTTP. A verification procedure nobody can run is not a
11
+ * verification procedure.
12
+ *
13
+ * **These reads need no API key.** That is deliberate on the gateway's side and worth preserving in
14
+ * your integration: evidence obtainable only by asking CERTEN nicely could not settle a dispute
15
+ * with CERTEN. The client sends its key anyway because it sends one to everything; the endpoints do
16
+ * not require it.
17
+ */
18
+ export class TransparencyResource {
19
+ http;
20
+ constructor(http) {
21
+ this.http = http;
22
+ }
23
+ /** What the log is, how big it is, and where its roots are anchored. */
24
+ async log() {
25
+ const { data } = await this.http.get('/v1/transparency');
26
+ return data;
27
+ }
28
+ /** Signed tree heads, newest first. */
29
+ async heads(params = {}) {
30
+ const { data } = await this.http.get('/v1/transparency/heads', {
31
+ params: { limit: params.limit ?? 50, offset: params.offset ?? 0 },
32
+ });
33
+ return data;
34
+ }
35
+ /**
36
+ * The signed head at one tree size.
37
+ *
38
+ * Step three of verifying a receipt: fold its audit path to a root, then check that root against
39
+ * the head fetched HERE rather than against the `root_hash` the proof itself carried. Comparing a
40
+ * proof to a root supplied in the same response proves nothing — it is the independent fetch, and
41
+ * the signature on it, that makes the check mean something.
42
+ */
43
+ async head(treeSize) {
44
+ const { data } = await this.http.get(`/v1/transparency/heads/${treeSize}`);
45
+ return data;
46
+ }
47
+ /**
48
+ * Proof that the log at `second` extends the log at `first` without rewriting it.
49
+ *
50
+ * Needed whenever a receipt's own head is not the one that got anchored. The anchored head is
51
+ * later and larger, and this is what shows the anchored root still commits to everything the
52
+ * earlier root did — that the log was appended to, not rebuilt.
53
+ */
54
+ async consistency(first, second) {
55
+ const { data } = await this.http.get('/v1/transparency/consistency', {
56
+ params: { first, second },
57
+ });
58
+ return data;
59
+ }
60
+ /**
61
+ * Every published price book, with its hash and the window it was in force.
62
+ *
63
+ * A receipt carries `price_book_hash`. This is where that hash resolves to actual prices — which
64
+ * is what lets someone check that a charge matched the prices published at the time, rather than
65
+ * prices chosen afterwards.
66
+ */
67
+ async priceBooks() {
68
+ const { data } = await this.http.get('/v1/transparency/price-books');
69
+ return data;
70
+ }
71
+ /**
72
+ * A signed FX observation.
73
+ *
74
+ * A gas-priced charge converts native currency to USD at a rate observed at a moment. The receipt
75
+ * names the observation; this returns it, signed, so the conversion can be rechecked rather than
76
+ * taken on trust.
77
+ */
78
+ async fx(id) {
79
+ const { data } = await this.http.get(`/v1/transparency/fx/${encodeURIComponent(id)}`);
80
+ return data;
81
+ }
82
+ }
83
+ //# sourceMappingURL=transparency.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transparency.js","sourceRoot":"","sources":["../../src/resources/transparency.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,o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,CAAC,EAAE,CAAC,EAAU;QACjB,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,uBAAuB,kBAAkB,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QACtF,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
@@ -0,0 +1,97 @@
1
+ import { AxiosInstance } from 'axios';
2
+ import type { WebhookEndpoint, WebhookDelivery, Pagination } from '../types.js';
3
+ /**
4
+ * Webhook endpoints, and what happened to each delivery.
5
+ *
6
+ * The gateway has had a delivery queue, a retry policy, an event registry and a customer-facing
7
+ * signature-verification guide since early on. None of it had a client surface — so the only push
8
+ * mechanism CERTEN offers could be configured nowhere, and a failed delivery could be neither seen
9
+ * nor retried. A webhook a customer cannot inspect is worse than no webhook: it fails silently and
10
+ * looks like the event never happened.
11
+ *
12
+ * These lived under `/v1/admin/webhooks/*` and required `admin:write` — a scope that also grants
13
+ * revoking every API key in the organization, attributing payments and publishing price books.
14
+ * The data was always org-scoped, so the path and the scope both overstated what this is. Moved to
15
+ * `/v1/webhooks/*` with `webhook:read` and `webhook:write`, which cover exactly this and nothing
16
+ * else.
17
+ */
18
+ export declare class WebhooksResource {
19
+ private http;
20
+ constructor(http: AxiosInstance);
21
+ /** Endpoints registered for this organization. Requires `webhook:read`. */
22
+ list(): Promise<{
23
+ endpoints: WebhookEndpoint[];
24
+ }>;
25
+ /**
26
+ * Register an endpoint.
27
+ *
28
+ * **The signing secret is returned once and never again.** Store it before doing anything else —
29
+ * without it you cannot verify that a delivery came from CERTEN, and the only recovery is
30
+ * `rotateSecret`, which invalidates whatever the previous secret was signing.
31
+ *
32
+ * Supply your own `secret` to keep the value out of a response body entirely. Omit `eventTypes`
33
+ * to receive everything.
34
+ */
35
+ register(params: {
36
+ url: string;
37
+ secret?: string;
38
+ eventTypes?: string[];
39
+ description?: string;
40
+ /** Skip the verification ping. The endpoint is registered unverified. */
41
+ skipVerification?: boolean;
42
+ }): Promise<WebhookEndpoint & {
43
+ secret?: string;
44
+ warning?: string;
45
+ }>;
46
+ /** Change an endpoint's URL, events, description, or active state. Requires `webhook:write`. */
47
+ update(id: string, params: {
48
+ url?: string;
49
+ eventTypes?: string[];
50
+ description?: string;
51
+ isActive?: boolean;
52
+ }): Promise<WebhookEndpoint>;
53
+ /** Stop delivering to an endpoint. Requires `webhook:write`. */
54
+ remove(id: string): Promise<{
55
+ deleted?: boolean;
56
+ [k: string]: unknown;
57
+ }>;
58
+ /**
59
+ * Issue a new signing secret.
60
+ *
61
+ * NOT retry-safe: each call invalidates the secret the previous one issued, so a retry can strand
62
+ * a receiver that was verifying correctly seconds earlier. Returns the new secret once.
63
+ */
64
+ rotateSecret(id: string): Promise<{
65
+ secret: string;
66
+ [k: string]: unknown;
67
+ }>;
68
+ /** Re-run the verification ping against an endpoint. Requires `webhook:write`. */
69
+ verify(id: string): Promise<WebhookEndpoint>;
70
+ /**
71
+ * Delivery attempts, newest first. Requires `webhook:read`.
72
+ *
73
+ * This is the half that makes webhooks debuggable: a delivery that failed is otherwise invisible
74
+ * to the person waiting for the event.
75
+ */
76
+ deliveries(params?: {
77
+ limit?: number;
78
+ offset?: number;
79
+ }): Promise<{
80
+ deliveries: WebhookDelivery[];
81
+ pagination?: Pagination;
82
+ }>;
83
+ /** Every delivery, paging automatically on `has_more`. */
84
+ deliveriesAll(pageSize?: number): AsyncIterableIterator<WebhookDelivery>;
85
+ /** One delivery, including the response body the endpoint returned. Requires `webhook:read`. */
86
+ delivery(id: string): Promise<WebhookDelivery>;
87
+ /**
88
+ * Send a delivery again.
89
+ *
90
+ * Deliberately NOT retry-safe: delivering again is the entire point, so calling this twice
91
+ * delivers twice. Make sure the receiver is idempotent before leaning on it.
92
+ */
93
+ redeliver(id: string): Promise<{
94
+ [k: string]: unknown;
95
+ }>;
96
+ }
97
+ //# sourceMappingURL=webhooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhooks.d.ts","sourceRoot":"","sources":["../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AAE,MAAM,CAAC;QAAC,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;IAOjF,kFAAkF;IAC5E,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAOlD;;;;;OAKG;IACG,UAAU,CACd,MAAM,GAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAO,GAC/C,OAAO,CAAC;QAAE,UAAU,EAAE,eAAe,EAAE,CAAC;QAAC,UAAU,CAAC,EAAE,UAAU,CAAA;KAAE,CAAC;IAOtE,0DAA0D;IAC1D,aAAa,CAAC,QAAQ,SAAM,GAAG,qBAAqB,CAAC,eAAe,CAAC;IAUrE,gGAAgG;IAC1F,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAKpD;;;;;OAKG;IACG,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;CAM/D"}
@@ -0,0 +1,112 @@
1
+ import { paginate } from '../client.js';
2
+ /**
3
+ * Webhook endpoints, and what happened to each delivery.
4
+ *
5
+ * The gateway has had a delivery queue, a retry policy, an event registry and a customer-facing
6
+ * signature-verification guide since early on. None of it had a client surface — so the only push
7
+ * mechanism CERTEN offers could be configured nowhere, and a failed delivery could be neither seen
8
+ * nor retried. A webhook a customer cannot inspect is worse than no webhook: it fails silently and
9
+ * looks like the event never happened.
10
+ *
11
+ * These lived under `/v1/admin/webhooks/*` and required `admin:write` — a scope that also grants
12
+ * revoking every API key in the organization, attributing payments and publishing price books.
13
+ * The data was always org-scoped, so the path and the scope both overstated what this is. Moved to
14
+ * `/v1/webhooks/*` with `webhook:read` and `webhook:write`, which cover exactly this and nothing
15
+ * else.
16
+ */
17
+ export class WebhooksResource {
18
+ http;
19
+ constructor(http) {
20
+ this.http = http;
21
+ }
22
+ /** Endpoints registered for this organization. Requires `webhook:read`. */
23
+ async list() {
24
+ const { data } = await this.http.get('/v1/webhooks/endpoints');
25
+ return data;
26
+ }
27
+ /**
28
+ * Register an endpoint.
29
+ *
30
+ * **The signing secret is returned once and never again.** Store it before doing anything else —
31
+ * without it you cannot verify that a delivery came from CERTEN, and the only recovery is
32
+ * `rotateSecret`, which invalidates whatever the previous secret was signing.
33
+ *
34
+ * Supply your own `secret` to keep the value out of a response body entirely. Omit `eventTypes`
35
+ * to receive everything.
36
+ */
37
+ async register(params) {
38
+ const { data } = await this.http.post('/v1/webhooks/endpoints', {
39
+ url: params.url,
40
+ ...(params.secret ? { secret: params.secret } : {}),
41
+ ...(params.eventTypes ? { event_types: params.eventTypes } : {}),
42
+ ...(params.description ? { description: params.description } : {}),
43
+ ...(params.skipVerification ? { skip_verification: true } : {}),
44
+ });
45
+ return data;
46
+ }
47
+ /** Change an endpoint's URL, events, description, or active state. Requires `webhook:write`. */
48
+ async update(id, params) {
49
+ const { data } = await this.http.patch(`/v1/webhooks/endpoints/${encodeURIComponent(id)}`, {
50
+ ...(params.url ? { url: params.url } : {}),
51
+ ...(params.eventTypes ? { event_types: params.eventTypes } : {}),
52
+ ...(params.description !== undefined ? { description: params.description } : {}),
53
+ ...(params.isActive !== undefined ? { is_active: params.isActive } : {}),
54
+ });
55
+ return data;
56
+ }
57
+ /** Stop delivering to an endpoint. Requires `webhook:write`. */
58
+ async remove(id) {
59
+ const { data } = await this.http.delete(`/v1/webhooks/endpoints/${encodeURIComponent(id)}`);
60
+ return data;
61
+ }
62
+ /**
63
+ * Issue a new signing secret.
64
+ *
65
+ * NOT retry-safe: each call invalidates the secret the previous one issued, so a retry can strand
66
+ * a receiver that was verifying correctly seconds earlier. Returns the new secret once.
67
+ */
68
+ async rotateSecret(id) {
69
+ const { data } = await this.http.post(`/v1/webhooks/endpoints/${encodeURIComponent(id)}/rotate-secret`);
70
+ return data;
71
+ }
72
+ /** Re-run the verification ping against an endpoint. Requires `webhook:write`. */
73
+ async verify(id) {
74
+ const { data } = await this.http.post(`/v1/webhooks/endpoints/${encodeURIComponent(id)}/verify`);
75
+ return data;
76
+ }
77
+ /**
78
+ * Delivery attempts, newest first. Requires `webhook:read`.
79
+ *
80
+ * This is the half that makes webhooks debuggable: a delivery that failed is otherwise invisible
81
+ * to the person waiting for the event.
82
+ */
83
+ async deliveries(params = {}) {
84
+ const { data } = await this.http.get('/v1/webhooks/deliveries', {
85
+ params: { limit: params.limit ?? 50, offset: params.offset ?? 0 },
86
+ });
87
+ return data;
88
+ }
89
+ /** Every delivery, paging automatically on `has_more`. */
90
+ deliveriesAll(pageSize = 100) {
91
+ return paginate(async (limit, offset) => {
92
+ const page = await this.deliveries({ limit, offset });
93
+ return { items: page.deliveries ?? [], hasMore: page.pagination?.has_more };
94
+ }, pageSize);
95
+ }
96
+ /** One delivery, including the response body the endpoint returned. Requires `webhook:read`. */
97
+ async delivery(id) {
98
+ const { data } = await this.http.get(`/v1/webhooks/deliveries/${encodeURIComponent(id)}`);
99
+ return data;
100
+ }
101
+ /**
102
+ * Send a delivery again.
103
+ *
104
+ * Deliberately NOT retry-safe: delivering again is the entire point, so calling this twice
105
+ * delivers twice. Make sure the receiver is idempotent before leaning on it.
106
+ */
107
+ async redeliver(id) {
108
+ const { data } = await this.http.post(`/v1/webhooks/deliveries/${encodeURIComponent(id)}/redeliver`);
109
+ return data;
110
+ }
111
+ }
112
+ //# sourceMappingURL=webhooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhooks.js","sourceRoot":"","sources":["../../src/resources/webhooks.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAGxC;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,gBAAgB;IACP;IAApB,YAAoB,IAAmB;QAAnB,SAAI,GAAJ,IAAI,CAAe;IAAG,CAAC;IAE3C,2EAA2E;IAC3E,KAAK,CAAC,IAAI;QACR,MAAM,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,MAAM,CAAC,KAAK,IAAI,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,CAAC,EAAE;SAClE,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IACd,CAAC;IAED,0DAA0D;IAC1D,aAAa,CAAC,QAAQ,GAAG,GAAG;QAC1B,OAAO,QAAQ,CACb,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;YACtB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;YACtD,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,UAAU,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,QAAQ,EAAE,CAAC;QAC9E,CAAC,EACD,QAAQ,CACT,CAAC;IACJ,CAAC;IAED,gGAAgG;IAChG,KAAK,CAAC,QAAQ,CAAC,EAAU;QACvB,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,2BAA2B,kBAAkB,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QAC1F,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,SAAS,CAAC,EAAU;QACxB,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CACnC,2BAA2B,kBAAkB,CAAC,EAAE,CAAC,YAAY,CAC9D,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
@@ -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,MAAM,MAAM,GAAG,CAAC,CAAC,QAAQ,EAAE,MAAM,IAAI,CAAC,CAAC;IACvC,MAAM,OAAO,GAAG,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC;IACjC,MAAM,IAAI,WAAW,CACnB,WAAW,OAAO,EAAE,KAAK,IAAI,CAAC,CAAC,OAAO,EAAE,EACxC,MAAM,EACN,OAAO,EAAE,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,eAAe,CAAC,EAC1D,EAAE,IAAI,EAAE,OAAO,EAAE,CAClB,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,SAAkB,EAClB,UAAoB,EAAE;IAEtB,MAAM,IAAI,GAAG,CAAC,OAAO,CAAC,OAAO,IAAI,gBAAgB,CAAC,CAAC,OAAO,CAAC,MAAM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ACb,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,IAAI,MAAM;YACpC,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAC/C,uFAAuF;YACvF,qBAAqB;SACtB,CACF,CAAC;QACF,OAAO,IAAmB,CAAC;IAC7B,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,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