@mcsherrylabs/evolver-mcp 0.13.0 → 0.15.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 (118) hide show
  1. package/deploy/docker-compose.http.yml +45 -0
  2. package/deploy/docker-compose.yml +4 -1
  3. package/dist/application-signer.d.ts +1 -1
  4. package/dist/application-signer.d.ts.map +1 -1
  5. package/dist/attachments.d.ts +1 -1
  6. package/dist/attachments.d.ts.map +1 -1
  7. package/dist/attachments.js +2 -2
  8. package/dist/attachments.js.map +1 -1
  9. package/dist/bootstrap.d.ts +36 -4
  10. package/dist/bootstrap.d.ts.map +1 -1
  11. package/dist/bootstrap.js +35 -11
  12. package/dist/bootstrap.js.map +1 -1
  13. package/dist/content-file-tools.js +1 -1
  14. package/dist/content-file-tools.js.map +1 -1
  15. package/dist/content-files.d.ts +1 -1
  16. package/dist/content-files.d.ts.map +1 -1
  17. package/dist/content-files.js +1 -1
  18. package/dist/content-files.js.map +1 -1
  19. package/dist/content-ranges.d.ts +1 -1
  20. package/dist/content-ranges.d.ts.map +1 -1
  21. package/dist/group-crypto-tools.js +1 -1
  22. package/dist/group-crypto-tools.js.map +1 -1
  23. package/dist/group-crypto.d.ts +2 -2
  24. package/dist/group-crypto.d.ts.map +1 -1
  25. package/dist/group-crypto.js +1 -1
  26. package/dist/group-crypto.js.map +1 -1
  27. package/dist/http-transport.d.ts +87 -0
  28. package/dist/http-transport.d.ts.map +1 -0
  29. package/dist/http-transport.js +359 -0
  30. package/dist/http-transport.js.map +1 -0
  31. package/dist/inbox.d.ts +1 -1
  32. package/dist/inbox.d.ts.map +1 -1
  33. package/dist/inbox.js +1 -1
  34. package/dist/inbox.js.map +1 -1
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +254 -115
  37. package/dist/index.js.map +1 -1
  38. package/dist/install-http.d.ts +27 -0
  39. package/dist/install-http.d.ts.map +1 -0
  40. package/dist/install-http.js +192 -0
  41. package/dist/install-http.js.map +1 -0
  42. package/dist/install.d.ts +18 -0
  43. package/dist/install.d.ts.map +1 -1
  44. package/dist/install.js +128 -22
  45. package/dist/install.js.map +1 -1
  46. package/dist/login.d.ts +1 -1
  47. package/dist/login.d.ts.map +1 -1
  48. package/dist/mcp.d.ts +2 -2
  49. package/dist/mcp.d.ts.map +1 -1
  50. package/dist/p2p.d.ts +1 -1
  51. package/dist/p2p.d.ts.map +1 -1
  52. package/dist/p2p.js +1 -1
  53. package/dist/p2p.js.map +1 -1
  54. package/dist/processor.d.ts +1 -1
  55. package/dist/processor.d.ts.map +1 -1
  56. package/dist/processor.js +1 -1
  57. package/dist/processor.js.map +1 -1
  58. package/dist/signed-http.d.ts +1 -1
  59. package/dist/signed-http.d.ts.map +1 -1
  60. package/dist/tools.d.ts +5 -3
  61. package/dist/tools.d.ts.map +1 -1
  62. package/dist/tools.js +34 -34
  63. package/dist/tools.js.map +1 -1
  64. package/dist/transaction-interchange-tools.js +1 -1
  65. package/dist/transaction-interchange-tools.js.map +1 -1
  66. package/dist/transaction-interchange.d.ts +5 -2
  67. package/dist/transaction-interchange.d.ts.map +1 -1
  68. package/dist/transaction-interchange.js +10 -10
  69. package/dist/transaction-interchange.js.map +1 -1
  70. package/package.json +10 -16
  71. package/dist/amount.d.ts +0 -23
  72. package/dist/amount.d.ts.map +0 -1
  73. package/dist/amount.js +0 -53
  74. package/dist/amount.js.map +0 -1
  75. package/dist/channel.d.ts +0 -77
  76. package/dist/channel.d.ts.map +0 -1
  77. package/dist/channel.js +0 -287
  78. package/dist/channel.js.map +0 -1
  79. package/dist/claim.d.ts +0 -48
  80. package/dist/claim.d.ts.map +0 -1
  81. package/dist/claim.js +0 -81
  82. package/dist/claim.js.map +0 -1
  83. package/dist/content.d.ts +0 -94
  84. package/dist/content.d.ts.map +0 -1
  85. package/dist/content.js +0 -215
  86. package/dist/content.js.map +0 -1
  87. package/dist/group-ownership.d.ts +0 -78
  88. package/dist/group-ownership.d.ts.map +0 -1
  89. package/dist/group-ownership.js +0 -324
  90. package/dist/group-ownership.js.map +0 -1
  91. package/dist/group.d.ts +0 -60
  92. package/dist/group.d.ts.map +0 -1
  93. package/dist/group.js +0 -204
  94. package/dist/group.js.map +0 -1
  95. package/dist/identity.d.ts +0 -87
  96. package/dist/identity.d.ts.map +0 -1
  97. package/dist/identity.js +0 -236
  98. package/dist/identity.js.map +0 -1
  99. package/dist/node-transport.d.ts +0 -14
  100. package/dist/node-transport.d.ts.map +0 -1
  101. package/dist/node-transport.js +0 -54
  102. package/dist/node-transport.js.map +0 -1
  103. package/dist/read.d.ts +0 -252
  104. package/dist/read.d.ts.map +0 -1
  105. package/dist/read.js +0 -320
  106. package/dist/read.js.map +0 -1
  107. package/dist/result.d.ts +0 -110
  108. package/dist/result.d.ts.map +0 -1
  109. package/dist/result.js +0 -97
  110. package/dist/result.js.map +0 -1
  111. package/dist/signer.d.ts +0 -37
  112. package/dist/signer.d.ts.map +0 -1
  113. package/dist/signer.js +0 -76
  114. package/dist/signer.js.map +0 -1
  115. package/dist/write.d.ts +0 -214
  116. package/dist/write.d.ts.map +0 -1
  117. package/dist/write.js +0 -399
  118. package/dist/write.js.map +0 -1
