@certen.io/sdk 0.9.0 → 0.11.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 (170) hide show
  1. package/CHANGELOG.md +153 -0
  2. package/README.md +111 -0
  3. package/dist/address.d.ts +12 -0
  4. package/dist/address.d.ts.map +1 -0
  5. package/dist/address.js +48 -0
  6. package/dist/address.js.map +1 -0
  7. package/dist/agent.d.ts +8 -0
  8. package/dist/agent.d.ts.map +1 -1
  9. package/dist/agent.js +12 -0
  10. package/dist/agent.js.map +1 -1
  11. package/dist/browser.d.ts +47 -0
  12. package/dist/browser.d.ts.map +1 -0
  13. package/dist/browser.js +55 -0
  14. package/dist/browser.js.map +1 -0
  15. package/dist/bytes.d.ts +14 -0
  16. package/dist/bytes.d.ts.map +1 -0
  17. package/dist/bytes.js +47 -0
  18. package/dist/bytes.js.map +1 -0
  19. package/dist/chains.d.ts +218 -0
  20. package/dist/chains.d.ts.map +1 -0
  21. package/dist/chains.js +295 -0
  22. package/dist/chains.js.map +1 -0
  23. package/dist/client.d.ts +17 -2
  24. package/dist/client.d.ts.map +1 -1
  25. package/dist/client.js +54 -8
  26. package/dist/client.js.map +1 -1
  27. package/dist/defaults.d.ts +3 -0
  28. package/dist/defaults.d.ts.map +1 -0
  29. package/dist/defaults.js +3 -0
  30. package/dist/defaults.js.map +1 -0
  31. package/dist/doctor.d.ts +10 -1
  32. package/dist/doctor.d.ts.map +1 -1
  33. package/dist/doctor.js +42 -27
  34. package/dist/doctor.js.map +1 -1
  35. package/dist/effect.d.ts +99 -0
  36. package/dist/effect.d.ts.map +1 -0
  37. package/dist/effect.js +139 -0
  38. package/dist/effect.js.map +1 -0
  39. package/dist/error-codes.d.ts.map +1 -1
  40. package/dist/error-codes.js +17 -0
  41. package/dist/error-codes.js.map +1 -1
  42. package/dist/errors.d.ts +76 -0
  43. package/dist/errors.d.ts.map +1 -1
  44. package/dist/errors.js +108 -0
  45. package/dist/errors.js.map +1 -1
  46. package/dist/evm-rpc.d.ts +55 -0
  47. package/dist/evm-rpc.d.ts.map +1 -0
  48. package/dist/evm-rpc.js +126 -0
  49. package/dist/evm-rpc.js.map +1 -0
  50. package/dist/execution-proof.d.ts.map +1 -1
  51. package/dist/execution-proof.js +2 -1
  52. package/dist/execution-proof.js.map +1 -1
  53. package/dist/funding.d.ts +214 -6
  54. package/dist/funding.d.ts.map +1 -1
  55. package/dist/funding.js +251 -29
  56. package/dist/funding.js.map +1 -1
  57. package/dist/header-fields.d.ts +68 -0
  58. package/dist/header-fields.d.ts.map +1 -0
  59. package/dist/header-fields.js +147 -0
  60. package/dist/header-fields.js.map +1 -0
  61. package/dist/index.d.ts +9 -17
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/index.js +11 -26
  64. package/dist/index.js.map +1 -1
  65. package/dist/intent-states.d.ts +75 -0
  66. package/dist/intent-states.d.ts.map +1 -0
  67. package/dist/intent-states.js +66 -0
  68. package/dist/intent-states.js.map +1 -0
  69. package/dist/internal.d.ts +18 -0
  70. package/dist/internal.d.ts.map +1 -1
  71. package/dist/internal.js +44 -0
  72. package/dist/internal.js.map +1 -1
  73. package/dist/key-page.d.ts +67 -0
  74. package/dist/key-page.d.ts.map +1 -0
  75. package/dist/key-page.js +154 -0
  76. package/dist/key-page.js.map +1 -0
  77. package/dist/origin.d.ts +19 -0
  78. package/dist/origin.d.ts.map +1 -0
  79. package/dist/origin.js +80 -0
  80. package/dist/origin.js.map +1 -0
  81. package/dist/random.d.ts +27 -0
  82. package/dist/random.d.ts.map +1 -0
  83. package/dist/random.js +30 -0
  84. package/dist/random.js.map +1 -0
  85. package/dist/readiness.d.ts +133 -0
  86. package/dist/readiness.d.ts.map +1 -0
  87. package/dist/readiness.js +467 -0
  88. package/dist/readiness.js.map +1 -0
  89. package/dist/reason-codes.d.ts +15 -0
  90. package/dist/reason-codes.d.ts.map +1 -0
  91. package/dist/reason-codes.js +30 -0
  92. package/dist/reason-codes.js.map +1 -0
  93. package/dist/receipt.d.ts +233 -0
  94. package/dist/receipt.d.ts.map +1 -0
  95. package/dist/receipt.js +318 -0
  96. package/dist/receipt.js.map +1 -0
  97. package/dist/resources/admin.d.ts +5 -2
  98. package/dist/resources/admin.d.ts.map +1 -1
  99. package/dist/resources/admin.js +8 -3
  100. package/dist/resources/admin.js.map +1 -1
  101. package/dist/resources/billing.d.ts.map +1 -1
  102. package/dist/resources/billing.js +5 -4
  103. package/dist/resources/billing.js.map +1 -1
  104. package/dist/resources/chains.d.ts +10 -0
  105. package/dist/resources/chains.d.ts.map +1 -1
  106. package/dist/resources/chains.js +15 -1
  107. package/dist/resources/chains.js.map +1 -1
  108. package/dist/resources/device.d.ts.map +1 -1
  109. package/dist/resources/device.js +2 -1
  110. package/dist/resources/device.js.map +1 -1
  111. package/dist/resources/execute.d.ts +110 -4
  112. package/dist/resources/execute.d.ts.map +1 -1
  113. package/dist/resources/execute.js +207 -35
  114. package/dist/resources/execute.js.map +1 -1
  115. package/dist/resources/governance.js +3 -3
  116. package/dist/resources/governance.js.map +1 -1
  117. package/dist/resources/identity.js +5 -5
  118. package/dist/resources/identity.js.map +1 -1
  119. package/dist/resources/oauth-clients.d.ts.map +1 -1
  120. package/dist/resources/oauth-clients.js +3 -2
  121. package/dist/resources/oauth-clients.js.map +1 -1
  122. package/dist/resources/proof.d.ts +10 -2
  123. package/dist/resources/proof.d.ts.map +1 -1
  124. package/dist/resources/proof.js +33 -11
  125. package/dist/resources/proof.js.map +1 -1
  126. package/dist/resources/registration-tokens.d.ts.map +1 -1
  127. package/dist/resources/registration-tokens.js +2 -1
  128. package/dist/resources/registration-tokens.js.map +1 -1
  129. package/dist/resources/sign.js +2 -2
  130. package/dist/resources/sign.js.map +1 -1
  131. package/dist/resources/transaction.d.ts.map +1 -1
  132. package/dist/resources/transaction.js +7 -3
  133. package/dist/resources/transaction.js.map +1 -1
  134. package/dist/resources/transparency.d.ts.map +1 -1
  135. package/dist/resources/transparency.js +3 -2
  136. package/dist/resources/transparency.js.map +1 -1
  137. package/dist/resources/webhooks.d.ts +5 -3
  138. package/dist/resources/webhooks.d.ts.map +1 -1
  139. package/dist/resources/webhooks.js +12 -8
  140. package/dist/resources/webhooks.js.map +1 -1
  141. package/dist/sha256.d.ts +10 -0
  142. package/dist/sha256.d.ts.map +1 -0
  143. package/dist/sha256.js +71 -0
  144. package/dist/sha256.js.map +1 -0
  145. package/dist/share-target.d.ts +10 -0
  146. package/dist/share-target.d.ts.map +1 -0
  147. package/dist/share-target.js +25 -0
  148. package/dist/share-target.js.map +1 -0
  149. package/dist/shared-proof.d.ts +1 -5
  150. package/dist/shared-proof.d.ts.map +1 -1
  151. package/dist/shared-proof.js +27 -21
  152. package/dist/shared-proof.js.map +1 -1
  153. package/dist/signing-check.d.ts +66 -0
  154. package/dist/signing-check.d.ts.map +1 -0
  155. package/dist/signing-check.js +171 -0
  156. package/dist/signing-check.js.map +1 -0
  157. package/dist/types.d.ts +139 -0
  158. package/dist/types.d.ts.map +1 -1
  159. package/dist/verify-receipt.d.ts.map +1 -1
  160. package/dist/verify-receipt.js +68 -28
  161. package/dist/verify-receipt.js.map +1 -1
  162. package/dist/verify.d.ts +206 -0
  163. package/dist/verify.d.ts.map +1 -0
  164. package/dist/verify.js +369 -0
  165. package/dist/verify.js.map +1 -0
  166. package/dist/version.d.ts +2 -0
  167. package/dist/version.d.ts.map +1 -0
  168. package/dist/version.js +4 -0
  169. package/dist/version.js.map +1 -0
  170. package/package.json +25 -7
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC1F,cAAc,YAAY,CAAC;AAC3B,YAAY,EAAE,MAAM,EAAE,oBAAoB,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACzG,OAAO,EACL,WAAW,EACX,eAAe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ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,cAAc,CAAC;AAI7B,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAIzE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACxD,YAAY,EAAE,WAAW,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAEjF,OAAO,EACL,sBAAsB,EAAE,kBAAkB,EAAE,cAAc,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,cAAc,EAAE,WAAW,EACnI,qBAAqB,EAAE,mBAAmB,EAAE,4BAA4B,EAAE,+BAA+B,GAC1G,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtG,YAAY,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC"}
package/dist/index.js CHANGED
@@ -1,28 +1,13 @@
1
- export { CertenClient, paginate, paginateWithTotal, DEFAULT_BASE_URL } from './client.js';
2
- export * from './types.js';
3
- export { CertenError, CertenAuthError, CertenRateLimitError, CertenBadRequestError, CertenServerError, CertenPaymentRequiredError, } from './errors.js';
4
- export { runDoctor, CREDENTIALLED_CHECKS } from './doctor.js';
5
- // Standalone on purpose: redeeming a share link needs no API key and therefore no client. See
6
- // shared-proof.ts.
7
- export { fetchSharedProof, parseShareTarget, decodeSharedBundle } from './shared-proof.js';
8
- // execution-proof.ts: verify a bundle's component 5 (the receipt and its trie proof) with no
9
- // dependencies and no gateway — what a counterparty runs.
10
- export { verifyExecutionProof, checkAgainstHeader, executionComponentOf, decodeReceipt, verifyTrieProof, keccak256, rlpDecode, rlpEncodeUint, bytesFrom, } from './execution-proof.js';
11
- // Standalone for the same reason: these carry their credential in the body and need no API key,
12
- // so a caller using OAuth is not made to hold one. See oauth.ts.
13
- export { fetchOAuthToken, refreshOAuthToken, revokeOAuthToken } from './oauth.js';
14
- // Exported so a caller can split `mnemonic_retrieval.url` the same way the SDK does, rather than
15
- // writing their own regex against a string whose parts they cannot afford to get wrong.
16
- export { parseMnemonicTarget } from './resources/identity.js';
17
- // Standalone for the same reason as the OAuth helpers: the caller has no credential yet, and
18
- // obtaining its first one is the entire purpose. See registration.ts.
19
- export { redeemRegistrationToken } from './registration.js';
20
- // Keypair-proof self-service signup — no browser, no email, nobody at CERTEN. Standalone for the
21
- // same reason: the caller holds nothing yet. See self-signup.ts.
22
- export { selfSignup, requestSignupChallenge, completeSignup } from './self-signup.js';
23
- export { CertenUnfundedAccountError, movesValue, normalizeChainId } from './funding.js';
24
- // One resolver, shared by the CLI and MCP. Two copies of this would drift — see sign-target.ts.
25
- export { resolveSignTarget } from './sign-target.js';
26
- // An autonomous agent's identity and every proof-gated verb it needs, composed once. See agent.ts.
1
+ /**
2
+ * The SDK's default entry (Node): everything in the browser-safe surface, plus the two parts that need Node.
3
+ * See browser.ts for the portable half and why the split exists.
4
+ */
5
+ export * from './browser.js';
6
+ // Standalone on purpose: redeeming a share link needs no API key and therefore no client. Node-only because a shared bundle may be
7
+ // gzipped (node:zlib). See shared-proof.ts.
8
+ export { fetchSharedProof, decodeSharedBundle } from './shared-proof.js';
9
+ // An autonomous agent's identity and every proof-gated verb it needs, composed once. Node-only: it holds and uses a local ed25519 key
10
+ // through node:crypto. See agent.ts.
27
11
  export { CertenAgent, ed25519Signer } from './agent.js';
