@qntx/wallet-engine 0.6.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/connect.d.mts +45 -0
- package/dist/connect.mjs +174 -0
- package/dist/connect.mjs.map +1 -0
- package/dist/errors-CW_XXGL9.d.mts +1296 -0
- package/dist/gateway-contract.d.mts +1 -13
- package/dist/gateway-contract.mjs +183 -1
- package/dist/gateway-contract.mjs.map +1 -0
- package/dist/idb.d.mts +0 -4
- package/dist/idb.mjs +3 -6
- package/dist/idb.mjs.map +1 -1
- package/dist/index.d.mts +32 -867
- package/dist/index.mjs +2297 -1821
- package/dist/index.mjs.map +1 -1
- package/dist/registry-CHiAn88k.mjs +98 -0
- package/dist/registry-CHiAn88k.mjs.map +1 -0
- package/dist/{registry-9oeWs_yZ.d.mts → registry-LcFSPrE1.d.mts} +1 -3
- package/dist/webln-CHjBMRcv.mjs +1247 -0
- package/dist/webln-CHjBMRcv.mjs.map +1 -0
- package/package.json +28 -17
- package/dist/contract-D5pguqiZ.mjs +0 -284
- package/dist/contract-D5pguqiZ.mjs.map +0 -1
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { a as networkById, i as SOLANA_NETWORKS, n as NETWORKS, r as NetworkInfo, t as BITCOIN_NETWORKS } from "./registry-
|
|
1
|
+
import { a as networkById, i as SOLANA_NETWORKS, n as NETWORKS, r as NetworkInfo, t as BITCOIN_NETWORKS } from "./registry-LcFSPrE1.mjs";
|
|
2
2
|
import * as z from "zod/mini";
|
|
3
|
-
//#region src/gateway/contract/primitives.d.ts
|
|
4
3
|
export declare const INSTALL_ID_HEADER = "x-install-id";
|
|
5
4
|
export declare const PROVIDERS_HEADER = "x-gateway-providers";
|
|
6
5
|
/** 128 random bits as lowercase hex — generated once per install, unrelated to wallet secrets. */
|
|
@@ -21,8 +20,6 @@ export declare const gatewayError: z.ZodMiniObject<{
|
|
|
21
20
|
}>;
|
|
22
21
|
}, z.core.$strip>;
|
|
23
22
|
export type GatewayErrorCode = (typeof GATEWAY_ERRORS)[number];
|
|
24
|
-
//#endregion
|
|
25
|
-
//#region src/gateway/contract/endpoint.d.ts
|
|
26
23
|
export type HttpMethod = "GET" | "POST" | "DELETE";
|
|
27
24
|
export type Endpoint<Req extends z.ZodMiniType, Res extends z.ZodMiniType> = {
|
|
28
25
|
readonly method: HttpMethod;
|
|
@@ -36,8 +33,6 @@ export declare function endpoint<Req extends z.ZodMiniType, Res extends z.ZodMin
|
|
|
36
33
|
export declare function parseWith<S extends z.ZodMiniType>(schema: S, value: unknown): z.output<S> | undefined;
|
|
37
34
|
/** Whether `value` satisfies `schema` — lets consumers validate without importing zod. */
|
|
38
35
|
export declare function accepts(schema: z.ZodMiniType, value: unknown): boolean;
|
|
39
|
-
//#endregion
|
|
40
|
-
//#region src/gateway/contract/health.d.ts
|
|
41
36
|
export declare const healthRequest: z.ZodMiniUndefined;
|
|
42
37
|
export declare const healthResponse: z.ZodMiniObject<{
|
|
43
38
|
status: z.ZodMiniLiteral<"ok">;
|
|
@@ -45,8 +40,6 @@ export declare const healthResponse: z.ZodMiniObject<{
|
|
|
45
40
|
export declare const health: Endpoint<z.ZodMiniUndefined, z.ZodMiniObject<{
|
|
46
41
|
status: z.ZodMiniLiteral<"ok">;
|
|
47
42
|
}, z.core.$strip>>;
|
|
48
|
-
//#endregion
|
|
49
|
-
//#region src/gateway/contract/rpc.d.ts
|
|
50
43
|
/** One JSON-RPC call plus nothing else: batches may carry at most this many entries. */
|
|
51
44
|
export declare const RPC_BATCH_MAX = 20;
|
|
52
45
|
/** Read-only EVM methods plus `eth_sendRawTransaction`. Anything not listed is rejected. */
|
|
@@ -267,8 +260,6 @@ export declare const rpc: Endpoint<z.ZodMiniUnion<readonly [z.ZodMiniObject<{
|
|
|
267
260
|
}, z.core.$strip>]>>]>>;
|
|
268
261
|
/** The JSON-RPC URL path for one network. */
|
|
269
262
|
export declare const rpcPath: (caip2: string) => string;
|
|
270
|
-
//#endregion
|
|
271
|
-
//#region src/gateway/contract/esplora.d.ts
|
|
272
263
|
type EsploraRoute = {
|
|
273
264
|
readonly method: "GET" | "POST";
|
|
274
265
|
readonly pattern: RegExp;
|
|
@@ -281,8 +272,6 @@ export declare const esploraGet: Endpoint<z.ZodMiniUndefined, z.ZodMiniUnknown>;
|
|
|
281
272
|
/** The Esplora base path for one network; allow-listed paths are appended to it. */
|
|
282
273
|
export declare const esploraBasePath: (caip2: string) => string;
|
|
283
274
|
export declare const esploraPost: Endpoint<z.ZodMiniString<string>, z.ZodMiniString<string>>;
|
|
284
|
-
//#endregion
|
|
285
|
-
//#region src/gateway/contract/served.d.ts
|
|
286
275
|
export declare const servedNetworksRequest: z.ZodMiniUndefined;
|
|
287
276
|
/** The networks the gateway actually serves, in its configured order. */
|
|
288
277
|
export declare const servedNetworksResponse: z.ZodMiniObject<{
|
|
@@ -292,6 +281,5 @@ export declare const servedNetworks: Endpoint<z.ZodMiniUndefined, z.ZodMiniObjec
|
|
|
292
281
|
networks: z.ZodMiniArray<z.ZodMiniString<string>>;
|
|
293
282
|
}, z.core.$strip>>;
|
|
294
283
|
export declare const networksPath: string;
|
|
295
|
-
//#endregion
|
|
296
284
|
export { BITCOIN_NETWORKS, NETWORKS, type NetworkInfo, SOLANA_NETWORKS, networkById };
|
|
297
285
|
//# sourceMappingURL=gateway-contract.d.mts.map
|
|
@@ -1 +1,183 @@
|
|
|
1
|
-
|
|
1
|
+
import { i as networkById, n as NETWORKS, r as SOLANA_NETWORKS, t as BITCOIN_NETWORKS } from "./registry-CHiAn88k.mjs";
|
|
2
|
+
import * as z from "zod/mini";
|
|
3
|
+
// src/gateway/contract/endpoint.ts
|
|
4
|
+
/** One gateway route: its verb, versioned path template, and request/response schemas. */
|
|
5
|
+
function endpoint(method, path, request, response) {
|
|
6
|
+
return {
|
|
7
|
+
method,
|
|
8
|
+
path,
|
|
9
|
+
request,
|
|
10
|
+
response
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/** `value` typed by `schema`, or `undefined` when it does not satisfy it. */
|
|
14
|
+
function parseWith(schema, value) {
|
|
15
|
+
const result = z.safeParse(schema, value);
|
|
16
|
+
return result.success ? result.data : void 0;
|
|
17
|
+
}
|
|
18
|
+
/** Whether `value` satisfies `schema` — lets consumers validate without importing zod. */
|
|
19
|
+
function accepts(schema, value) {
|
|
20
|
+
return z.safeParse(schema, value).success;
|
|
21
|
+
}
|
|
22
|
+
// src/gateway/contract/rpc.ts
|
|
23
|
+
/** One JSON-RPC call plus nothing else: batches may carry at most this many entries. */
|
|
24
|
+
const RPC_BATCH_MAX = 20;
|
|
25
|
+
/** Read-only EVM methods plus `eth_sendRawTransaction`. Anything not listed is rejected. */
|
|
26
|
+
const EVM_RPC_METHODS = [
|
|
27
|
+
"eth_blobBaseFee",
|
|
28
|
+
"eth_blockNumber",
|
|
29
|
+
"eth_call",
|
|
30
|
+
"eth_chainId",
|
|
31
|
+
"eth_createAccessList",
|
|
32
|
+
"eth_estimateGas",
|
|
33
|
+
"eth_feeHistory",
|
|
34
|
+
"eth_gasPrice",
|
|
35
|
+
"eth_getBalance",
|
|
36
|
+
"eth_getBlockByHash",
|
|
37
|
+
"eth_getBlockByNumber",
|
|
38
|
+
"eth_getBlockReceipts",
|
|
39
|
+
"eth_getBlockTransactionCountByHash",
|
|
40
|
+
"eth_getBlockTransactionCountByNumber",
|
|
41
|
+
"eth_getCode",
|
|
42
|
+
"eth_getProof",
|
|
43
|
+
"eth_getStorageAt",
|
|
44
|
+
"eth_getTransactionByBlockHashAndIndex",
|
|
45
|
+
"eth_getTransactionByBlockNumberAndIndex",
|
|
46
|
+
"eth_getTransactionByHash",
|
|
47
|
+
"eth_getTransactionCount",
|
|
48
|
+
"eth_getTransactionReceipt",
|
|
49
|
+
"eth_maxPriorityFeePerGas",
|
|
50
|
+
"eth_sendRawTransaction",
|
|
51
|
+
"net_version",
|
|
52
|
+
"web3_clientVersion"
|
|
53
|
+
];
|
|
54
|
+
/** Read-only Solana methods plus `sendTransaction`. Anything not listed is rejected. */
|
|
55
|
+
const SOLANA_RPC_METHODS = [
|
|
56
|
+
"getAccountInfo",
|
|
57
|
+
"getBalance",
|
|
58
|
+
"getBlock",
|
|
59
|
+
"getBlockHeight",
|
|
60
|
+
"getBlockTime",
|
|
61
|
+
"getEpochInfo",
|
|
62
|
+
"getFeeForMessage",
|
|
63
|
+
"getGenesisHash",
|
|
64
|
+
"getLatestBlockhash",
|
|
65
|
+
"getMinimumBalanceForRentExemption",
|
|
66
|
+
"getMultipleAccounts",
|
|
67
|
+
"getRecentPrioritizationFees",
|
|
68
|
+
"getSignatureStatuses",
|
|
69
|
+
"getSignaturesForAddress",
|
|
70
|
+
"getSlot",
|
|
71
|
+
"getTokenAccountBalance",
|
|
72
|
+
"getTokenAccountsByOwner",
|
|
73
|
+
"getTokenSupply",
|
|
74
|
+
"getTransaction",
|
|
75
|
+
"getVersion",
|
|
76
|
+
"isBlockhashValid",
|
|
77
|
+
"sendTransaction",
|
|
78
|
+
"simulateTransaction"
|
|
79
|
+
];
|
|
80
|
+
const jsonRpcId = z.union([
|
|
81
|
+
z.string(),
|
|
82
|
+
z.number(),
|
|
83
|
+
z.null()
|
|
84
|
+
]);
|
|
85
|
+
const jsonRpcParams = z.optional(z.union([z.array(z.unknown()), z.record(z.string(), z.unknown())]));
|
|
86
|
+
const callSchema = (method) => z.object({
|
|
87
|
+
jsonrpc: z.literal("2.0"),
|
|
88
|
+
id: jsonRpcId,
|
|
89
|
+
method,
|
|
90
|
+
params: jsonRpcParams
|
|
91
|
+
});
|
|
92
|
+
const bodySchema = (call) => z.union([call, z.array(call).check(z.minLength(1), z.maxLength(20))]);
|
|
93
|
+
/** Method-agnostic wire shape of a call or batch (the gateway narrows by family). */
|
|
94
|
+
const rpcRequest = bodySchema(callSchema(z.string()));
|
|
95
|
+
const evmRpcRequest = bodySchema(callSchema(z.enum(EVM_RPC_METHODS)));
|
|
96
|
+
const solanaRpcRequest = bodySchema(callSchema(z.enum(SOLANA_RPC_METHODS)));
|
|
97
|
+
const successResponse = z.object({
|
|
98
|
+
jsonrpc: z.literal("2.0"),
|
|
99
|
+
id: jsonRpcId,
|
|
100
|
+
result: z.unknown()
|
|
101
|
+
});
|
|
102
|
+
const errorResponse = z.object({
|
|
103
|
+
jsonrpc: z.literal("2.0"),
|
|
104
|
+
id: jsonRpcId,
|
|
105
|
+
error: z.object({
|
|
106
|
+
code: z.int(),
|
|
107
|
+
message: z.string(),
|
|
108
|
+
data: z.optional(z.unknown())
|
|
109
|
+
})
|
|
110
|
+
});
|
|
111
|
+
const jsonRpcResponse = z.union([successResponse, errorResponse]);
|
|
112
|
+
const rpcResponse = z.union([jsonRpcResponse, z.array(jsonRpcResponse)]);
|
|
113
|
+
const rpc = endpoint("POST", "/v1/rpc/:caip2", rpcRequest, rpcResponse);
|
|
114
|
+
/** The JSON-RPC URL path for one network. */
|
|
115
|
+
const rpcPath = (caip2) => rpc.path.replace(":caip2", caip2);
|
|
116
|
+
// src/gateway/contract/primitives.ts
|
|
117
|
+
const INSTALL_ID_HEADER = "x-install-id";
|
|
118
|
+
const PROVIDERS_HEADER = "x-gateway-providers";
|
|
119
|
+
/** 128 random bits as lowercase hex — generated once per install, unrelated to wallet secrets. */
|
|
120
|
+
const installId = z.string().check(z.regex(/^[0-9a-f]{32}$/));
|
|
121
|
+
/** CAIP-2 chain id: `namespace:reference`. */
|
|
122
|
+
const caip2 = z.string().check(z.regex(/^[-a-z0-9]{3,8}:[-_a-zA-Z0-9]{1,32}$/));
|
|
123
|
+
const GATEWAY_ERRORS = [
|
|
124
|
+
"invalid-request",
|
|
125
|
+
"unknown-network",
|
|
126
|
+
"not-found",
|
|
127
|
+
"rate-limited",
|
|
128
|
+
"unavailable",
|
|
129
|
+
"internal"
|
|
130
|
+
];
|
|
131
|
+
const gatewayError = z.object({ error: z.enum(GATEWAY_ERRORS) });
|
|
132
|
+
// src/gateway/contract/health.ts
|
|
133
|
+
const healthRequest = z.undefined();
|
|
134
|
+
const healthResponse = z.object({ status: z.literal("ok") });
|
|
135
|
+
const health = endpoint("GET", "/v1/health", healthRequest, healthResponse);
|
|
136
|
+
// src/gateway/contract/esplora.ts
|
|
137
|
+
const HEX64 = "[0-9a-f]{64}";
|
|
138
|
+
/** The Esplora surface the engine uses; every other path is rejected. */
|
|
139
|
+
const ESPLORA_ROUTES = [
|
|
140
|
+
{
|
|
141
|
+
method: "GET",
|
|
142
|
+
pattern: /^\/block-height\/\d{1,10}$/
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
method: "GET",
|
|
146
|
+
pattern: /^\/fee-estimates$/
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
method: "GET",
|
|
150
|
+
pattern: new RegExp(`^/scripthash/${HEX64}/txs$`)
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
method: "GET",
|
|
154
|
+
pattern: new RegExp(`^/scripthash/${HEX64}/utxo$`)
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
method: "GET",
|
|
158
|
+
pattern: new RegExp(`^/tx/${HEX64}/hex$`)
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
method: "GET",
|
|
162
|
+
pattern: new RegExp(`^/tx/${HEX64}/status$`)
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
method: "POST",
|
|
166
|
+
pattern: /^\/tx$/
|
|
167
|
+
}
|
|
168
|
+
];
|
|
169
|
+
/** `path` is the Esplora path after `/v1/esplora/:caip2`, with a leading slash and no query. */
|
|
170
|
+
const esploraPathAllowed = (method, path) => ESPLORA_ROUTES.some((route) => route.method === method && route.pattern.test(path));
|
|
171
|
+
const esploraGet = endpoint("GET", "/v1/esplora/:caip2/*", z.undefined(), z.unknown());
|
|
172
|
+
/** The Esplora base path for one network; allow-listed paths are appended to it. */
|
|
173
|
+
const esploraBasePath = (caip2) => esploraGet.path.replace(":caip2", caip2).replace(/\/\*$/, "");
|
|
174
|
+
const esploraPost = endpoint("POST", "/v1/esplora/:caip2/tx", z.string(), z.string());
|
|
175
|
+
// src/gateway/contract/served.ts
|
|
176
|
+
const servedNetworksRequest = z.undefined();
|
|
177
|
+
/** The networks the gateway actually serves, in its configured order. */
|
|
178
|
+
const servedNetworksResponse = z.object({ networks: z.array(caip2) });
|
|
179
|
+
const servedNetworks = endpoint("GET", "/v1/networks", servedNetworksRequest, servedNetworksResponse);
|
|
180
|
+
const networksPath = servedNetworks.path;
|
|
181
|
+
export { BITCOIN_NETWORKS, ESPLORA_ROUTES, EVM_RPC_METHODS, GATEWAY_ERRORS, INSTALL_ID_HEADER, NETWORKS, PROVIDERS_HEADER, RPC_BATCH_MAX, SOLANA_NETWORKS, SOLANA_RPC_METHODS, accepts, caip2, endpoint, esploraBasePath, esploraGet, esploraPathAllowed, esploraPost, evmRpcRequest, gatewayError, health, healthRequest, healthResponse, installId, jsonRpcId, jsonRpcResponse, networkById, networksPath, parseWith, rpc, rpcPath, rpcRequest, rpcResponse, servedNetworks, servedNetworksRequest, servedNetworksResponse, solanaRpcRequest };
|
|
182
|
+
|
|
183
|
+
//# sourceMappingURL=gateway-contract.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway-contract.mjs","names":[],"sources":["../src/gateway/contract/endpoint.ts","../src/gateway/contract/rpc.ts","../src/gateway/contract/primitives.ts","../src/gateway/contract/health.ts","../src/gateway/contract/esplora.ts","../src/gateway/contract/served.ts"],"sourcesContent":["import * as z from \"zod/mini\";\n\nexport type HttpMethod = \"GET\" | \"POST\" | \"DELETE\";\n\nexport type Endpoint<Req extends z.ZodMiniType, Res extends z.ZodMiniType> = {\n readonly method: HttpMethod;\n readonly path: string;\n readonly request: Req;\n readonly response: Res;\n};\n\n/** One gateway route: its verb, versioned path template, and request/response schemas. */\nexport function endpoint<Req extends z.ZodMiniType, Res extends z.ZodMiniType>(\n method: HttpMethod,\n path: `/v1/${string}`,\n request: Req,\n response: Res,\n): Endpoint<Req, Res> {\n return { method, path, request, response };\n}\n\n/** `value` typed by `schema`, or `undefined` when it does not satisfy it. */\nexport function parseWith<S extends z.ZodMiniType>(\n schema: S,\n value: unknown,\n): z.output<S> | undefined {\n const result = z.safeParse(schema, value);\n return result.success ? result.data : undefined;\n}\n\n/** Whether `value` satisfies `schema` — lets consumers validate without importing zod. */\nexport function accepts(schema: z.ZodMiniType, value: unknown): boolean {\n return z.safeParse(schema, value).success;\n}\n","import * as z from \"zod/mini\";\n\nimport { endpoint } from \"./endpoint.ts\";\n\n/** One JSON-RPC call plus nothing else: batches may carry at most this many entries. */\nexport const RPC_BATCH_MAX = 20;\n\n/** Read-only EVM methods plus `eth_sendRawTransaction`. Anything not listed is rejected. */\nexport const EVM_RPC_METHODS = [\n \"eth_blobBaseFee\",\n \"eth_blockNumber\",\n \"eth_call\",\n \"eth_chainId\",\n \"eth_createAccessList\",\n \"eth_estimateGas\",\n \"eth_feeHistory\",\n \"eth_gasPrice\",\n \"eth_getBalance\",\n \"eth_getBlockByHash\",\n \"eth_getBlockByNumber\",\n \"eth_getBlockReceipts\",\n \"eth_getBlockTransactionCountByHash\",\n \"eth_getBlockTransactionCountByNumber\",\n \"eth_getCode\",\n \"eth_getProof\",\n \"eth_getStorageAt\",\n \"eth_getTransactionByBlockHashAndIndex\",\n \"eth_getTransactionByBlockNumberAndIndex\",\n \"eth_getTransactionByHash\",\n \"eth_getTransactionCount\",\n \"eth_getTransactionReceipt\",\n \"eth_maxPriorityFeePerGas\",\n \"eth_sendRawTransaction\",\n \"net_version\",\n \"web3_clientVersion\",\n] as const;\n\n/** Read-only Solana methods plus `sendTransaction`. Anything not listed is rejected. */\nexport const SOLANA_RPC_METHODS = [\n \"getAccountInfo\",\n \"getBalance\",\n \"getBlock\",\n \"getBlockHeight\",\n \"getBlockTime\",\n \"getEpochInfo\",\n \"getFeeForMessage\",\n \"getGenesisHash\",\n \"getLatestBlockhash\",\n \"getMinimumBalanceForRentExemption\",\n \"getMultipleAccounts\",\n \"getRecentPrioritizationFees\",\n \"getSignatureStatuses\",\n \"getSignaturesForAddress\",\n \"getSlot\",\n \"getTokenAccountBalance\",\n \"getTokenAccountsByOwner\",\n \"getTokenSupply\",\n \"getTransaction\",\n \"getVersion\",\n \"isBlockhashValid\",\n \"sendTransaction\",\n \"simulateTransaction\",\n] as const;\n\nexport type EvmRpcMethod = (typeof EVM_RPC_METHODS)[number];\nexport type SolanaRpcMethod = (typeof SOLANA_RPC_METHODS)[number];\n\nexport const jsonRpcId = z.union([z.string(), z.number(), z.null()]);\n\nconst jsonRpcParams = z.optional(\n z.union([z.array(z.unknown()), z.record(z.string(), z.unknown())]),\n);\n\nconst callSchema = <M extends z.ZodMiniType<string>>(method: M) =>\n z.object({ jsonrpc: z.literal(\"2.0\"), id: jsonRpcId, method, params: jsonRpcParams });\n\nconst bodySchema = <C extends z.ZodMiniType>(call: C) =>\n z.union([call, z.array(call).check(z.minLength(1), z.maxLength(RPC_BATCH_MAX))]);\n\n/** Method-agnostic wire shape of a call or batch (the gateway narrows by family). */\nexport const rpcRequest = bodySchema(callSchema(z.string()));\n\nexport const evmRpcRequest = bodySchema(callSchema(z.enum(EVM_RPC_METHODS)));\nexport const solanaRpcRequest = bodySchema(callSchema(z.enum(SOLANA_RPC_METHODS)));\n\nconst successResponse = z.object({\n jsonrpc: z.literal(\"2.0\"),\n id: jsonRpcId,\n result: z.unknown(),\n});\nconst errorResponse = z.object({\n jsonrpc: z.literal(\"2.0\"),\n id: jsonRpcId,\n error: z.object({ code: z.int(), message: z.string(), data: z.optional(z.unknown()) }),\n});\n\nexport const jsonRpcResponse = z.union([successResponse, errorResponse]);\nexport const rpcResponse = z.union([jsonRpcResponse, z.array(jsonRpcResponse)]);\n\nexport const rpc = endpoint(\"POST\", \"/v1/rpc/:caip2\", rpcRequest, rpcResponse);\n\n/** The JSON-RPC URL path for one network. */\nexport const rpcPath = (caip2: string): string => rpc.path.replace(\":caip2\", caip2);\n","import * as z from \"zod/mini\";\n\nexport const INSTALL_ID_HEADER = \"x-install-id\";\nexport const PROVIDERS_HEADER = \"x-gateway-providers\";\n\n/** 128 random bits as lowercase hex — generated once per install, unrelated to wallet secrets. */\nexport const installId = z.string().check(z.regex(/^[0-9a-f]{32}$/));\n\n/** CAIP-2 chain id: `namespace:reference`. */\nexport const caip2 = z.string().check(z.regex(/^[-a-z0-9]{3,8}:[-_a-zA-Z0-9]{1,32}$/));\n\nexport type Caip2 = z.infer<typeof caip2>;\nexport type InstallId = z.infer<typeof installId>;\n\nexport const GATEWAY_ERRORS = [\n \"invalid-request\",\n \"unknown-network\",\n \"not-found\",\n \"rate-limited\",\n \"unavailable\",\n \"internal\",\n] as const;\n\nexport const gatewayError = z.object({ error: z.enum(GATEWAY_ERRORS) });\n\nexport type GatewayErrorCode = (typeof GATEWAY_ERRORS)[number];\n","import * as z from \"zod/mini\";\n\nimport { endpoint } from \"./endpoint.ts\";\n\nexport const healthRequest = z.undefined();\nexport const healthResponse = z.object({ status: z.literal(\"ok\") });\n\nexport const health = endpoint(\"GET\", \"/v1/health\", healthRequest, healthResponse);\n","import * as z from \"zod/mini\";\n\nimport { endpoint } from \"./endpoint.ts\";\n\nconst HEX64 = \"[0-9a-f]{64}\";\n\ntype EsploraRoute = { readonly method: \"GET\" | \"POST\"; readonly pattern: RegExp };\n\n/** The Esplora surface the engine uses; every other path is rejected. */\nexport const ESPLORA_ROUTES: ReadonlyArray<EsploraRoute> = [\n { method: \"GET\", pattern: /^\\/block-height\\/\\d{1,10}$/ },\n { method: \"GET\", pattern: /^\\/fee-estimates$/ },\n { method: \"GET\", pattern: new RegExp(`^/scripthash/${HEX64}/txs$`) },\n { method: \"GET\", pattern: new RegExp(`^/scripthash/${HEX64}/utxo$`) },\n { method: \"GET\", pattern: new RegExp(`^/tx/${HEX64}/hex$`) },\n { method: \"GET\", pattern: new RegExp(`^/tx/${HEX64}/status$`) },\n { method: \"POST\", pattern: /^\\/tx$/ },\n];\n\n/** `path` is the Esplora path after `/v1/esplora/:caip2`, with a leading slash and no query. */\nexport const esploraPathAllowed = (method: string, path: string): boolean =>\n ESPLORA_ROUTES.some((route) => route.method === method && route.pattern.test(path));\n\nexport const esploraGet = endpoint(\"GET\", \"/v1/esplora/:caip2/*\", z.undefined(), z.unknown());\n\n/** The Esplora base path for one network; allow-listed paths are appended to it. */\nexport const esploraBasePath = (caip2: string): string =>\n esploraGet.path.replace(\":caip2\", caip2).replace(/\\/\\*$/, \"\");\nexport const esploraPost = endpoint(\"POST\", \"/v1/esplora/:caip2/tx\", z.string(), z.string());\n","import * as z from \"zod/mini\";\n\nimport { endpoint } from \"./endpoint.ts\";\nimport { caip2 } from \"./primitives.ts\";\n\nexport const servedNetworksRequest = z.undefined();\n/** The networks the gateway actually serves, in its configured order. */\nexport const servedNetworksResponse = z.object({ networks: z.array(caip2) });\n\nexport const servedNetworks = endpoint(\n \"GET\",\n \"/v1/networks\",\n servedNetworksRequest,\n servedNetworksResponse,\n);\n\nexport const networksPath: string = servedNetworks.path;\n"],"mappings":";;;;AAYA,SAAgB,SACd,QACA,MACA,SACA,UACoB;CACpB,OAAO;EAAE;EAAQ;EAAM;EAAS;CAAS;AAC3C;;AAGA,SAAgB,UACd,QACA,OACyB;CACzB,MAAM,SAAS,EAAE,UAAU,QAAQ,KAAK;CACxC,OAAO,OAAO,UAAU,OAAO,OAAO,KAAA;AACxC;;AAGA,SAAgB,QAAQ,QAAuB,OAAyB;CACtE,OAAO,EAAE,UAAU,QAAQ,KAAK,CAAC,CAAC;AACpC;;;AC5BA,MAAa,gBAAgB;;AAG7B,MAAa,kBAAkB;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AAGA,MAAa,qBAAqB;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA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KAAK,CAAC,CAAC,QAAQ,SAAS,EAAE;AAC9D,MAAa,cAAc,SAAS,QAAQ,yBAAyB,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC;;ACvB3F,MAAa,wBAAwB,EAAE,UAAU;;AAEjD,MAAa,yBAAyB,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,KAAK,EAAE,CAAC;AAE3E,MAAa,iBAAiB,SAC5B,OACA,gBACA,uBACA,sBACF;AAEA,MAAa,eAAuB,eAAe"}
|
package/dist/idb.d.mts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/store/port.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Engine storage port: named collections of byte values. `collection` is synchronous and cheap —
|
|
4
3
|
* the same collection object backs every call, so guards (closed) live on the store.
|
|
@@ -14,8 +13,6 @@ type EngineStore = {
|
|
|
14
13
|
readonly collection: (name: string) => EngineCollection;
|
|
15
14
|
readonly close: () => Promise<void>;
|
|
16
15
|
};
|
|
17
|
-
//#endregion
|
|
18
|
-
//#region src/idb/indexeddb.d.ts
|
|
19
16
|
export type Random = (length: number) => Uint8Array;
|
|
20
17
|
export type IndexedDbEngineStoreOptions = {
|
|
21
18
|
readonly name: string;
|
|
@@ -23,6 +20,5 @@ export type IndexedDbEngineStoreOptions = {
|
|
|
23
20
|
readonly random: Random;
|
|
24
21
|
};
|
|
25
22
|
export declare function openIndexedDbEngineStore(options: IndexedDbEngineStoreOptions): Promise<EngineStore>;
|
|
26
|
-
//#endregion
|
|
27
23
|
export {};
|
|
28
24
|
//# sourceMappingURL=idb.d.mts.map
|
package/dist/idb.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { xchacha20poly1305 } from "@noble/ciphers/chacha.js";
|
|
2
|
-
|
|
2
|
+
// src/errors.ts
|
|
3
3
|
/** Typed engine errors: store codes are `closed` and `integrity` (decrypt or bind failure). */
|
|
4
4
|
var EngineStoreError = class extends Error {
|
|
5
5
|
code;
|
|
@@ -9,14 +9,12 @@ var EngineStoreError = class extends Error {
|
|
|
9
9
|
this.code = code;
|
|
10
10
|
}
|
|
11
11
|
};
|
|
12
|
-
|
|
13
|
-
//#region src/store/guard.ts
|
|
12
|
+
// src/store/guard.ts
|
|
14
13
|
/** NUL is the composite-key/AAD separator — a name or key containing it collides. */
|
|
15
14
|
function checkName(kind, value) {
|
|
16
15
|
if (value.includes("\0")) throw new EngineStoreError("invalid-input", `${kind} must not contain NUL`);
|
|
17
16
|
}
|
|
18
|
-
|
|
19
|
-
//#region src/idb/indexeddb.ts
|
|
17
|
+
// src/idb/indexeddb.ts
|
|
20
18
|
/**
|
|
21
19
|
* The Web EngineStore: one IndexedDB database, one `records` object store, values encrypted per
|
|
22
20
|
* record with XChaCha20-Poly1305. Key = the injected 32-byte data key; nonce = 24 random bytes
|
|
@@ -128,7 +126,6 @@ function makeStore(db, key, random) {
|
|
|
128
126
|
}
|
|
129
127
|
};
|
|
130
128
|
}
|
|
131
|
-
//#endregion
|
|
132
129
|
export { openIndexedDbEngineStore };
|
|
133
130
|
|
|
134
131
|
//# sourceMappingURL=idb.mjs.map
|
package/dist/idb.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"idb.mjs","names":[],"sources":["../src/errors.ts","../src/store/guard.ts","../src/idb/indexeddb.ts"],"sourcesContent":["export type EngineErrorCode = \"closed\" | \"integrity\" | \"invalid-input\";\n\n/** Typed engine errors: store codes are `closed` and `integrity` (decrypt or bind failure). */\nexport class EngineStoreError extends Error {\n readonly code: EngineErrorCode;\n\n constructor(code: EngineErrorCode, message: string) {\n super(message);\n this.name = \"EngineStoreError\";\n this.code = code;\n }\n}\n","import { EngineStoreError } from \"../errors.ts\";\n\n/** NUL is the composite-key/AAD separator — a name or key containing it collides. */\nexport function checkName(kind: \"collection\" | \"key\", value: string): void {\n if (value.includes(\"\\u0000\")) {\n throw new EngineStoreError(\"invalid-input\", `${kind} must not contain NUL`);\n }\n}\n","/**\n * The Web EngineStore: one IndexedDB database, one `records` object store, values encrypted per\n * record with XChaCha20-Poly1305. Key = the injected 32-byte data key; nonce = 24 random bytes\n * stored as nonce‖ciphertext; AAD = UTF-8 `<collection>\\0<key>` — moving a record to another key or\n * collection fails the MAC, same as a tampered payload. `close()` drops the connection, wipes the\n * module-held key copy and latches every call to `closed`.\n */\nimport { xchacha20poly1305 } from \"@noble/ciphers/chacha.js\";\n\nimport { EngineStoreError } from \"../errors.ts\";\nimport { checkName } from \"../store/guard.ts\";\nimport type { EngineCollection, EngineStore } from \"../store/port.ts\";\n\nexport type Random = (length: number) => Uint8Array;\n\nexport type IndexedDbEngineStoreOptions = {\n readonly name: string;\n readonly dataKey: Uint8Array;\n readonly random: Random;\n};\n\nconst STORE = \"records\";\n\nconst id = (collection: string, recordKey: string): string => `${collection}\\u0000${recordKey}`;\nconst aad = (collection: string, recordKey: string): Uint8Array =>\n new TextEncoder().encode(`${collection}\\u0000${recordKey}`);\n\nasync function request<T>(req: IDBRequest<T>): Promise<T> {\n return new Promise((resolve, reject) => {\n req.addEventListener(\"success\", () => {\n resolve(req.result);\n });\n req.addEventListener(\"error\", () => {\n reject(new Error(\"indexeddb request failed\", { cause: req.error }));\n });\n });\n}\n\nasync function done(tx: IDBTransaction): Promise<void> {\n return new Promise((resolve, reject) => {\n tx.addEventListener(\"complete\", () => {\n resolve();\n });\n tx.addEventListener(\"error\", () => {\n reject(new Error(\"indexeddb transaction failed\", { cause: tx.error }));\n });\n tx.addEventListener(\"abort\", () => {\n reject(new Error(\"indexeddb transaction aborted\", { cause: tx.error }));\n });\n });\n}\n\nexport async function openIndexedDbEngineStore(\n options: IndexedDbEngineStoreOptions,\n): Promise<EngineStore> {\n const key = new Uint8Array(options.dataKey);\n return new Promise<EngineStore>((resolve, reject) => {\n const open = indexedDB.open(options.name, 1);\n open.addEventListener(\"upgradeneeded\", () => {\n open.result.createObjectStore(STORE);\n });\n open.addEventListener(\"success\", () => {\n resolve(makeStore(open.result, key, options.random));\n });\n open.addEventListener(\"error\", () => {\n key.fill(0);\n reject(new Error(\"indexeddb open failed\", { cause: open.error }));\n });\n });\n}\n\nfunction makeStore(db: IDBDatabase, key: Uint8Array, random: Random): EngineStore {\n let closed = false;\n\n const guard = (): IDBDatabase => {\n if (closed) {\n throw new EngineStoreError(\"closed\", \"engine store is closed\");\n }\n return db;\n };\n\n const seal = (collection: string, recordKey: string, bytes: Uint8Array): Uint8Array => {\n const nonce = random(24);\n const ciphertext = xchacha20poly1305(key, nonce, aad(collection, recordKey)).encrypt(bytes);\n const record = new Uint8Array(24 + ciphertext.length);\n record.set(nonce, 0);\n record.set(ciphertext, 24);\n return record;\n };\n\n const open = (collection: string, recordKey: string, record: Uint8Array): Uint8Array => {\n if (record.length < 24) {\n throw new EngineStoreError(\"integrity\", \"engine record too short\");\n }\n try {\n return xchacha20poly1305(key, record.slice(0, 24), aad(collection, recordKey)).decrypt(\n record.slice(24),\n );\n } catch {\n throw new EngineStoreError(\"integrity\", \"engine record failed integrity\");\n }\n };\n\n const make = (name: string): EngineCollection => ({\n get: async (recordKey) => {\n const database = guard();\n checkName(\"key\", recordKey);\n const tx = database.transaction(STORE, \"readonly\");\n const raw = tx.objectStore(STORE).get(id(name, recordKey));\n // oxlint-disable-next-line typescript/no-unsafe-argument -- IDB get() is any-typed by spec\n const record = await request<Uint8Array | undefined>(raw);\n return record === undefined ? undefined : open(name, recordKey, record);\n },\n put: async (recordKey, bytes) => {\n const database = guard();\n checkName(\"key\", recordKey);\n const tx = database.transaction(STORE, \"readwrite\");\n tx.objectStore(STORE).put(seal(name, recordKey, bytes), id(name, recordKey));\n await done(tx);\n },\n delete: async (recordKey) => {\n const database = guard();\n checkName(\"key\", recordKey);\n const tx = database.transaction(STORE, \"readwrite\");\n tx.objectStore(STORE).delete(id(name, recordKey));\n await done(tx);\n },\n list: async () => {\n const database = guard();\n const tx = database.transaction(STORE, \"readonly\");\n const all = tx.objectStore(STORE).getAllKeys();\n const keys = await request<IDBValidKey[]>(all);\n const prefix = `${name}\\u0000`;\n return keys\n .filter((k): k is string => typeof k === \"string\" && k.startsWith(prefix))\n .map((k) => k.slice(prefix.length));\n },\n });\n\n return {\n collection: (name) => {\n checkName(\"collection\", name);\n return make(name);\n },\n close: async () => {\n closed = true;\n db.close();\n key.fill(0);\n await Promise.resolve();\n },\n };\n}\n"],"mappings":";;;AAGA,IAAa,mBAAb,cAAsC,MAAM;CAC1C;CAEA,YAAY,MAAuB,SAAiB;EAClD,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,OAAO;CACd;AACF
|
|
1
|
+
{"version":3,"file":"idb.mjs","names":[],"sources":["../src/errors.ts","../src/store/guard.ts","../src/idb/indexeddb.ts"],"sourcesContent":["export type EngineErrorCode = \"closed\" | \"integrity\" | \"invalid-input\";\n\n/** Typed engine errors: store codes are `closed` and `integrity` (decrypt or bind failure). */\nexport class EngineStoreError extends Error {\n readonly code: EngineErrorCode;\n\n constructor(code: EngineErrorCode, message: string) {\n super(message);\n this.name = \"EngineStoreError\";\n this.code = code;\n }\n}\n","import { EngineStoreError } from \"../errors.ts\";\n\n/** NUL is the composite-key/AAD separator — a name or key containing it collides. */\nexport function checkName(kind: \"collection\" | \"key\", value: string): void {\n if (value.includes(\"\\u0000\")) {\n throw new EngineStoreError(\"invalid-input\", `${kind} must not contain NUL`);\n }\n}\n","/**\n * The Web EngineStore: one IndexedDB database, one `records` object store, values encrypted per\n * record with XChaCha20-Poly1305. Key = the injected 32-byte data key; nonce = 24 random bytes\n * stored as nonce‖ciphertext; AAD = UTF-8 `<collection>\\0<key>` — moving a record to another key or\n * collection fails the MAC, same as a tampered payload. `close()` drops the connection, wipes the\n * module-held key copy and latches every call to `closed`.\n */\nimport { xchacha20poly1305 } from \"@noble/ciphers/chacha.js\";\n\nimport { EngineStoreError } from \"../errors.ts\";\nimport { checkName } from \"../store/guard.ts\";\nimport type { EngineCollection, EngineStore } from \"../store/port.ts\";\n\nexport type Random = (length: number) => Uint8Array;\n\nexport type IndexedDbEngineStoreOptions = {\n readonly name: string;\n readonly dataKey: Uint8Array;\n readonly random: Random;\n};\n\nconst STORE = \"records\";\n\nconst id = (collection: string, recordKey: string): string => `${collection}\\u0000${recordKey}`;\nconst aad = (collection: string, recordKey: string): Uint8Array =>\n new TextEncoder().encode(`${collection}\\u0000${recordKey}`);\n\nasync function request<T>(req: IDBRequest<T>): Promise<T> {\n return new Promise((resolve, reject) => {\n req.addEventListener(\"success\", () => {\n resolve(req.result);\n });\n req.addEventListener(\"error\", () => {\n reject(new Error(\"indexeddb request failed\", { cause: req.error }));\n });\n });\n}\n\nasync function done(tx: IDBTransaction): Promise<void> {\n return new Promise((resolve, reject) => {\n tx.addEventListener(\"complete\", () => {\n resolve();\n });\n tx.addEventListener(\"error\", () => {\n reject(new Error(\"indexeddb transaction failed\", { cause: tx.error }));\n });\n tx.addEventListener(\"abort\", () => {\n reject(new Error(\"indexeddb transaction aborted\", { cause: tx.error }));\n });\n });\n}\n\nexport async function openIndexedDbEngineStore(\n options: IndexedDbEngineStoreOptions,\n): Promise<EngineStore> {\n const key = new Uint8Array(options.dataKey);\n return new Promise<EngineStore>((resolve, reject) => {\n const open = indexedDB.open(options.name, 1);\n open.addEventListener(\"upgradeneeded\", () => {\n open.result.createObjectStore(STORE);\n });\n open.addEventListener(\"success\", () => {\n resolve(makeStore(open.result, key, options.random));\n });\n open.addEventListener(\"error\", () => {\n key.fill(0);\n reject(new Error(\"indexeddb open failed\", { cause: open.error }));\n });\n });\n}\n\nfunction makeStore(db: IDBDatabase, key: Uint8Array, random: Random): EngineStore {\n let closed = false;\n\n const guard = (): IDBDatabase => {\n if (closed) {\n throw new EngineStoreError(\"closed\", \"engine store is closed\");\n }\n return db;\n };\n\n const seal = (collection: string, recordKey: string, bytes: Uint8Array): Uint8Array => {\n const nonce = random(24);\n const ciphertext = xchacha20poly1305(key, nonce, aad(collection, recordKey)).encrypt(bytes);\n const record = new Uint8Array(24 + ciphertext.length);\n record.set(nonce, 0);\n record.set(ciphertext, 24);\n return record;\n };\n\n const open = (collection: string, recordKey: string, record: Uint8Array): Uint8Array => {\n if (record.length < 24) {\n throw new EngineStoreError(\"integrity\", \"engine record too short\");\n }\n try {\n return xchacha20poly1305(key, record.slice(0, 24), aad(collection, recordKey)).decrypt(\n record.slice(24),\n );\n } catch {\n throw new EngineStoreError(\"integrity\", \"engine record failed integrity\");\n }\n };\n\n const make = (name: string): EngineCollection => ({\n get: async (recordKey) => {\n const database = guard();\n checkName(\"key\", recordKey);\n const tx = database.transaction(STORE, \"readonly\");\n const raw = tx.objectStore(STORE).get(id(name, recordKey));\n // oxlint-disable-next-line typescript/no-unsafe-argument -- IDB get() is any-typed by spec\n const record = await request<Uint8Array | undefined>(raw);\n return record === undefined ? undefined : open(name, recordKey, record);\n },\n put: async (recordKey, bytes) => {\n const database = guard();\n checkName(\"key\", recordKey);\n const tx = database.transaction(STORE, \"readwrite\");\n tx.objectStore(STORE).put(seal(name, recordKey, bytes), id(name, recordKey));\n await done(tx);\n },\n delete: async (recordKey) => {\n const database = guard();\n checkName(\"key\", recordKey);\n const tx = database.transaction(STORE, \"readwrite\");\n tx.objectStore(STORE).delete(id(name, recordKey));\n await done(tx);\n },\n list: async () => {\n const database = guard();\n const tx = database.transaction(STORE, \"readonly\");\n const all = tx.objectStore(STORE).getAllKeys();\n const keys = await request<IDBValidKey[]>(all);\n const prefix = `${name}\\u0000`;\n return keys\n .filter((k): k is string => typeof k === \"string\" && k.startsWith(prefix))\n .map((k) => k.slice(prefix.length));\n },\n });\n\n return {\n collection: (name) => {\n checkName(\"collection\", name);\n return make(name);\n },\n close: async () => {\n closed = true;\n db.close();\n key.fill(0);\n await Promise.resolve();\n },\n };\n}\n"],"mappings":";;;AAGA,IAAa,mBAAb,cAAsC,MAAM;CAC1C;CAEA,YAAY,MAAuB,SAAiB;EAClD,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,OAAO;CACd;AACF;;;ACRA,SAAgB,UAAU,MAA4B,OAAqB;C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