@@ -1,87 +0,0 @@
1
- import type { Signer } from "@mcsherrylabs/evolver-client";
2
- import type { ChainReads } from "./read.js";
3
- import type { SignedIdentity, SignedGroup, SignedChannel, SignedRecord } from "./write.js";
4
- import type { ToolResult } from "./result.js";
5
- /** What the identity verbs need from the world. NO `submitTx` — deliberately: the five signing
6
- * verbs submit nothing, so the capability is not present to reach for (SIGN-20 is structural). */
7
- export interface IdentityOpsDeps {
8
- readonly identity: string;
9
- readonly signer: Signer;
10
- readonly ttlOffset?: number;
11
- readonly reads: ChainReads;
12
- }
13
- /** A signed identity operation, as returned by a signing verb. Always `ok` once composed. */
14
- export type IdentitySignResult = ToolResult<SignedIdentity>;
15
- /** Decode a starting credit from a decimal string, refusing `< 1`, non-integers, and negative/hex
16
- * forms. The chain FINES a zero- or negative-credit creation rather than refusing it, so the whole
17
- * point is this refusal happening BEFORE anything is signed (Pitfall 4). */
18
- export declare function parseInitialCredit(input: string): {
19
- ok: true;
20
- value: bigint;
21
- } | {
22
- ok: false;
23
- error: string;
24
- };
25
- /**
26
- * Compose a body into a signed identity transaction and record it — in ONE call. Mirrors
27
- * `signTransfer`'s inline compose→sign→record: `buildSignedTx` → `txIdHex` → record into the two
28
- * session stores via `recordSigned`. It SUBMITS NOTHING.
29
- *
30
- * This is the single compose implementation, re-exported from `src/write.ts` as `composeAndSign`
31
- * (one compose path, never two). The `ledgerId` is always `LEDGER.identity` at the call sites.
32
- */
33
- export declare function composeIdentityTx(deps: IdentityOpsDeps, args: {
34
- ledgerId: string;
35
- body: Uint8Array;
36
- ttlRound: number;
37
- signedAtRound: number;
38
- verb: SignedIdentity["verb"] | SignedGroup["verb"] | SignedChannel["verb"];
39
- fields: Record<string, string>;
40
- maxToll?: bigint;
41
- }): ToolResult<SignedRecord>;
42
- /**
43
- * Sponsor a new identity, paid for by this agent — signed for `deps.identity`, the configured host
44
- * identity as `senderNodeId` (never a caller-chosen node id).
45
- *
46
- * ⚠️ THE CHAIN'S KEY RULES ARE ENFORCED HERE, not left to it, because its answer arrives too late
47
- * to help: a body with the wrong keys is ORDERED and FINED 100, not refused. Exactly one
48
- * BLS12-381-G1 and one Ed25519, each at label "", a starting credit >= 1, and both keys carrying a
49
- * proof of possession from their holder.
50
- */
51
- export declare function signCreateIdentity(deps: IdentityOpsDeps, params: {
52
- keys: Array<{
53
- keyType: string;
54
- keyLabel: string;
55
- publicKey: string;
56
- popSignature: string;
57
- }>;
58
- initialCredit: string;
59
- }): Promise<ToolResult<SignedRecord>>;
60
- /**
61
- * Delete the identity this agent signs as. SELF-DELETION ONLY (Pitfall 5): `confirmName` must match
62
- * `deps.identity`, else the chain would fine a deletion naming another identity.
63
- */
64
- export declare function signDeleteIdentity(deps: IdentityOpsDeps, params: {
65
- confirmName: string;
66
- }): Promise<ToolResult<SignedRecord>>;
67
- export declare const signAddKey: (deps: IdentityOpsDeps, p: {
68
- keyType: string;
69
- keyLabel: string;
70
- publicKey: string;
71
- popSignature: string;
72
- }) => Promise<ToolResult<SignedRecord>>;
73
- export declare const signReplaceKey: (deps: IdentityOpsDeps, p: {
74
- keyType: string;
75
- keyLabel: string;
76
- publicKey: string;
77
- popSignature: string;
78
- }) => Promise<ToolResult<SignedRecord>>;
79
- /**
80
- * Remove one of this identity's own keys. ⚠️ THE CHAIN WILL NOT STOP YOU LOCKING YOURSELF OUT — its
81
- * only guard refuses a committee member deleting its default consensus key.
82
- */
83
- export declare function signDeleteKey(deps: IdentityOpsDeps, p: {
84
- keyType: string;
85
- keyLabel: string;
86
- }): Promise<ToolResult<SignedRecord>>;
87
- //# sourceMappingURL=identity.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AA0BA,OAAO,KAAK,EAAE,MAAM,EAAY,MAAM,8BAA8B,CAAC;AACrE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE5C,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC3F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C;mGACmG;AACnG,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;CAC5B;AAED,6FAA6F;AAC7F,MAAM,MAAM,kBAAkB,GAAG,UAAU,CAAC,cAAc,CAAC,CAAC;AAE5D;;6EAE6E;AAC7E,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAA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;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,sCACpG,CAAC;AAEhC,eAAO,MAAM,cAAc,GAAI,MAAM,eAAe,EAAE,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,sCACpG,CAAC;AAEpC;;;GAGG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,eAAe,EACrB,CAAC,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GACvC,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,CAiBnC"}
package/dist/identity.js DELETED
@@ -1,236 +0,0 @@
1
- // Identity-lifecycle signing verbs (SIGN-03..07): sign create/delete identity and add/replace/delete
2
- // key. Each is a compose→sign→record→return-txId operation with ZERO submit, mirroring Phase 2's
3
- // `signTransfer` (SIGN-20) and resolving in the SAME `submitSigned`/`inspectSigned` path (SIGN-19).
4
- //
5
- // The ledger is pinned to `LEDGER.identity` (never a caller-chosen channel or core-ledger id), so
6
- // nothing here can reach a node before `evolver_submit`. The costly local refusals — create-identity
7
- // key rules, delete-identity self-check, empty-PoP refusal — fire BEFORE anything is signed, because
8
- // the chain's answer for a malformed body arrives as a FINE, too late to refuse (Pitfalls 4/5).
9
- //
10
- // ⚠️ KEY MATERIAL NEVER REACHES A RECORD OR A REFUSAL. Records carry key `type`/`label` and the txId
11
- // only; the caller supplies the holder-produced `popSignature` bytes, which are folded into the
12
- // composed body by the SDK encoder — this process never computes a PoP digest and never signs for a
13
- // key it does not hold.
14
- import { LEDGER, buildSignedTx, txIdHex, hexToBytes, createIdentityInner, createIdentityBody, deleteIdentityBody, addKeyBody, replaceKeyBody, deleteKeyBody, } from "@mcsherrylabs/evolver-client";
15
- import { DEFAULT_TTL_OFFSET, recordSigned } from "./write.js";
16
- /** Decode a starting credit from a decimal string, refusing `< 1`, non-integers, and negative/hex
17
- * forms. The chain FINES a zero- or negative-credit creation rather than refusing it, so the whole
18
- * point is this refusal happening BEFORE anything is signed (Pitfall 4). */
19
- export function parseInitialCredit(input) {
20
- const s = String(input ?? "").trim();
21
- if (!/^[1-9][0-9]*$/.test(s))
22
- return {
23
- ok: false,
24
- error: `initialCredit "${s}" is not a positive decimal integer — it must be at least 1, because ` +
25
- `a zero- or negative-credit creation is ordered and FINED rather than refused`,
26
- };
27
- return { ok: true, value: BigInt(s) };
28
- }
29
- /**
30
- * Compose a body into a signed identity transaction and record it — in ONE call. Mirrors
31
- * `signTransfer`'s inline compose→sign→record: `buildSignedTx` → `txIdHex` → record into the two
32
- * session stores via `recordSigned`. It SUBMITS NOTHING.
33
- *
34
- * This is the single compose implementation, re-exported from `src/write.ts` as `composeAndSign`
35
- * (one compose path, never two). The `ledgerId` is always `LEDGER.identity` at the call sites.
36
- */
37
- export function composeIdentityTx(deps, args) {
38
- // Resolve once for the envelope, digest and inspection. Call-site metadata must not override
39
- // the channel write's effective signed consent (including the SDK's zero default).
40
- const maxToll = args.maxToll ?? 0n;
41
- const fields = args.verb === "channel_write"
42
- ? { ...args.fields, maxToll: maxToll.toString() }
43
- : { ...args.fields };
44
- const bytes = buildSignedTx({
45
- ledgerId: args.ledgerId,
46
- senderNodeId: deps.identity,
47
- body: args.body,
48
- ttlRound: args.ttlRound,
49
- signers: [deps.signer],
50
- maxToll,
51
- });
52
- const id = txIdHex(args.ledgerId, deps.identity, args.ttlRound, args.body, maxToll);
53
- const signed = {
54
- txId: id,
55
- expiresAtRound: args.ttlRound,
56
- signedAtRound: args.signedAtRound,
57
- verb: args.verb,
58
- fields,
59
- summary: { sender: deps.identity, ...fields },
60
- };
61
- recordSigned(signed, bytes);
62
- return { kind: "ok", value: signed };
63
- }
64
- /** Read the chain tip to bound a transaction's life; an unreachable chain is `unreachable`, never a
65
- * submit. */
66
- async function tipOrUnreachable(deps) {
67
- try {
68
- return await deps.reads.currentRound();
69
- }
70
- catch (e) {
71
- return { kind: "unreachable", chain: "", cause: e instanceof Error ? e.message : String(e) };
72
- }
73
- }
74
- /**
75
- * Sponsor a new identity, paid for by this agent — signed for `deps.identity`, the configured host
76
- * identity as `senderNodeId` (never a caller-chosen node id).
77
- *
78
- * ⚠️ THE CHAIN'S KEY RULES ARE ENFORCED HERE, not left to it, because its answer arrives too late
79
- * to help: a body with the wrong keys is ORDERED and FINED 100, not refused. Exactly one
80
- * BLS12-381-G1 and one Ed25519, each at label "", a starting credit >= 1, and both keys carrying a
81
- * proof of possession from their holder.
82
- */
83
- export async function signCreateIdentity(deps, params) {
84
- const credit = parseInitialCredit(params.initialCredit);
85
- if (!credit.ok)
86
- return { kind: "partial", what: "initialCredit", cause: credit.error };
87
- const keys = Array.isArray(params.keys) ? params.keys : [];
88
- const bls = keys.filter((k) => k.keyType === "BLS12-381-G1");
89
- const ed = keys.filter((k) => k.keyType === "Ed25519");
90
- if (bls.length !== 1 || ed.length !== 1 || keys.length !== 2)
91
- return {
92
- kind: "partial",
93
- what: "keys",
94
- cause: "exactly one BLS12-381-G1 and one Ed25519 are required, each at the default label. " +
95
- "A body without both is ordered and FINED 100 rather than refused, so it is refused here.",
96
- };
97
- if (keys.some((k) => String(k.keyLabel ?? "") !== ""))
98
- return {
99
- kind: "partial",
100
- what: "keys",
101
- cause: "both keys must be at the default (empty) label — a non-empty label is refused here rather than fined on-chain",
102
- };
103
- // Empty-PoP refusal: this agent signs for NO key it does not hold (T-03-01). Named by field, never bytes.
104
- const empty = keys.findIndex((k) => !k.popSignature || String(k.popSignature).length === 0);
105
- if (empty !== -1)
106
- return {
107
- kind: "partial",
108
- what: `keys.${empty}.popSignature`,
109
- cause: "each key needs a proof of possession from its holder — this agent signs for no key it does not hold",
110
- };
111
- // Hex-decode each key, refusing (naming the PATH) on non-hex/odd-length input (T-03-07). The
112
- // refusal names the field, never echoes the bytes.
113
- const decoded = [];
114
- for (let i = 0; i < keys.length; i++) {
115
- const k = keys[i];
116
- try {
117
- const publicKey = hexToBytes(String(k.publicKey ?? ""));
118
- // Empty-publicKey refusal: zero bytes, not an error — refused for free rather than fined.
119
- if (publicKey.length === 0)
120
- return { kind: "partial", what: `keys.${i}.publicKey`, cause: "a key is needed" };
121
- const popSig = hexToBytes(String(k.popSignature ?? ""));
122
- decoded.push({ keyType: k.keyType, publicKey, keyLabel: String(k.keyLabel ?? ""), popSig });
123
- }
124
- catch (e) {
125
- return { kind: "partial", what: `keys.${i}`, cause: e instanceof Error ? e.message : String(e) };
126
- }
127
- }
128
- const tip = await tipOrUnreachable(deps);
129
- if (typeof tip !== "number")
130
- return tip;
131
- const expiresAtRound = tip + (deps.ttlOffset ?? DEFAULT_TTL_OFFSET);
132
- const body = createIdentityBody(createIdentityInner(deps.identity, credit.value, decoded, true));
133
- return composeIdentityTx(deps, {
134
- ledgerId: LEDGER.identity,
135
- body,
136
- ttlRound: expiresAtRound,
137
- signedAtRound: tip,
138
- verb: "create_identity",
139
- fields: { initialCredit: credit.value.toString() },
140
- });
141
- }
142
- /**
143
- * Delete the identity this agent signs as. SELF-DELETION ONLY (Pitfall 5): `confirmName` must match
144
- * `deps.identity`, else the chain would fine a deletion naming another identity.
145
- */
146
- export async function signDeleteIdentity(deps, params) {
147
- const confirmName = String(params.confirmName ?? "").trim();
148
- if (confirmName !== deps.identity)
149
- return {
150
- kind: "partial",
151
- what: "confirmName",
152
- cause: `this deletes THIS identity and nothing else — the chain fines a deletion naming another. ` +
153
- `Pass "${deps.identity}" to mean it.`,
154
- };
155
- const tip = await tipOrUnreachable(deps);
156
- if (typeof tip !== "number")
157
- return tip;
158
- const expiresAtRound = tip + (deps.ttlOffset ?? DEFAULT_TTL_OFFSET);
159
- return composeIdentityTx(deps, {
160
- ledgerId: LEDGER.identity,
161
- body: deleteIdentityBody(deps.identity),
162
- ttlRound: expiresAtRound,
163
- signedAtRound: tip,
164
- verb: "delete_identity",
165
- fields: { target: deps.identity },
166
- });
167
- }
168
- /** Add/replace share one shape, differing only by verb tag and encoder. The SDK encoders keep them
169
- * distinct (a shared hand-rolled digest would make an AddKey proof valid for a ReplaceKey). */
170
- async function signKeyOp(deps, verb, p) {
171
- const keyType = String(p.keyType ?? "").trim();
172
- const keyLabel = String(p.keyLabel ?? "");
173
- let publicKey, popSignature;
174
- try {
175
- publicKey = hexToBytes(String(p.publicKey ?? ""));
176
- }
177
- catch (e) {
178
- return { kind: "partial", what: "publicKey", cause: e instanceof Error ? e.message : String(e) };
179
- }
180
- // Empty-publicKey refusal: `hexToBytes("")` is zero bytes, not an error — a body carrying an
181
- // empty key would be ordered and fined on-chain, so it is refused for free before anything is
182
- // signed (reference: admin.ts signKeyOp refuses `publicKey.length === 0`).
183
- if (publicKey.length === 0)
184
- return { kind: "partial", what: "publicKey", cause: "a key is needed" };
185
- try {
186
- popSignature = hexToBytes(String(p.popSignature ?? ""));
187
- }
188
- catch (e) {
189
- return { kind: "partial", what: "popSignature", cause: e instanceof Error ? e.message : String(e) };
190
- }
191
- // Empty-PoP refusal: this agent signs for NO key it does not hold.
192
- if (popSignature.length === 0)
193
- return {
194
- kind: "partial",
195
- what: "popSignature",
196
- cause: "the key's holder must prove possession — this agent cannot sign for a key it does not hold",
197
- };
198
- const tip = await tipOrUnreachable(deps);
199
- if (typeof tip !== "number")
200
- return tip;
201
- const expiresAtRound = tip + (deps.ttlOffset ?? DEFAULT_TTL_OFFSET);
202
- const args = { publicKey, keyType, keyLabel, popSignature };
203
- return composeIdentityTx(deps, {
204
- ledgerId: LEDGER.identity,
205
- body: verb === "add_key" ? addKeyBody(args) : replaceKeyBody(args),
206
- ttlRound: expiresAtRound,
207
- signedAtRound: tip,
208
- verb,
209
- fields: { keyType, keyLabel },
210
- });
211
- }
212
- export const signAddKey = (deps, p) => signKeyOp(deps, "add_key", p);
213
- export const signReplaceKey = (deps, p) => signKeyOp(deps, "replace_key", p);
214
- /**
215
- * Remove one of this identity's own keys. ⚠️ THE CHAIN WILL NOT STOP YOU LOCKING YOURSELF OUT — its
216
- * only guard refuses a committee member deleting its default consensus key.
217
- */
218
- export async function signDeleteKey(deps, p) {
219
- const keyType = String(p.keyType ?? "").trim();
220
- if (keyType.length === 0)
221
- return { kind: "partial", what: "keyType", cause: "which key?" };
222
- const keyLabel = String(p.keyLabel ?? "");
223
- const tip = await tipOrUnreachable(deps);
224
- if (typeof tip !== "number")
225
- return tip;
226
- const expiresAtRound = tip + (deps.ttlOffset ?? DEFAULT_TTL_OFFSET);
227
- return composeIdentityTx(deps, {
228
- ledgerId: LEDGER.identity,
229
- body: deleteKeyBody({ keyType, keyLabel }),
230
- ttlRound: expiresAtRound,
231
- signedAtRound: tip,
232
- verb: "delete_key",
233
- fields: { keyType, keyLabel },
234
- });
235
- }
236
- //# sourceMappingURL=identity.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"identity.js","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAAA,qGAAqG;AACrG,iGAAiG;AACjG,oGAAoG;AACpG,EAAE;AACF,kGAAkG;AAClG,qGAAqG;AACrG,qGAAqG;AACrG,gGAAgG;AAChG,EAAE;AACF,qGAAqG;AACrG,gGAAgG;AAChG,oGAAoG;AACpG,wBAAwB;AAExB,OAAO,EACL,MAAM,EACN,aAAa,EACb,OAAO,EACP,UAAU,EACV,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EAClB,UAAU,EACV,cAAc,EACd,aAAa,GACd,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAgB9D;;6EAE6E;AAC7E,MAAM,UAAU,kBAAkB,CAAC,KAAa;IAC9C,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACrC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC;QAC1B,OAAO;YACL,EAAE,EAAE,KAAK;YACT,KAAK,EACH,kBAAkB,CAAC,uEAAuE;g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QAAQ;QACzB,IAAI,EAAE,aAAa,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;QAC1C,QAAQ,EAAE,cAAc;QACxB,aAAa,EAAE,GAAG;QAClB,IAAI,EAAE,YAAY;QAClB,MAAM,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE;KAC9B,CAAC,CAAC;AACL,CAAC"}
@@ -1,14 +0,0 @@
1
- import type { ContentUploadTls } from "@mcsherrylabs/evolver-client";
2
- import type { TlsOptions } from "./config.js";
3
- export interface NodeTransport {
4
- readonly fetch: typeof fetch;
5
- readonly contentUploadTls: ContentUploadTls;
6
- close(): Promise<void>;
7
- }
8
- export declare function resolveNodeTransport(tls?: TlsOptions): Promise<{
9
- ok: true;
10
- } & NodeTransport | {
11
- ok: false;
12
- error: string;
13
- }>;
14
- //# sourceMappingURL=node-transport.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"node-transport.d.ts","sourceRoot":"","sources":["../src/node-transport.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,KAAK,EAAE,OAAO,KAAK,CAAC;IAC7B,QAAQ,CAAC,gBAAgB,EAAE,gBAAgB,CAAC;IAC5C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AACD,wBAAsB,oBAAoB,CAAC,GAAG,CAAC,EAAE,UAAU,GAAG,OAAO,CACnE;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,GAAG,aAAa,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAC5D,CAmCA"}
@@ -1,54 +0,0 @@
1
- // One operator NODE trust policy, applied equally to fetch and the SDK's native stream upload.
2
- // This is not the external relying-service transport: never reuse insecure node TLS there.
3
- import { constants } from "node:fs";
4
- import { open } from "node:fs/promises";
5
- import { X509Certificate } from "node:crypto";
6
- import { Agent } from "undici";
7
- export async function resolveNodeTransport(tls) {
8
- try {
9
- if (tls?.insecure !== undefined && typeof tls.insecure !== "boolean")
10
- throw new Error();
11
- let ca;
12
- if (tls?.caFile !== undefined) {
13
- if (typeof tls.caFile !== "string" || !tls.caFile)
14
- throw new Error();
15
- const file = await open(tls.caFile, constants.O_RDONLY | constants.O_NONBLOCK);
16
- try {
17
- const st = await file.stat();
18
- if (!st.isFile() || st.size < 1 || st.size > 1024 * 1024)
19
- throw new Error();
20
- const bytes = Buffer.alloc(st.size + 1);
21
- let count = 0;
22
- while (count < bytes.length) {
23
- const got = await file.read(bytes, count, bytes.length - count, null);
24
- if (!got.bytesRead)
25
- break;
26
- count += got.bytesRead;
27
- }
28
- if (count !== st.size)
29
- throw new Error();
30
- ca = new TextDecoder("utf8", { fatal: true }).decode(bytes.subarray(0, count));
31
- // Parse explicitly, without reflecting certificate contents in any error/log.
32
- new X509Certificate(ca);
33
- }
34
- finally {
35
- await file.close();
36
- }
37
- }
38
- const connect = Object.freeze({ rejectUnauthorized: tls?.insecure !== true,
39
- ...(ca === undefined ? {} : { ca }) });
40
- const contentUploadTls = connect;
41
- const dispatcher = new Agent({ connect });
42
- let closed = false;
43
- return { ok: true, contentUploadTls,
44
- fetch: (input, init) => globalThis.fetch(input, { ...init, dispatcher }),
45
- async close() { if (!closed) {
46
- closed = true;
47
- await dispatcher.destroy();
48
- } }, };
49
- }
50
- catch {
51
- return { ok: false, error: "Cannot honor node TLS configuration: use a readable bounded CA PEM file and explicit boolean insecure option. Refusing rather than ignoring trust policy; certificate contents are not returned." };
52
- }
53
- }
54
- //# sourceMappingURL=node-transport.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"node-transport.js","sourceRoot":"","sources":["../src/node-transport.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAC/F,2FAA2F;AAC3F,OAAO,EAAE,SAAS,EAAE,MAAM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