12
+ export { CertenSigningDataError, checkIntentSigning, checkCosigning, checkGovernanceSigning, inspectSigningData, legsFromIntent, toBaseUnits, SIGNING_DATA_MISMATCH, SIGNING_DATA_ABSENT, SIGNING_VERIFIER_UNAVAILABLE, SIGNING_EXPECTATION_UNAVAILABLE, } from './signing-check.js';
28
13
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,E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"AAAA;;;GAGG;AACH,cAAc,cAAc,CAAC;AAE7B,mIAAmI;AACnI,4CAA4C;AAC5C,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEzE,sIAAsI;AACtI,qCAAqC;AACrC,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGxD,OAAO,EACL,sBAAsB,EAAE,kBAAkB,EAAE,cAAc,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,cAAc,EAAE,WAAW,EACnI,qBAAqB,EAAE,mBAAmB,EAAE,4BAA4B,EAAE,+BAA+B,GAC1G,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Where an intent can be, and what each place means.
3
+ *
4
+ * ONE table, used by `execute.wait()`, the CLI and the MCP server, so they cannot disagree about which statuses end a wait. Before
5
+ * this there were three copies of `['completed', 'delivered', 'proven']`, and none of them knew the two states the execution
6
+ * outcome model added:
7
+ *
8
+ * - `executed`: the action EXECUTED on its chain and its proof bundle is pending. Not a failure, and not terminal: CERTEN produces
9
+ * the bundle automatically and the intent then reads `completed`. The fee is held meanwhile.
10
+ * - `completed_unproven`: the action executed and its proof can NEVER be produced (declared by an operator with the evidence).
11
+ * Terminal. Billed gas only, fee waived. It is never "completed": nothing can be verified for it.
12
+ *
13
+ * `expired` is terminal too, and a failure: the intent will never execute. `wait()` used to poll through it to its timeout.
14
+ *
15
+ * The statuses are the gateway's own (`chk_intent_status`, api-gateway migration 053) and the spec's description of the field.
16
+ * `delivered` and `error` are older spellings this client has always treated as terminal; they stay in the table so a gateway that
17
+ * still sends them is not misread. A status that is not in the table is `unknown` and is never treated as terminal.
18
+ */
19
+ /** What a status means for a caller waiting on the intent. */
20
+ export type IntentStatusClass =
21
+ /** Opened or in progress; nothing has executed. Keep waiting. */
22
+ 'in_flight'
23
+ /** Executed on its chain; the proof bundle is pending. Not terminal, not a failure. Keep waiting for `completed`. */
24
+ | 'executed'
25
+ /** Executed and proven. Terminal. */
26
+ | 'terminal_success'
27
+ /** Executed and its proof can never be produced. Terminal; gas-only billing. */
28
+ | 'terminal_gas_only'
29
+ /** Will never execute. Terminal. */
30
+ | 'terminal_failure'
31
+ /** A status this client does not know. Not terminal: more waiting cannot make it worse, and calling it done could. */
32
+ | 'unknown';
33
+ export declare const INTENT_STATUS_CLASS: {
34
+ readonly created: "in_flight";
35
+ readonly signing_required: "in_flight";
36
+ readonly submitted: "in_flight";
37
+ readonly processing: "in_flight";
38
+ readonly anchoring: "in_flight";
39
+ readonly executed: "executed";
40
+ readonly completed: "terminal_success";
41
+ readonly proven: "terminal_success";
42
+ readonly delivered: "terminal_success";
43
+ readonly completed_unproven: "terminal_gas_only";
44
+ readonly failed: "terminal_failure";
45
+ readonly expired: "terminal_failure";
46
+ readonly error: "terminal_failure";
47
+ };
48
+ export type KnownIntentStatus = keyof typeof INTENT_STATUS_CLASS;
49
+ /** The reason the gateway gives a `completed_unproven` intent: the proof can never be produced. */
50
+ export declare const EXECUTION_PROOF_UNAVAILABLE = "execution_proof_unavailable";
51
+ export declare function classifyIntentStatus(status: unknown): IntentStatusClass;
52
+ /** Does this status end a wait (success, gas-only, or failure)? `executed` and `unknown` do not. */
53
+ export declare function isTerminalIntentStatus(status: unknown): boolean;
54
+ /** What happened to the action itself, which is what a caller usually wants to branch on. */
55
+ export type IntentOutcomeName = 'completed' | 'completed_unproven' | 'executed' | 'failed'
56
+ /** Nothing has executed yet. */
57
+ | 'pending' | 'unknown';
58
+ export interface IntentOutcome {
59
+ /** The gateway's status, verbatim. */
60
+ status: string;
61
+ class: IntentStatusClass;
62
+ terminal: boolean;
63
+ outcome: IntentOutcomeName;
64
+ /**
65
+ * Why, as a stable value. For `completed_unproven` this is always `execution_proof_unavailable`; for a failure it is the gateway's
66
+ * `reason_code`; otherwise null.
67
+ */
68
+ reason: string | null;
69
+ }
70
+ /** Read the named outcome off a transaction response. Never invents a state: an unrecognised status is `unknown`. */
71
+ export declare function intentOutcome(tx: {
72
+ status?: unknown;
73
+ reason_code?: unknown;
74
+ } | null | undefined): IntentOutcome;
75
+ //# sourceMappingURL=intent-states.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intent-states.d.ts","sourceRoot":"","sources":["../src/intent-states.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,8DAA8D;AAC9D,MAAM,MAAM,iBAAiB;AAC3B,iEAAiE;AAC/D,WAAW;AACb,qHAAqH;GACnH,UAAU;AACZ,qCAAqC;GACnC,kBAAkB;AACpB,gFAAgF;GAC9E,mBAAmB;AACrB,oCAAoC;GAClC,kBAAkB;AACpB,sHAAsH;GACpH,SAAS,CAAC;AAEd,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;CAc0C,CAAC;AAE3E,MAAM,MAAM,iBAAiB,GAAG,MAAM,OAAO,mBAAmB,CAAC;AAEjE,mGAAmG;AACnG,eAAO,MAAM,2BAA2B,gCAAgC,CAAC;AAEzE,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,GAAG,iBAAiB,CAIvE;AAED,oGAAoG;AACpG,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAG/D;AAED,6FAA6F;AAC7F,MAAM,MAAM,iBAAiB,GACzB,WAAW,GACX,oBAAoB,GACpB,UAAU,GACV,QAAQ;AACV,gCAAgC;GAC9B,SAAS,GACT,SAAS,CAAC;AAEd,MAAM,WAAW,aAAa;IAC5B,sCAAsC;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,iBAAiB,CAAC;IACzB,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,iBAAiB,CAAC;IAC3B;;;OAGG;IACH,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAED,qHAAqH;AACrH,wBAAgB,aAAa,CAAC,EAAE,EAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,WAAW,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,GAAG,SAAS,GAAG,aAAa,CAkB/G"}
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Where an intent can be, and what each place means.
3
+ *
4
+ * ONE table, used by `execute.wait()`, the CLI and the MCP server, so they cannot disagree about which statuses end a wait. Before
5
+ * this there were three copies of `['completed', 'delivered', 'proven']`, and none of them knew the two states the execution
6
+ * outcome model added:
7
+ *
8
+ * - `executed`: the action EXECUTED on its chain and its proof bundle is pending. Not a failure, and not terminal: CERTEN produces
9
+ * the bundle automatically and the intent then reads `completed`. The fee is held meanwhile.
10
+ * - `completed_unproven`: the action executed and its proof can NEVER be produced (declared by an operator with the evidence).
11
+ * Terminal. Billed gas only, fee waived. It is never "completed": nothing can be verified for it.
12
+ *
13
+ * `expired` is terminal too, and a failure: the intent will never execute. `wait()` used to poll through it to its timeout.
14
+ *
15
+ * The statuses are the gateway's own (`chk_intent_status`, api-gateway migration 053) and the spec's description of the field.
16
+ * `delivered` and `error` are older spellings this client has always treated as terminal; they stay in the table so a gateway that
17
+ * still sends them is not misread. A status that is not in the table is `unknown` and is never treated as terminal.
18
+ */
19
+ export const INTENT_STATUS_CLASS = {
20
+ created: 'in_flight',
21
+ signing_required: 'in_flight',
22
+ submitted: 'in_flight',
23
+ processing: 'in_flight',
24
+ anchoring: 'in_flight',
25
+ executed: 'executed',
26
+ completed: 'terminal_success',
27
+ proven: 'terminal_success',
28
+ delivered: 'terminal_success',
29
+ completed_unproven: 'terminal_gas_only',
30
+ failed: 'terminal_failure',
31
+ expired: 'terminal_failure',
32
+ error: 'terminal_failure',
33
+ };
34
+ /** The reason the gateway gives a `completed_unproven` intent: the proof can never be produced. */
35
+ export const EXECUTION_PROOF_UNAVAILABLE = 'execution_proof_unavailable';
36
+ export function classifyIntentStatus(status) {
37
+ return typeof status === 'string' && Object.prototype.hasOwnProperty.call(INTENT_STATUS_CLASS, status)
38
+ ? INTENT_STATUS_CLASS[status]
39
+ : 'unknown';
40
+ }
41
+ /** Does this status end a wait (success, gas-only, or failure)? `executed` and `unknown` do not. */
42
+ export function isTerminalIntentStatus(status) {
43
+ const c = classifyIntentStatus(status);
44
+ return c === 'terminal_success' || c === 'terminal_gas_only' || c === 'terminal_failure';
45
+ }
46
+ /** Read the named outcome off a transaction response. Never invents a state: an unrecognised status is `unknown`. */
47
+ export function intentOutcome(tx) {
48
+ const status = typeof tx?.status === 'string' ? tx.status : '';
49
+ const cls = classifyIntentStatus(status);
50
+ const reasonCode = typeof tx?.reason_code === 'string' && tx.reason_code ? tx.reason_code : null;
51
+ switch (cls) {
52
+ case 'terminal_success':
53
+ return { status, class: cls, terminal: true, outcome: 'completed', reason: null };
54
+ case 'terminal_gas_only':
55
+ return { status, class: cls, terminal: true, outcome: 'completed_unproven', reason: reasonCode ?? EXECUTION_PROOF_UNAVAILABLE };
56
+ case 'executed':
57
+ return { status, class: cls, terminal: false, outcome: 'executed', reason: null };
58
+ case 'terminal_failure':
59
+ return { status, class: cls, terminal: true, outcome: 'failed', reason: reasonCode };
60
+ case 'in_flight':
61
+ return { status, class: cls, terminal: false, outcome: 'pending', reason: null };
62
+ default:
63
+ return { status, class: cls, terminal: false, outcome: 'unknown', reason: null };
64
+ }
65
+ }
66
+ //# sourceMappingURL=intent-states.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intent-states.js","sourceRoot":"","sources":["../src/intent-states.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAiBH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,OAAO,EAAE,WAAW;IACpB,gBAAgB,EAAE,WAAW;IAC7B,SAAS,EAAE,WAAW;IACtB,UAAU,EAAE,WAAW;IACvB,SAAS,EAAE,WAAW;IACtB,QAAQ,EAAE,UAAU;IACpB,SAAS,EAAE,kBAAkB;IAC7B,MAAM,EAAE,kBAAkB;IAC1B,SAAS,EAAE,kBAAkB;IAC7B,kBAAkB,EAAE,mBAAmB;IACvC,MAAM,EAAE,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AAK,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,EAAE,UAAU,IAAI,2BAA2B,EAAE,CAAC;QAClI,KAAK,UAAU;YACb,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;QACpF,KAAK,kBAAkB;YACrB,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;QACvF,KAAK,WAAW;YACd,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;QACnF;YACE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IACrF,CAAC;AACH,CAAC"}
@@ -7,4 +7,22 @@
7
7
  * Building bodies through this keeps the wire payload exactly the set of fields the caller actually set.
