@keldra/sdk 0.1.4 → 0.1.6
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 +16 -7
- package/dist/{client-q45X0E5a.d.ts → client-CFSlZ1qY.d.ts} +10 -1
- package/dist/{client-COg_GErM.d.cts → client-u777j3mH.d.cts} +10 -1
- package/dist/ethers/index.d.cts +1 -1
- package/dist/ethers/index.d.ts +1 -1
- package/dist/index.cjs +52 -26
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +47 -21
- package/dist/viem/index.d.cts +1 -1
- package/dist/viem/index.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -31,8 +31,10 @@ npm install @keldra/sdk viem
|
|
|
31
31
|
|
|
32
32
|
```ts
|
|
33
33
|
import { KeldraClient } from "@keldra/sdk";
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
const client = await KeldraClient.createSecure(
|
|
35
|
+
process.env.KELDRA_API_KEY!,
|
|
36
|
+
{ gatewayUrl: process.env.KELDRA_GATEWAY_URL ?? "https://keldra.network" },
|
|
37
|
+
);
|
|
36
38
|
const result = await client.relay("ethereum", signedTxHex);
|
|
37
39
|
const limits = await client.limits();
|
|
38
40
|
const usage = await client.usage("2026-02-01", "2026-02-20");
|
|
@@ -55,7 +57,7 @@ Then initialize directly:
|
|
|
55
57
|
```ts
|
|
56
58
|
import { KeldraClient } from "@keldra/sdk";
|
|
57
59
|
|
|
58
|
-
const client = KeldraClient.
|
|
60
|
+
const client = await KeldraClient.fromEnvSecure();
|
|
59
61
|
```
|
|
60
62
|
|
|
61
63
|
## Backend Proxy Example (Next.js)
|
|
@@ -66,8 +68,10 @@ Keep Keldra calls on your server route:
|
|
|
66
68
|
// app/api/relay/route.ts
|
|
67
69
|
import { NextRequest, NextResponse } from "next/server";
|
|
68
70
|
import { KeldraClient } from "@keldra/sdk";
|
|
69
|
-
|
|
70
|
-
|
|
71
|
+
const client = await KeldraClient.createSecure(
|
|
72
|
+
process.env.KELDRA_API_KEY!,
|
|
73
|
+
{ gatewayUrl: process.env.KELDRA_GATEWAY_URL ?? "https://keldra.network" },
|
|
74
|
+
);
|
|
71
75
|
|
|
72
76
|
export async function POST(req: NextRequest) {
|
|
73
77
|
const body = await req.json();
|
|
@@ -92,6 +96,7 @@ import { createEncryptFn } from "@keldra/sdk/crypto";
|
|
|
92
96
|
|
|
93
97
|
const client = KeldraClient.builder()
|
|
94
98
|
.apiKey("kk_your_api_key")
|
|
99
|
+
.gatewayUrl("https://keldra.network")
|
|
95
100
|
.withEncryption(createEncryptFn())
|
|
96
101
|
.build();
|
|
97
102
|
|
|
@@ -105,7 +110,9 @@ const relay = await client.submit("ethereum", signedTxHex);
|
|
|
105
110
|
import { KeldraClient } from "@keldra/sdk";
|
|
106
111
|
import { wrapSigner } from "@keldra/sdk/ethers";
|
|
107
112
|
|
|
108
|
-
const client = KeldraClient.
|
|
113
|
+
const client = await KeldraClient.createSecure("kk_your_api_key", {
|
|
114
|
+
gatewayUrl: "https://keldra.network",
|
|
115
|
+
});
|
|
109
116
|
const signer = wrapSigner(originalSigner, { client, chain: "ethereum" });
|
|
110
117
|
|
|
111
118
|
const tx = await signer.sendTransaction({ to, value });
|
|
@@ -118,7 +125,9 @@ console.log(tx.hash);
|
|
|
118
125
|
import { KeldraClient } from "@keldra/sdk";
|
|
119
126
|
import { wrapWalletClient } from "@keldra/sdk/viem";
|
|
120
127
|
|
|
121
|
-
const client = KeldraClient.
|
|
128
|
+
const client = await KeldraClient.createSecure("kk_your_api_key", {
|
|
129
|
+
gatewayUrl: "https://keldra.network",
|
|
130
|
+
});
|
|
122
131
|
const walletClient = wrapWalletClient(originalWalletClient, { client, chain: "ethereum" });
|
|
123
132
|
|
|
124
133
|
const relayId = await walletClient.sendTransaction({ to, value });
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { K as KeldraClientConfig,
|
|
1
|
+
import { K as KeldraClientConfig, E as EncryptFn, D as DelayProfile, C as Chain, h as RelayResult, g as RelayResponse, i as RelayStatusResponse, H as HealthResponse, b as ChainsResponse, M as MeLimitsResponse, d as MeUsageResponse } from './types-CL-VpP9K.js';
|
|
2
2
|
|
|
3
3
|
type EnvMap = Record<string, string | undefined>;
|
|
4
4
|
declare class KeldraClient {
|
|
@@ -12,10 +12,18 @@ declare class KeldraClient {
|
|
|
12
12
|
private readonly encryptFn?;
|
|
13
13
|
constructor(config: KeldraClientConfig);
|
|
14
14
|
static create(apiKey: string): KeldraClient;
|
|
15
|
+
static createSecure(apiKey: string, options?: Omit<KeldraClientConfig, 'apiKey' | 'encryptFn' | 'noisePublicKey' | 'noiseKid'> & {
|
|
16
|
+
encryptFn?: EncryptFn;
|
|
17
|
+
}): Promise<KeldraClient>;
|
|
15
18
|
static fromEnv(env?: EnvMap, options?: {
|
|
16
19
|
apiKeyEnv?: string;
|
|
17
20
|
gatewayUrlEnv?: string;
|
|
18
21
|
}): KeldraClient;
|
|
22
|
+
static fromEnvSecure(env?: EnvMap, options?: {
|
|
23
|
+
apiKeyEnv?: string;
|
|
24
|
+
gatewayUrlEnv?: string;
|
|
25
|
+
encryptFn?: EncryptFn;
|
|
26
|
+
}): Promise<KeldraClient>;
|
|
19
27
|
static builder(): KeldraClientBuilder;
|
|
20
28
|
relay(chain: Chain, signedTx: string): Promise<RelayResult>;
|
|
21
29
|
submit(chain: Chain, signedTx: string): Promise<RelayResponse>;
|
|
@@ -27,6 +35,7 @@ declare class KeldraClient {
|
|
|
27
35
|
usage(from: string, to: string): Promise<MeUsageResponse>;
|
|
28
36
|
fetchNoiseKey(): Promise<void>;
|
|
29
37
|
get encrypted(): boolean;
|
|
38
|
+
private static resolveEncryptFn;
|
|
30
39
|
}
|
|
31
40
|
declare class KeldraClientBuilder {
|
|
32
41
|
private config;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { K as KeldraClientConfig,
|
|
1
|
+
import { K as KeldraClientConfig, E as EncryptFn, D as DelayProfile, C as Chain, h as RelayResult, g as RelayResponse, i as RelayStatusResponse, H as HealthResponse, b as ChainsResponse, M as MeLimitsResponse, d as MeUsageResponse } from './types-CL-VpP9K.cjs';
|
|
2
2
|
|
|
3
3
|
type EnvMap = Record<string, string | undefined>;
|
|
4
4
|
declare class KeldraClient {
|
|
@@ -12,10 +12,18 @@ declare class KeldraClient {
|
|
|
12
12
|
private readonly encryptFn?;
|
|
13
13
|
constructor(config: KeldraClientConfig);
|
|
14
14
|
static create(apiKey: string): KeldraClient;
|
|
15
|
+
static createSecure(apiKey: string, options?: Omit<KeldraClientConfig, 'apiKey' | 'encryptFn' | 'noisePublicKey' | 'noiseKid'> & {
|
|
16
|
+
encryptFn?: EncryptFn;
|
|
17
|
+
}): Promise<KeldraClient>;
|
|
15
18
|
static fromEnv(env?: EnvMap, options?: {
|
|
16
19
|
apiKeyEnv?: string;
|
|
17
20
|
gatewayUrlEnv?: string;
|
|
18
21
|
}): KeldraClient;
|
|
22
|
+
static fromEnvSecure(env?: EnvMap, options?: {
|
|
23
|
+
apiKeyEnv?: string;
|
|
24
|
+
gatewayUrlEnv?: string;
|
|
25
|
+
encryptFn?: EncryptFn;
|
|
26
|
+
}): Promise<KeldraClient>;
|
|
19
27
|
static builder(): KeldraClientBuilder;
|
|
20
28
|
relay(chain: Chain, signedTx: string): Promise<RelayResult>;
|
|
21
29
|
submit(chain: Chain, signedTx: string): Promise<RelayResponse>;
|
|
@@ -27,6 +35,7 @@ declare class KeldraClient {
|
|
|
27
35
|
usage(from: string, to: string): Promise<MeUsageResponse>;
|
|
28
36
|
fetchNoiseKey(): Promise<void>;
|
|
29
37
|
get encrypted(): boolean;
|
|
38
|
+
private static resolveEncryptFn;
|
|
30
39
|
}
|
|
31
40
|
declare class KeldraClientBuilder {
|
|
32
41
|
private config;
|
package/dist/ethers/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Signer } from 'ethers';
|
|
2
|
-
import { K as KeldraClient } from '../client-
|
|
2
|
+
import { K as KeldraClient } from '../client-u777j3mH.cjs';
|
|
3
3
|
import { C as Chain, g as RelayResponse } from '../types-CL-VpP9K.cjs';
|
|
4
4
|
|
|
5
5
|
interface KeldraBroadcasterOptions {
|
package/dist/ethers/index.d.ts
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;// src/errors.ts
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } async function _asyncOptionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = await fn(value); } else if (op === 'call' || op === 'optionalCall') { value = await fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;// src/errors.ts
|
|
2
2
|
var KeldraError = class _KeldraError extends Error {
|
|
3
3
|
|
|
4
4
|
|
|
@@ -64,9 +64,6 @@ function parseHex(hexStr) {
|
|
|
64
64
|
}
|
|
65
65
|
return bytes;
|
|
66
66
|
}
|
|
67
|
-
function toHex(bytes) {
|
|
68
|
-
return Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
69
|
-
}
|
|
70
67
|
function toBase64(bytes) {
|
|
71
68
|
if (typeof Buffer !== "undefined") {
|
|
72
69
|
return Buffer.from(bytes).toString("base64");
|
|
@@ -202,14 +199,24 @@ var KeldraClient = class _KeldraClient {
|
|
|
202
199
|
static create(apiKey) {
|
|
203
200
|
return new _KeldraClient({ apiKey });
|
|
204
201
|
}
|
|
205
|
-
static
|
|
202
|
+
static async createSecure(apiKey, options) {
|
|
203
|
+
const encryptFn = await _asyncNullishCoalesce(await _asyncOptionalChain([options, 'optionalAccess', async _2 => _2.encryptFn]), async () => ( await _KeldraClient.resolveEncryptFn()));
|
|
204
|
+
const client = new _KeldraClient({
|
|
205
|
+
...options,
|
|
206
|
+
apiKey,
|
|
207
|
+
encryptFn
|
|
208
|
+
});
|
|
209
|
+
await client.fetchNoiseKey();
|
|
210
|
+
return client;
|
|
211
|
+
}
|
|
212
|
+
static fromEnv(env = _nullishCoalesce(_optionalChain([globalThis, 'access', _3 => _3.process, 'optionalAccess', _4 => _4.env]), () => ( {})), options) {
|
|
206
213
|
if (isBrowserRuntime()) {
|
|
207
214
|
throw KeldraError.config(
|
|
208
215
|
"KeldraClient.fromEnv() is server-only. Load KELDRA_API_KEY on your backend."
|
|
209
216
|
);
|
|
210
217
|
}
|
|
211
|
-
const apiKeyName = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
212
|
-
const gatewayUrlName = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
218
|
+
const apiKeyName = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _5 => _5.apiKeyEnv]), () => ( DEFAULT_API_KEY_ENV));
|
|
219
|
+
const gatewayUrlName = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _6 => _6.gatewayUrlEnv]), () => ( DEFAULT_GATEWAY_ENV));
|
|
213
220
|
const apiKey = env[apiKeyName];
|
|
214
221
|
if (!apiKey) {
|
|
215
222
|
throw KeldraError.config(`${apiKeyName} is required`);
|
|
@@ -219,6 +226,19 @@ var KeldraClient = class _KeldraClient {
|
|
|
219
226
|
gatewayUrl: _nullishCoalesce(env[gatewayUrlName], () => ( DEFAULT_GATEWAY_URL))
|
|
220
227
|
});
|
|
221
228
|
}
|
|
229
|
+
static async fromEnvSecure(env = _nullishCoalesce(_optionalChain([globalThis, 'access', _7 => _7.process, 'optionalAccess', _8 => _8.env]), () => ( {})), options) {
|
|
230
|
+
const apiKeyName = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _9 => _9.apiKeyEnv]), () => ( DEFAULT_API_KEY_ENV));
|
|
231
|
+
const gatewayUrlName = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _10 => _10.gatewayUrlEnv]), () => ( DEFAULT_GATEWAY_ENV));
|
|
232
|
+
const apiKey = env[apiKeyName];
|
|
233
|
+
const gatewayUrl = _nullishCoalesce(env[gatewayUrlName], () => ( DEFAULT_GATEWAY_URL));
|
|
234
|
+
if (!apiKey) {
|
|
235
|
+
throw KeldraError.config(`${apiKeyName} is required`);
|
|
236
|
+
}
|
|
237
|
+
return _KeldraClient.createSecure(apiKey, {
|
|
238
|
+
gatewayUrl,
|
|
239
|
+
encryptFn: _optionalChain([options, 'optionalAccess', _11 => _11.encryptFn])
|
|
240
|
+
});
|
|
241
|
+
}
|
|
222
242
|
static builder() {
|
|
223
243
|
return new KeldraClientBuilder();
|
|
224
244
|
}
|
|
@@ -236,25 +256,21 @@ var KeldraClient = class _KeldraClient {
|
|
|
236
256
|
}
|
|
237
257
|
async submit(chain, signedTx) {
|
|
238
258
|
const rawBytes = parseHex(signedTx);
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
const b64 = toBase64(encrypted);
|
|
244
|
-
request = {
|
|
245
|
-
chain,
|
|
246
|
-
signed_tx: "",
|
|
247
|
-
options: { delay_profile: this.defaultDelayProfile },
|
|
248
|
-
encrypted_payload: b64,
|
|
249
|
-
noise_kid: this.noiseKid
|
|
250
|
-
};
|
|
251
|
-
} else {
|
|
252
|
-
request = {
|
|
253
|
-
chain,
|
|
254
|
-
signed_tx: `0x${toHex(padded)}`,
|
|
255
|
-
options: { delay_profile: this.defaultDelayProfile }
|
|
256
|
-
};
|
|
259
|
+
if (!(this.noisePublicKey && this.noiseKid && this.encryptFn)) {
|
|
260
|
+
throw KeldraError.config(
|
|
261
|
+
"Encryption is required. Configure .withEncryption(createEncryptFn()) and call fetchNoiseKey() before submit()."
|
|
262
|
+
);
|
|
257
263
|
}
|
|
264
|
+
const padded = padTransaction(rawBytes);
|
|
265
|
+
const encrypted = await this.encryptFn(padded, this.noisePublicKey);
|
|
266
|
+
const b64 = toBase64(encrypted);
|
|
267
|
+
const request = {
|
|
268
|
+
chain,
|
|
269
|
+
signed_tx: "",
|
|
270
|
+
options: { delay_profile: this.defaultDelayProfile },
|
|
271
|
+
encrypted_payload: b64,
|
|
272
|
+
noise_kid: this.noiseKid
|
|
273
|
+
};
|
|
258
274
|
return this.http.post(
|
|
259
275
|
`${this.gatewayUrl}/v1/relay`,
|
|
260
276
|
request
|
|
@@ -280,7 +296,7 @@ var KeldraClient = class _KeldraClient {
|
|
|
280
296
|
}
|
|
281
297
|
interval = Math.min(interval * 2, MAX_POLL_INTERVAL_MS);
|
|
282
298
|
}
|
|
283
|
-
throw KeldraError.timeout(relayId, _nullishCoalesce(_optionalChain([lastStatus, 'optionalAccess',
|
|
299
|
+
throw KeldraError.timeout(relayId, _nullishCoalesce(_optionalChain([lastStatus, 'optionalAccess', _12 => _12.status]), () => ( "queued")));
|
|
284
300
|
}
|
|
285
301
|
async health() {
|
|
286
302
|
return this.http.get(`${this.gatewayUrl}/v1/health`);
|
|
@@ -307,6 +323,16 @@ var KeldraClient = class _KeldraClient {
|
|
|
307
323
|
get encrypted() {
|
|
308
324
|
return !!(this.noisePublicKey && this.noiseKid && this.encryptFn);
|
|
309
325
|
}
|
|
326
|
+
static async resolveEncryptFn() {
|
|
327
|
+
try {
|
|
328
|
+
const mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./crypto/index.cjs")));
|
|
329
|
+
return mod.createEncryptFn();
|
|
330
|
+
} catch (e3) {
|
|
331
|
+
throw KeldraError.config(
|
|
332
|
+
"Encryption helpers are not installed. Install @stablelib/x25519 @stablelib/chacha20poly1305 @stablelib/blake2s or provide encryptFn manually."
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
310
336
|
};
|
|
311
337
|
var KeldraClientBuilder = (_class = class {constructor() { _class.prototype.__init.call(this); }
|
|
312
338
|
__init() {this.config = {}}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { K as KeldraClient, a as KeldraClientBuilder } from './client-
|
|
1
|
+
export { K as KeldraClient, a as KeldraClientBuilder } from './client-u777j3mH.cjs';
|
|
2
2
|
import { R as RelayStatus } from './types-CL-VpP9K.cjs';
|
|
3
3
|
export { C as Chain, a as ChainConfig, b as ChainsResponse, D as DelayProfile, E as EncryptFn, H as HealthResponse, c as HealthStats, K as KeldraClientConfig, M as MeLimitsResponse, d as MeUsageResponse, N as NoiseKeyResponse, e as RelayOptions, f as RelayRequest, g as RelayResponse, h as RelayResult, i as RelayStatusResponse, T as TERMINAL_STATUSES, U as UsageDailyRow, j as UsageTotals } from './types-CL-VpP9K.cjs';
|
|
4
4
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { K as KeldraClient, a as KeldraClientBuilder } from './client-
|
|
1
|
+
export { K as KeldraClient, a as KeldraClientBuilder } from './client-CFSlZ1qY.js';
|
|
2
2
|
import { R as RelayStatus } from './types-CL-VpP9K.js';
|
|
3
3
|
export { C as Chain, a as ChainConfig, b as ChainsResponse, D as DelayProfile, E as EncryptFn, H as HealthResponse, c as HealthStats, K as KeldraClientConfig, M as MeLimitsResponse, d as MeUsageResponse, N as NoiseKeyResponse, e as RelayOptions, f as RelayRequest, g as RelayResponse, h as RelayResult, i as RelayStatusResponse, T as TERMINAL_STATUSES, U as UsageDailyRow, j as UsageTotals } from './types-CL-VpP9K.js';
|
|
4
4
|
|
package/dist/index.js
CHANGED
|
@@ -64,9 +64,6 @@ function parseHex(hexStr) {
|
|
|
64
64
|
}
|
|
65
65
|
return bytes;
|
|
66
66
|
}
|
|
67
|
-
function toHex(bytes) {
|
|
68
|
-
return Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
69
|
-
}
|
|
70
67
|
function toBase64(bytes) {
|
|
71
68
|
if (typeof Buffer !== "undefined") {
|
|
72
69
|
return Buffer.from(bytes).toString("base64");
|
|
@@ -202,6 +199,16 @@ var KeldraClient = class _KeldraClient {
|
|
|
202
199
|
static create(apiKey) {
|
|
203
200
|
return new _KeldraClient({ apiKey });
|
|
204
201
|
}
|
|
202
|
+
static async createSecure(apiKey, options) {
|
|
203
|
+
const encryptFn = options?.encryptFn ?? await _KeldraClient.resolveEncryptFn();
|
|
204
|
+
const client = new _KeldraClient({
|
|
205
|
+
...options,
|
|
206
|
+
apiKey,
|
|
207
|
+
encryptFn
|
|
208
|
+
});
|
|
209
|
+
await client.fetchNoiseKey();
|
|
210
|
+
return client;
|
|
211
|
+
}
|
|
205
212
|
static fromEnv(env = globalThis.process?.env ?? {}, options) {
|
|
206
213
|
if (isBrowserRuntime()) {
|
|
207
214
|
throw KeldraError.config(
|
|
@@ -219,6 +226,19 @@ var KeldraClient = class _KeldraClient {
|
|
|
219
226
|
gatewayUrl: env[gatewayUrlName] ?? DEFAULT_GATEWAY_URL
|
|
220
227
|
});
|
|
221
228
|
}
|
|
229
|
+
static async fromEnvSecure(env = globalThis.process?.env ?? {}, options) {
|
|
230
|
+
const apiKeyName = options?.apiKeyEnv ?? DEFAULT_API_KEY_ENV;
|
|
231
|
+
const gatewayUrlName = options?.gatewayUrlEnv ?? DEFAULT_GATEWAY_ENV;
|
|
232
|
+
const apiKey = env[apiKeyName];
|
|
233
|
+
const gatewayUrl = env[gatewayUrlName] ?? DEFAULT_GATEWAY_URL;
|
|
234
|
+
if (!apiKey) {
|
|
235
|
+
throw KeldraError.config(`${apiKeyName} is required`);
|
|
236
|
+
}
|
|
237
|
+
return _KeldraClient.createSecure(apiKey, {
|
|
238
|
+
gatewayUrl,
|
|
239
|
+
encryptFn: options?.encryptFn
|
|
240
|
+
});
|
|
241
|
+
}
|
|
222
242
|
static builder() {
|
|
223
243
|
return new KeldraClientBuilder();
|
|
224
244
|
}
|
|
@@ -236,25 +256,21 @@ var KeldraClient = class _KeldraClient {
|
|
|
236
256
|
}
|
|
237
257
|
async submit(chain, signedTx) {
|
|
238
258
|
const rawBytes = parseHex(signedTx);
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
const b64 = toBase64(encrypted);
|
|
244
|
-
request = {
|
|
245
|
-
chain,
|
|
246
|
-
signed_tx: "",
|
|
247
|
-
options: { delay_profile: this.defaultDelayProfile },
|
|
248
|
-
encrypted_payload: b64,
|
|
249
|
-
noise_kid: this.noiseKid
|
|
250
|
-
};
|
|
251
|
-
} else {
|
|
252
|
-
request = {
|
|
253
|
-
chain,
|
|
254
|
-
signed_tx: `0x${toHex(padded)}`,
|
|
255
|
-
options: { delay_profile: this.defaultDelayProfile }
|
|
256
|
-
};
|
|
259
|
+
if (!(this.noisePublicKey && this.noiseKid && this.encryptFn)) {
|
|
260
|
+
throw KeldraError.config(
|
|
261
|
+
"Encryption is required. Configure .withEncryption(createEncryptFn()) and call fetchNoiseKey() before submit()."
|
|
262
|
+
);
|
|
257
263
|
}
|
|
264
|
+
const padded = padTransaction(rawBytes);
|
|
265
|
+
const encrypted = await this.encryptFn(padded, this.noisePublicKey);
|
|
266
|
+
const b64 = toBase64(encrypted);
|
|
267
|
+
const request = {
|
|
268
|
+
chain,
|
|
269
|
+
signed_tx: "",
|
|
270
|
+
options: { delay_profile: this.defaultDelayProfile },
|
|
271
|
+
encrypted_payload: b64,
|
|
272
|
+
noise_kid: this.noiseKid
|
|
273
|
+
};
|
|
258
274
|
return this.http.post(
|
|
259
275
|
`${this.gatewayUrl}/v1/relay`,
|
|
260
276
|
request
|
|
@@ -307,6 +323,16 @@ var KeldraClient = class _KeldraClient {
|
|
|
307
323
|
get encrypted() {
|
|
308
324
|
return !!(this.noisePublicKey && this.noiseKid && this.encryptFn);
|
|
309
325
|
}
|
|
326
|
+
static async resolveEncryptFn() {
|
|
327
|
+
try {
|
|
328
|
+
const mod = await import("./crypto/index.js");
|
|
329
|
+
return mod.createEncryptFn();
|
|
330
|
+
} catch {
|
|
331
|
+
throw KeldraError.config(
|
|
332
|
+
"Encryption helpers are not installed. Install @stablelib/x25519 @stablelib/chacha20poly1305 @stablelib/blake2s or provide encryptFn manually."
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
310
336
|
};
|
|
311
337
|
var KeldraClientBuilder = class {
|
|
312
338
|
config = {};
|
package/dist/viem/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Transport, Chain as Chain$1, Account, WalletClient } from 'viem';
|
|
2
|
-
import { K as KeldraClient } from '../client-
|
|
2
|
+
import { K as KeldraClient } from '../client-u777j3mH.cjs';
|
|
3
3
|
import { C as Chain } from '../types-CL-VpP9K.cjs';
|
|
4
4
|
|
|
5
5
|
interface KeldraViemOptions {
|
package/dist/viem/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Transport, Chain as Chain$1, Account, WalletClient } from 'viem';
|
|
2
|
-
import { K as KeldraClient } from '../client-
|
|
2
|
+
import { K as KeldraClient } from '../client-CFSlZ1qY.js';
|
|
3
3
|
import { C as Chain } from '../types-CL-VpP9K.js';
|
|
4
4
|
|
|
5
5
|
interface KeldraViemOptions {
|