8
8
  */
9
9
  export declare function omitUndefined<T extends Record<string, unknown>>(o: T): Partial<T>;
10
+ /**
11
+ * Build a request path from a template, encoding every interpolated value as exactly ONE path segment.
12
+ *
13
+ * apiPath`/v1/proof/${proofId}/bundle`
14
+ *
15
+ * Every id, hash and token reaching a url goes through here. Interpolating one raw let it change which route a call reached:
16
+ * an id containing `/` or `?` added segments or a query, and an id of `..` or `.` is resolved away by any proxy or server that
17
+ * normalises paths (`/v1/proof/../admin` is not `/v1/proof/<id>`). So:
18
+ *
19
+ * - `/`, `?`, `#`, `%`, spaces and every other reserved character are percent-encoded (`encodeURIComponent`);
20
+ * - a value that is only dots (`.`, `..`) is REFUSED, not encoded: `encodeURIComponent` leaves it alone, and even as `%2E%2E` the url
21
+ * parser treats it as `..` (measured: a request for `/v1/transaction/%2E%2E` arrived as `/v1/`). No genuine id is made of dots;
22
+ * - an empty, null or undefined value is REFUSED (`INVALID_PATH_PARAMETER`) rather than dropped: `identity.get('')` would otherwise
23
+ * request `/v1/identity/`, a different route, and answer with a list where a record was asked for.
24
+ *
25
+ * Only the interpolated values are encoded; the literal parts of the template are the route.
26
+ */
27
+ export declare function apiPath(strings: TemplateStringsArray, ...values: unknown[]): string;
10
28
  //# sourceMappingURL=internal.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAIjF"}
1
+ {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAIjF;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,oBAAoB,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAMnF"}
package/dist/internal.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { CertenError } from './errors.js';
1
2
  /**
2
3
  * Strip keys whose value is `undefined` before sending a body.
3
4
  *
@@ -13,4 +14,47 @@ export function omitUndefined(o) {
13
14
  out[k] = v;
14
15
  return out;
15
16
  }
17
+ /**
18
+ * Build a request path from a template, encoding every interpolated value as exactly ONE path segment.
19
+ *
20
+ * apiPath`/v1/proof/${proofId}/bundle`
21
+ *
22
+ * Every id, hash and token reaching a url goes through here. Interpolating one raw let it change which route a call reached:
23
+ * an id containing `/` or `?` added segments or a query, and an id of `..` or `.` is resolved away by any proxy or server that
24
+ * normalises paths (`/v1/proof/../admin` is not `/v1/proof/<id>`). So:
25
+ *
26
+ * - `/`, `?`, `#`, `%`, spaces and every other reserved character are percent-encoded (`encodeURIComponent`);
27
+ * - a value that is only dots (`.`, `..`) is REFUSED, not encoded: `encodeURIComponent` leaves it alone, and even as `%2E%2E` the url
28
+ * parser treats it as `..` (measured: a request for `/v1/transaction/%2E%2E` arrived as `/v1/`). No genuine id is made of dots;
29
+ * - an empty, null or undefined value is REFUSED (`INVALID_PATH_PARAMETER`) rather than dropped: `identity.get('')` would otherwise
30
+ * request `/v1/identity/`, a different route, and answer with a list where a record was asked for.
31
+ *
32
+ * Only the interpolated values are encoded; the literal parts of the template are the route.
33
+ */
34
+ export function apiPath(strings, ...values) {
35
+ let out = strings[0];
36
+ values.forEach((v, i) => {
37
+ out += segment(v, i + 1, strings) + strings[i + 1];
38
+ });
39
+ return out;
40
+ }
41
+ function segment(v, position, strings) {
42
+ const where = `${strings[position - 1].split('/').filter(Boolean).pop() ?? 'path'} parameter`;
43
+ if (typeof v !== 'string' && typeof v !== 'number' && typeof v !== 'bigint') {
44
+ throw new CertenError(`certen: ${where} must be a string or number, got ${v === null ? 'null' : typeof v}`, 0, 'INVALID_PATH_PARAMETER');
45
+ }
46
+ const s = String(v);
47
+ if (s === '')
48
+ throw new CertenError(`certen: ${where} is empty`, 0, 'INVALID_PATH_PARAMETER');
49
+ let enc;
50
+ try {
51
+ enc = encodeURIComponent(s);
52
+ }
53
+ catch {
54
+ throw new CertenError(`certen: ${where} is not valid text (a lone surrogate cannot be encoded)`, 0, 'INVALID_PATH_PARAMETER');
55
+ }
56
+ if (/^\.+$/.test(s))
57
+ throw new CertenError(`certen: ${where} cannot be "${s}": a path segment of dots would be resolved away by the url parser`, 0, 'INVALID_PATH_PARAMETER');
58
+ return enc;
59
+ }
16
60
  //# sourceMappingURL=internal.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAoC,CAAI;IACnE,MAAM,GAAG,GAA4B,EAAE,CAAC;IACxC,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;QAAE,IAAI,CAAC,KAAK,SAAS;YAAE,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IACxE,OAAO,GAAiB,CAAC;AAC3B,CAAC"}
1
+ {"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAoC,CAAI;IACnE,MAAM,GAAG,GAA4B,EAAE,CAAC;IACxC,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;QAAE,IAAI,CAAC,KAAK,SAAS;YAAE,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IACxE,OAAO,GAAiB,CAAC;AAC3B,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,OAAO,CAAC,OAA6B,EAAE,GAAG,MAAiB;IACzE,IAAI,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACrB,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QACtB,GAAG,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;IACH,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,OAAO,CAAC,CAAU,EAAE,QAAgB,EAAE,OAA6B;IAC1E,MAAM,KAAK,GAAG,GAAG,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,IAAI,MAAM,YAAY,CAAC;IAC9F,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;QAC5E,MAAM,IAAI,WAAW,CAAC,WAAW,KAAK,oCAAoC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,EAAE,wBAAwB,CAAC,CAAC;IAC3I,CAAC;IACD,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IACpB,IAAI,CAAC,KAAK,EAAE;QAAE,MAAM,IAAI,WAAW,CAAC,WAAW,KAAK,WAAW,EAAE,CAAC,EAAE,wBAAwB,CAAC,CAAC;IAC9F,IAAI,GAAW,CAAC;IAChB,IAAI,CAAC;QACH,GAAG,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAAC;IAC9B,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,WAAW,CAAC,WAAW,KAAK,yDAAyD,EAAE,CAAC,EAAE,wBAAwB,CAAC,CAAC;IAChI,CAAC;IACD,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;QAAE,MAAM,IAAI,WAAW,CAAC,WAAW,KAAK,eAAe,CAAC,oEAAoE,EAAE,CAAC,EAAE,wBAAwB,CAAC,CAAC;IAC9K,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,67 @@
1
+ export interface KeyPageReading {
2
+ /** The key page that was read. */
3
+ url: string;
4
+ /** The Accumulate node that answered. */
5
+ rpc: string;
6
+ /** SHA-256 of each public key on the page, lower-case hex. */
7
+ keyHashes: string[];
8
+ /**
9
+ * The page's credit balance exactly as the node reports it. The spec does not pin whether that is whole credits or hundredths of one, so
10
+ * it is never converted here: zero is zero in either, and nothing else should be read as a quantity of credits without knowing which.
11
+ */
12
+ creditBalance: number | null;
13
+ version: number | null;
14
+ /** How many of the page's keys must sign for a transaction to execute. */
15
+ acceptThreshold: number | null;
16
+ }
17
+ export type KeyPageHold =
18
+ /** The page was read and lists the key. */
19
+ {
20
+ state: 'holds';
21
+ reading: KeyPageReading;
22
+ }
23
+ /** The page was read and does not list the key. A fact about the page, not a failure to read it. */
24
+ | {
25
+ state: 'absent';
26
+ reading: KeyPageReading;
27
+ }
28
+ /** The page could not be read. `notFound` is the node saying it has no such account (a wrong node, or an identity not yet anchored). */
29
+ | {
30
+ state: 'unreadable';
31
+ rpc: string;
32
+ reason: string;
33
+ notFound: boolean;
34
+ };
35
+ export interface KeyPageReadOptions {
36
+ /** The Accumulate API endpoint, e.g. `https://kermit.accumulatenetwork.io/v3`. */
37
+ rpc: string;
38
+ /** Injectable for tests; defaults to the platform `fetch`. */
39
+ fetch?: typeof fetch;
40
+ /** Default 10 seconds. */
41
+ timeoutMs?: number;
42
+ }
43
+ /**
44
+ * The key hashes on a key page, lower-case hex.
45
+ *
46
+ * Accumulate v3 returns `publicKeyHash` in more than one shape - a hex string, or a serialised Node Buffer (`{type:'Buffer',data:[...]}`)
47
+ * that leaked out of a JSON serializer - and the gateway normalises both for the same reason: a comparison that silently failed to parse
48
+ * one of them would report "this key is not on the page" for a key that is.
49
+ */
50
+ export declare function keyHashesOf(account: {
51
+ keys?: unknown;
52
+ } | null | undefined): string[];
53
+ /**
54
+ * Read one key page from an Accumulate node.
55
+ *
56
+ * @throws CertenError `ACCUMULATE_RPC_INVALID` (a bad endpoint, before any request), `KEY_PAGE_NOT_FOUND` (the node has no such account) or
57
+ * `KEY_PAGE_UNREADABLE` (anything else: no answer, a non-200, a malformed reply, an account that is not a key page).
58
+ */
59
+ export declare function readKeyPage(keyPageUrl: string, options: KeyPageReadOptions): Promise<KeyPageReading>;
60
+ /**
61
+ * Does this key page list this key?
62
+ *
63
+ * `keyHash` is the SHA-256 of the raw public key, hex (what `identity.create` takes as `publicKeyHash`). A malformed hash is a programming
64
+ * error and throws; a page that cannot be read is a result.
65
+ */
66
+ export declare function verifyKeyPageHolds(keyPageUrl: string, keyHash: string, options: KeyPageReadOptions): Promise<KeyPageHold>;
67
+ //# sourceMappingURL=key-page.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"key-page.d.ts","sourceRoot":"","sources":["../src/key-page.ts"],"names":[],"mappings":"AAgCA,MAAM,WAAW,cAAc;IAC7B,kCAAkC;IAClC,GAAG,EAAE,MAAM,CAAC;IACZ,yCAAyC;IACzC,GAAG,EAAE,MAAM,CAAC;IACZ,8DAA8D;IAC9D,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB;;;OAGG;IACH,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,0EAA0E;IAC1E,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAED,MAAM,MAAM,WAAW;AACrB,2CAA2C;AACzC;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,cAAc,CAAA;CAAE;AAC7C,oGAAoG;GAClG;IAAE,KAAK,EAAE,QAAQ,CAAC;IAAC,OAAO,EAAE,cAAc,CAAA;CAAE;AAC9C,wIAAwI;GACtI;IAAE,KAAK,EAAE,YAAY,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,CAAC;AAE5E,MAAM,WAAW,kBAAkB;IACjC,kFAAkF;IAClF,GAAG,EAAE,MAAM,CAAC;IACZ,8DAA8D;IAC9D,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,0BAA0B;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAUD;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE;IAAE,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,EAAE,CAapF;AA6BD;;;;;GAKG;AACH,wBAAsB,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,cAAc,CAAC,CAiE1G;AAED;;;;;GAKG;AACH,wBAAsB,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,WAAW,CAAC,CAe/H"}
@@ -0,0 +1,154 @@
1
+ import { CertenError } from './errors.js';
2
+ const DEFAULT_TIMEOUT_MS = 10_000;
3
+ /** A key page is a few kilobytes. Anything past this is not one, and is not read to the end. */
4
+ const MAX_RESPONSE_CHARS = 1_000_000;
5
+ const HEX = /^[0-9a-f]+$/;
6
+ const hex = (bytes) => bytes.map((b) => (b & 0xff).toString(16).padStart(2, '0')).join('');
7
+ /**
8
+ * The key hashes on a key page, lower-case hex.
9
+ *
10
+ * Accumulate v3 returns `publicKeyHash` in more than one shape - a hex string, or a serialised Node Buffer (`{type:'Buffer',data:[...]}`)
11
+ * that leaked out of a JSON serializer - and the gateway normalises both for the same reason: a comparison that silently failed to parse
12
+ * one of them would report "this key is not on the page" for a key that is.
13
+ */
14
+ export function keyHashesOf(account) {
15
+ const keys = account?.keys;
16
+ if (!Array.isArray(keys))
17
+ return [];
18
+ const out = [];
19
+ for (const k of keys) {
20
+ const raw = k?.publicKeyHash;
21
+ let h;
22
+ if (typeof raw === 'string')
23
+ h = raw.trim().replace(/^0x/i, '').toLowerCase();
24
+ else if (Array.isArray(raw))
25
+ h = hex(raw);
26
+ else if (raw && typeof raw === 'object' && Array.isArray(raw.data))
27
+ h = hex(raw.data);
28
+ if (h && h.length % 2 === 0 && HEX.test(h))
29
+ out.push(h);
30
+ }
31
+ return out;
32
+ }
33
+ function fail(message, code) {
34
+ throw new CertenError(message, 0, code);
35
+ }
36
+ function checkEndpoint(rpc) {
37
+ let u;
38
+ try {
39
+ u = new URL(rpc);
40
+ }
41
+ catch {
42
+ return fail(`certen: "${rpc}" is not a URL, so it cannot be an Accumulate API endpoint.`, 'ACCUMULATE_RPC_INVALID');
43
+ }
44
+ if (u.protocol !== 'https:' && u.protocol !== 'http:') {
45
+ fail(`certen: the Accumulate API endpoint must be http or https, not ${u.protocol}`, 'ACCUMULATE_RPC_INVALID');
46
+ }
47
+ // A credential in the URL would be sent on to whoever answers; there is no reason for one on a public read.
48
+ if (u.username || u.password) {
49
+ fail('certen: the Accumulate API endpoint must not carry a username or password in the URL.', 'ACCUMULATE_RPC_INVALID');
50
+ }
51
+ return u.toString();
52
+ }
53
+ const asNumber = (v) => {
54
+ if (v === undefined || v === null || v === '')
55
+ return null;
56
+ const n = Number(v);
57
+ return Number.isFinite(n) ? n : null;
58
+ };
59
+ /**
60
+ * Read one key page from an Accumulate node.
61
+ *
62
+ * @throws CertenError `ACCUMULATE_RPC_INVALID` (a bad endpoint, before any request), `KEY_PAGE_NOT_FOUND` (the node has no such account) or
63
+ * `KEY_PAGE_UNREADABLE` (anything else: no answer, a non-200, a malformed reply, an account that is not a key page).
64
+ */
65
+ export async function readKeyPage(keyPageUrl, options) {
66
+ if (!/^acc:\/\/\S+$/i.test(keyPageUrl)) {
67
+ fail(`certen: "${keyPageUrl}" is not an Accumulate URL (acc://...), so it cannot be a key page.`, 'KEY_PAGE_UNREADABLE');
68
+ }
69
+ const endpoint = checkEndpoint(options.rpc);
70
+ const doFetch = options.fetch ?? (typeof fetch === 'function' ? fetch : undefined);
71
+ if (!doFetch)
72
+ fail('certen: this environment has no fetch, so the Accumulate node cannot be asked.', 'KEY_PAGE_UNREADABLE');
73
+ const controller = new AbortController();
74
+ const timer = setTimeout(() => controller.abort(), options.timeoutMs ?? DEFAULT_TIMEOUT_MS);
75
+ let text;
76
+ try {
77
+ const res = await doFetch(endpoint, {
78
+ method: 'POST',
79
+ headers: { 'content-type': 'application/json' },
80
+ // The same request the gateway makes for the same page.
81
+ body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'query', params: { scope: keyPageUrl } }),
82
+ // A node that redirects is not the node that was named. Not followed.
83
+ redirect: 'error',
84
+ signal: controller.signal,
85
+ });
86
+ if (!res.ok)
87
+ fail(`certen: the Accumulate node at ${endpoint} answered HTTP ${res.status}.`, 'KEY_PAGE_UNREADABLE');
88
+ text = await res.text();
89
+ }
90
+ catch (err) {
91
+ if (err instanceof CertenError)
92
+ throw err;
93
+ const why = controller.signal.aborted
94
+ ? `did not answer within ${(options.timeoutMs ?? DEFAULT_TIMEOUT_MS) / 1000}s`
95
+ : err instanceof Error ? err.message : String(err);
96
+ return fail(`certen: the Accumulate node at ${endpoint} ${why}`, 'KEY_PAGE_UNREADABLE');
97
+ }
98
+ finally {
99
+ clearTimeout(timer);
100
+ }
101
+ if (text.length > MAX_RESPONSE_CHARS) {
102
+ fail(`certen: the Accumulate node at ${endpoint} sent a reply too large to be a key page.`, 'KEY_PAGE_UNREADABLE');
103
+ }
104
+ let body;
105
+ try {
106
+ body = JSON.parse(text);
107
+ }
108
+ catch {
109
+ return fail(`certen: the Accumulate node at ${endpoint} did not answer with JSON.`, 'KEY_PAGE_UNREADABLE');
110
+ }
111
+ if (body?.error) {
112
+ const message = typeof body.error.message === 'string' ? body.error.message : JSON.stringify(body.error);
113
+ fail(`certen: the Accumulate node at ${endpoint} could not read ${keyPageUrl}: ${message}`, /not found|does not exist|no such/i.test(message) ? 'KEY_PAGE_NOT_FOUND' : 'KEY_PAGE_UNREADABLE');
114
+ }
115
+ const account = body?.result?.account;
116
+ if (!account || typeof account !== 'object') {
117
+ return fail(`certen: the Accumulate node at ${endpoint} returned no account record for ${keyPageUrl}.`, 'KEY_PAGE_UNREADABLE');
118
+ }
119
+ if (account.type !== undefined && account.type !== 'keyPage') {
120
+ fail(`certen: ${keyPageUrl} is a ${String(account.type)} on Accumulate, not a key page.`, 'KEY_PAGE_UNREADABLE');
121
+ }
122
+ return {
123
+ url: keyPageUrl,
124
+ rpc: endpoint,
125
+ keyHashes: keyHashesOf(account),
126
+ creditBalance: asNumber(account.creditBalance),
127
+ version: asNumber(account.version),
128
+ acceptThreshold: asNumber(account.acceptThreshold),
129
+ };
130
+ }
131
+ /**
132
+ * Does this key page list this key?
133
+ *
134
+ * `keyHash` is the SHA-256 of the raw public key, hex (what `identity.create` takes as `publicKeyHash`). A malformed hash is a programming
135
+ * error and throws; a page that cannot be read is a result.
136
+ */
137
+ export async function verifyKeyPageHolds(keyPageUrl, keyHash, options) {
138
+ const want = keyHash.trim().replace(/^0x/i, '').toLowerCase();
139
+ if (want.length !== 64 || !HEX.test(want)) {
140
+ throw new CertenError(`certen: "${keyHash}" is not a key hash. Expected 64 hex characters (SHA-256 of the public key).`, 0, 'INVALID_KEY_HASH');
141
+ }
142
+ let reading;
143
+ try {
144
+ reading = await readKeyPage(keyPageUrl, options);
145
+ }
146
+ catch (err) {
147
+ if (err instanceof CertenError && err.code !== 'ACCUMULATE_RPC_INVALID') {
148
+ return { state: 'unreadable', rpc: options.rpc, reason: err.message.replace(/^certen: /, ''), notFound: err.code === 'KEY_PAGE_NOT_FOUND' };
149
+ }
150
+ throw err;
151
+ }
152
+ return { state: reading.keyHashes.includes(want) ? 'holds' : 'absent', reading };
153
+ }
154
+ //# sourceMappingURL=key-page.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"key-page.js","sourceRoot":"","sources":["../src/key-page.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAkE1C,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAClC,gGAAgG;AAChG,MAAM,kBAAkB,GAAG,SAAS,CAAC;AAErC,MAAM,GAAG,GAAG,aAAa,CAAC;AAE1B,MAAM,GAAG,GAAG,CAAC,KAAe,EAAU,EAAE,CAAC,KAAK,CAA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AW,IAAI,GAAG,CAAC,IAAI,KAAK,wBAAwB,EAAE,CAAC;YACxE,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,EAAE,QAAQ,EAAE,GAAG,CAAC,IAAI,KAAK,oBAAoB,EAAE,CAAC;QAC9I,CAAC;QACD,MAAM,GAAG,CAAC;IACZ,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,EAAE,OAAO,EAAE,CAAC;AACnF,CAAC"}
@@ -0,0 +1,19 @@
1
+ export interface OriginCheck {
2
+ ok: boolean;
3
+ reason?: string;
4
+ resolved?: string;
5
+ }
6
+ /** Would a request for `url` stay on `baseURL`'s origin, with no credentials smuggled in the url? */
7
+ export declare function checkOwnOrigin(url: string | undefined, baseURL: string | undefined): OriginCheck;
8
+ /**
9
+ * Throw `CertenForeignOriginError` unless `url` stays on the client's own origin.
10
+ * `what` names where the url came from (`submit_url`, `request`, `redirect`), so the message says what to distrust.
11
+ */
12
+ export declare function assertOwnOrigin(url: string | undefined, baseURL: string | undefined, what: string): void;
13
+ /**
14
+ * Is a redirect from `from` to `to` safe for a request carrying credentials?
15
+ * Same origin, or an http -> https upgrade of the same host on the default ports (a gateway configured as `http://` that
16
+ * redirects to its own TLS port); never another host, and never https -> http.
17
+ */
18
+ export declare function redirectStaysOnOrigin(from: string, to: string): boolean;
19
+ //# sourceMappingURL=origin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"origin.d.ts","sourceRoot":"","sources":["../src/origin.ts"],"names":[],"mappings":"AA0BA,MAAM,WAAW,WAAW;IAAG,EAAE,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE;AAEhF,qGAAqG;AACrG,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,WAAW,CAkBhG;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CASxG;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAQvE"}