@keldra/sdk 0.1.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/LICENSE +22 -0
- package/README.md +93 -0
- package/dist/client-03PUOnb6.d.ts +38 -0
- package/dist/client-Bm1hg0EA.d.cts +38 -0
- package/dist/crypto/index.cjs +98 -0
- package/dist/crypto/index.d.cts +7 -0
- package/dist/crypto/index.d.ts +7 -0
- package/dist/crypto/index.js +98 -0
- package/dist/ethers/index.cjs +44 -0
- package/dist/ethers/index.d.cts +18 -0
- package/dist/ethers/index.d.ts +18 -0
- package/dist/ethers/index.js +44 -0
- package/dist/index.cjs +331 -0
- package/dist/index.d.cts +29 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +331 -0
- package/dist/types-CL-VpP9K.d.cts +121 -0
- package/dist/types-CL-VpP9K.d.ts +121 -0
- package/dist/viem/index.cjs +34 -0
- package/dist/viem/index.d.cts +16 -0
- package/dist/viem/index.d.ts +16 -0
- package/dist/viem/index.js +34 -0
- package/package.json +84 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Keldra
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# @keldra/sdk
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for the Keldra relay API.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @keldra/sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
If you want encrypted payload transport:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @keldra/sdk @stablelib/x25519 @stablelib/chacha20poly1305 @stablelib/blake2s
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
If you want framework adapters:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @keldra/sdk ethers
|
|
21
|
+
npm install @keldra/sdk viem
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { KeldraClient } from "@keldra/sdk";
|
|
28
|
+
|
|
29
|
+
const client = KeldraClient.create("kk_your_api_key");
|
|
30
|
+
const result = await client.relay("ethereum", signedTxHex);
|
|
31
|
+
const limits = await client.limits();
|
|
32
|
+
const usage = await client.usage("2026-02-01", "2026-02-20");
|
|
33
|
+
|
|
34
|
+
console.log(result.relayId, result.status, result.txHash);
|
|
35
|
+
console.log(limits.tier, usage.totals.relays_submitted);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Encrypted Transport
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import { KeldraClient } from "@keldra/sdk";
|
|
42
|
+
import { createEncryptFn } from "@keldra/sdk/crypto";
|
|
43
|
+
|
|
44
|
+
const client = KeldraClient.builder()
|
|
45
|
+
.apiKey("kk_your_api_key")
|
|
46
|
+
.withEncryption(createEncryptFn())
|
|
47
|
+
.build();
|
|
48
|
+
|
|
49
|
+
await client.fetchNoiseKey();
|
|
50
|
+
const relay = await client.submit("ethereum", signedTxHex);
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Ethers Integration
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import { KeldraClient } from "@keldra/sdk";
|
|
57
|
+
import { wrapSigner } from "@keldra/sdk/ethers";
|
|
58
|
+
|
|
59
|
+
const client = KeldraClient.create("kk_your_api_key");
|
|
60
|
+
const signer = wrapSigner(originalSigner, { client, chain: "ethereum" });
|
|
61
|
+
|
|
62
|
+
const tx = await signer.sendTransaction({ to, value });
|
|
63
|
+
console.log(tx.hash);
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Viem Integration
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
import { KeldraClient } from "@keldra/sdk";
|
|
70
|
+
import { wrapWalletClient } from "@keldra/sdk/viem";
|
|
71
|
+
|
|
72
|
+
const client = KeldraClient.create("kk_your_api_key");
|
|
73
|
+
const walletClient = wrapWalletClient(originalWalletClient, { client, chain: "ethereum" });
|
|
74
|
+
|
|
75
|
+
const relayId = await walletClient.sendTransaction({ to, value });
|
|
76
|
+
console.log(relayId);
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Exports
|
|
80
|
+
|
|
81
|
+
- `@keldra/sdk` core client, types, errors
|
|
82
|
+
- `@keldra/sdk/crypto` optional encryption helper
|
|
83
|
+
- `@keldra/sdk/ethers` ethers wrapper
|
|
84
|
+
- `@keldra/sdk/viem` viem wrapper
|
|
85
|
+
|
|
86
|
+
## Requirements
|
|
87
|
+
|
|
88
|
+
- Node.js 18+
|
|
89
|
+
- API key from Keldra
|
|
90
|
+
|
|
91
|
+
## License
|
|
92
|
+
|
|
93
|
+
MIT
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { K as KeldraClientConfig, D as DelayProfile, E as EncryptFn, 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
|
+
|
|
3
|
+
declare class KeldraClient {
|
|
4
|
+
private readonly http;
|
|
5
|
+
private readonly gatewayUrl;
|
|
6
|
+
private readonly defaultDelayProfile;
|
|
7
|
+
private readonly confirmationTimeoutMs;
|
|
8
|
+
private readonly pollIntervalMs;
|
|
9
|
+
private noisePublicKey?;
|
|
10
|
+
private noiseKid?;
|
|
11
|
+
private readonly encryptFn?;
|
|
12
|
+
constructor(config: KeldraClientConfig);
|
|
13
|
+
static create(apiKey: string): KeldraClient;
|
|
14
|
+
static builder(): KeldraClientBuilder;
|
|
15
|
+
relay(chain: Chain, signedTx: string): Promise<RelayResult>;
|
|
16
|
+
submit(chain: Chain, signedTx: string): Promise<RelayResponse>;
|
|
17
|
+
status(relayId: string): Promise<RelayStatusResponse>;
|
|
18
|
+
waitForConfirmation(relayId: string): Promise<RelayStatusResponse>;
|
|
19
|
+
health(): Promise<HealthResponse>;
|
|
20
|
+
chains(): Promise<ChainsResponse>;
|
|
21
|
+
limits(): Promise<MeLimitsResponse>;
|
|
22
|
+
usage(from: string, to: string): Promise<MeUsageResponse>;
|
|
23
|
+
fetchNoiseKey(): Promise<void>;
|
|
24
|
+
get encrypted(): boolean;
|
|
25
|
+
}
|
|
26
|
+
declare class KeldraClientBuilder {
|
|
27
|
+
private config;
|
|
28
|
+
apiKey(key: string): this;
|
|
29
|
+
gatewayUrl(url: string): this;
|
|
30
|
+
delayProfile(profile: DelayProfile): this;
|
|
31
|
+
timeout(ms: number): this;
|
|
32
|
+
pollInterval(ms: number): this;
|
|
33
|
+
noisePublicKey(key: string, kid: string): this;
|
|
34
|
+
withEncryption(fn: EncryptFn): this;
|
|
35
|
+
build(): KeldraClient;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { KeldraClient as K, KeldraClientBuilder as a };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { K as KeldraClientConfig, D as DelayProfile, E as EncryptFn, 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
|
+
|
|
3
|
+
declare class KeldraClient {
|
|
4
|
+
private readonly http;
|
|
5
|
+
private readonly gatewayUrl;
|
|
6
|
+
private readonly defaultDelayProfile;
|
|
7
|
+
private readonly confirmationTimeoutMs;
|
|
8
|
+
private readonly pollIntervalMs;
|
|
9
|
+
private noisePublicKey?;
|
|
10
|
+
private noiseKid?;
|
|
11
|
+
private readonly encryptFn?;
|
|
12
|
+
constructor(config: KeldraClientConfig);
|
|
13
|
+
static create(apiKey: string): KeldraClient;
|
|
14
|
+
static builder(): KeldraClientBuilder;
|
|
15
|
+
relay(chain: Chain, signedTx: string): Promise<RelayResult>;
|
|
16
|
+
submit(chain: Chain, signedTx: string): Promise<RelayResponse>;
|
|
17
|
+
status(relayId: string): Promise<RelayStatusResponse>;
|
|
18
|
+
waitForConfirmation(relayId: string): Promise<RelayStatusResponse>;
|
|
19
|
+
health(): Promise<HealthResponse>;
|
|
20
|
+
chains(): Promise<ChainsResponse>;
|
|
21
|
+
limits(): Promise<MeLimitsResponse>;
|
|
22
|
+
usage(from: string, to: string): Promise<MeUsageResponse>;
|
|
23
|
+
fetchNoiseKey(): Promise<void>;
|
|
24
|
+
get encrypted(): boolean;
|
|
25
|
+
}
|
|
26
|
+
declare class KeldraClientBuilder {
|
|
27
|
+
private config;
|
|
28
|
+
apiKey(key: string): this;
|
|
29
|
+
gatewayUrl(url: string): this;
|
|
30
|
+
delayProfile(profile: DelayProfile): this;
|
|
31
|
+
timeout(ms: number): this;
|
|
32
|
+
pollInterval(ms: number): this;
|
|
33
|
+
noisePublicKey(key: string, kid: string): this;
|
|
34
|
+
withEncryption(fn: EncryptFn): this;
|
|
35
|
+
build(): KeldraClient;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { KeldraClient as K, KeldraClientBuilder as a };
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/crypto/noise.ts
|
|
2
|
+
var _x25519 = require('@stablelib/x25519');
|
|
3
|
+
var _chacha20poly1305 = require('@stablelib/chacha20poly1305');
|
|
4
|
+
var _blake2s = require('@stablelib/blake2s');
|
|
5
|
+
var PROTOCOL_NAME = "Noise_NK_25519_ChaChaPoly_BLAKE2s";
|
|
6
|
+
var HASHLEN = 32;
|
|
7
|
+
async function encryptForGateway(plaintext, gatewayPublicKeyHex) {
|
|
8
|
+
const rs = hexToBytes(gatewayPublicKeyHex);
|
|
9
|
+
if (rs.length !== 32) {
|
|
10
|
+
throw new Error(`Expected 32-byte public key, got ${rs.length} bytes`);
|
|
11
|
+
}
|
|
12
|
+
const protocolBytes = new TextEncoder().encode(PROTOCOL_NAME);
|
|
13
|
+
let h;
|
|
14
|
+
if (protocolBytes.length <= HASHLEN) {
|
|
15
|
+
h = new Uint8Array(HASHLEN);
|
|
16
|
+
h.set(protocolBytes);
|
|
17
|
+
} else {
|
|
18
|
+
h = _blake2s.hash.call(void 0, protocolBytes, HASHLEN);
|
|
19
|
+
}
|
|
20
|
+
let ck = new Uint8Array(h);
|
|
21
|
+
h = _blake2s.hash.call(void 0, concat(h, new Uint8Array(0)), HASHLEN);
|
|
22
|
+
h = _blake2s.hash.call(void 0, concat(h, rs), HASHLEN);
|
|
23
|
+
const ephemeral = _x25519.generateKeyPair.call(void 0, );
|
|
24
|
+
const ePub = ephemeral.publicKey;
|
|
25
|
+
h = _blake2s.hash.call(void 0, concat(h, ePub), HASHLEN);
|
|
26
|
+
const dhResult = _x25519.sharedKey.call(void 0, ephemeral.secretKey, rs);
|
|
27
|
+
const hkdfResult = hkdf(ck, dhResult, 2);
|
|
28
|
+
ck = new Uint8Array(hkdfResult[0]);
|
|
29
|
+
const k = new Uint8Array(hkdfResult[1]);
|
|
30
|
+
const nonce = nonceBytes(0n);
|
|
31
|
+
const aead = new (0, _chacha20poly1305.ChaCha20Poly1305)(k);
|
|
32
|
+
const ciphertext = aead.seal(nonce, plaintext, h);
|
|
33
|
+
return concat(ePub, ciphertext);
|
|
34
|
+
}
|
|
35
|
+
function hexToBytes(hex) {
|
|
36
|
+
const cleaned = hex.startsWith("0x") ? hex.slice(2) : hex;
|
|
37
|
+
const bytes = new Uint8Array(cleaned.length / 2);
|
|
38
|
+
for (let i = 0; i < cleaned.length; i += 2) {
|
|
39
|
+
bytes[i / 2] = parseInt(cleaned.substring(i, i + 2), 16);
|
|
40
|
+
}
|
|
41
|
+
return bytes;
|
|
42
|
+
}
|
|
43
|
+
function concat(...arrays) {
|
|
44
|
+
const totalLen = arrays.reduce((sum, a) => sum + a.length, 0);
|
|
45
|
+
const result = new Uint8Array(totalLen);
|
|
46
|
+
let offset = 0;
|
|
47
|
+
for (const a of arrays) {
|
|
48
|
+
result.set(a, offset);
|
|
49
|
+
offset += a.length;
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
function hkdf(chainingKey, inputKeyMaterial, numOutputs) {
|
|
54
|
+
const tempKey = hmacBlake2s(chainingKey, inputKeyMaterial);
|
|
55
|
+
const outputs = [];
|
|
56
|
+
let prev = new Uint8Array(0);
|
|
57
|
+
for (let i = 1; i <= numOutputs; i++) {
|
|
58
|
+
const input = concat(prev, new Uint8Array([i]));
|
|
59
|
+
prev = new Uint8Array(hmacBlake2s(tempKey, input));
|
|
60
|
+
outputs.push(prev);
|
|
61
|
+
}
|
|
62
|
+
return outputs;
|
|
63
|
+
}
|
|
64
|
+
function hmacBlake2s(key, data) {
|
|
65
|
+
const blockSize = 64;
|
|
66
|
+
let paddedKey;
|
|
67
|
+
if (key.length > blockSize) {
|
|
68
|
+
paddedKey = new Uint8Array(blockSize);
|
|
69
|
+
paddedKey.set(_blake2s.hash.call(void 0, key, HASHLEN));
|
|
70
|
+
} else {
|
|
71
|
+
paddedKey = new Uint8Array(blockSize);
|
|
72
|
+
paddedKey.set(key);
|
|
73
|
+
}
|
|
74
|
+
const iPad = new Uint8Array(blockSize);
|
|
75
|
+
const oPad = new Uint8Array(blockSize);
|
|
76
|
+
for (let i = 0; i < blockSize; i++) {
|
|
77
|
+
iPad[i] = paddedKey[i] ^ 54;
|
|
78
|
+
oPad[i] = paddedKey[i] ^ 92;
|
|
79
|
+
}
|
|
80
|
+
const inner = _blake2s.hash.call(void 0, concat(iPad, data), HASHLEN);
|
|
81
|
+
return _blake2s.hash.call(void 0, concat(oPad, inner), HASHLEN);
|
|
82
|
+
}
|
|
83
|
+
function nonceBytes(n) {
|
|
84
|
+
const nonce = new Uint8Array(12);
|
|
85
|
+
const view = new DataView(nonce.buffer);
|
|
86
|
+
view.setUint32(4, Number(n & 0xffffffffn), true);
|
|
87
|
+
view.setUint32(8, Number(n >> 32n & 0xffffffffn), true);
|
|
88
|
+
return nonce;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// src/crypto/index.ts
|
|
92
|
+
function createEncryptFn() {
|
|
93
|
+
return encryptForGateway;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
exports.createEncryptFn = createEncryptFn; exports.encryptForGateway = encryptForGateway;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { E as EncryptFn } from '../types-CL-VpP9K.cjs';
|
|
2
|
+
|
|
3
|
+
declare function encryptForGateway(plaintext: Uint8Array, gatewayPublicKeyHex: string): Promise<Uint8Array>;
|
|
4
|
+
|
|
5
|
+
declare function createEncryptFn(): typeof encryptForGateway;
|
|
6
|
+
|
|
7
|
+
export { createEncryptFn, encryptForGateway };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { E as EncryptFn } from '../types-CL-VpP9K.js';
|
|
2
|
+
|
|
3
|
+
declare function encryptForGateway(plaintext: Uint8Array, gatewayPublicKeyHex: string): Promise<Uint8Array>;
|
|
4
|
+
|
|
5
|
+
declare function createEncryptFn(): typeof encryptForGateway;
|
|
6
|
+
|
|
7
|
+
export { createEncryptFn, encryptForGateway };
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// src/crypto/noise.ts
|
|
2
|
+
import { generateKeyPair, sharedKey } from "@stablelib/x25519";
|
|
3
|
+
import { ChaCha20Poly1305 } from "@stablelib/chacha20poly1305";
|
|
4
|
+
import { hash as blake2sHash } from "@stablelib/blake2s";
|
|
5
|
+
var PROTOCOL_NAME = "Noise_NK_25519_ChaChaPoly_BLAKE2s";
|
|
6
|
+
var HASHLEN = 32;
|
|
7
|
+
async function encryptForGateway(plaintext, gatewayPublicKeyHex) {
|
|
8
|
+
const rs = hexToBytes(gatewayPublicKeyHex);
|
|
9
|
+
if (rs.length !== 32) {
|
|
10
|
+
throw new Error(`Expected 32-byte public key, got ${rs.length} bytes`);
|
|
11
|
+
}
|
|
12
|
+
const protocolBytes = new TextEncoder().encode(PROTOCOL_NAME);
|
|
13
|
+
let h;
|
|
14
|
+
if (protocolBytes.length <= HASHLEN) {
|
|
15
|
+
h = new Uint8Array(HASHLEN);
|
|
16
|
+
h.set(protocolBytes);
|
|
17
|
+
} else {
|
|
18
|
+
h = blake2sHash(protocolBytes, HASHLEN);
|
|
19
|
+
}
|
|
20
|
+
let ck = new Uint8Array(h);
|
|
21
|
+
h = blake2sHash(concat(h, new Uint8Array(0)), HASHLEN);
|
|
22
|
+
h = blake2sHash(concat(h, rs), HASHLEN);
|
|
23
|
+
const ephemeral = generateKeyPair();
|
|
24
|
+
const ePub = ephemeral.publicKey;
|
|
25
|
+
h = blake2sHash(concat(h, ePub), HASHLEN);
|
|
26
|
+
const dhResult = sharedKey(ephemeral.secretKey, rs);
|
|
27
|
+
const hkdfResult = hkdf(ck, dhResult, 2);
|
|
28
|
+
ck = new Uint8Array(hkdfResult[0]);
|
|
29
|
+
const k = new Uint8Array(hkdfResult[1]);
|
|
30
|
+
const nonce = nonceBytes(0n);
|
|
31
|
+
const aead = new ChaCha20Poly1305(k);
|
|
32
|
+
const ciphertext = aead.seal(nonce, plaintext, h);
|
|
33
|
+
return concat(ePub, ciphertext);
|
|
34
|
+
}
|
|
35
|
+
function hexToBytes(hex) {
|
|
36
|
+
const cleaned = hex.startsWith("0x") ? hex.slice(2) : hex;
|
|
37
|
+
const bytes = new Uint8Array(cleaned.length / 2);
|
|
38
|
+
for (let i = 0; i < cleaned.length; i += 2) {
|
|
39
|
+
bytes[i / 2] = parseInt(cleaned.substring(i, i + 2), 16);
|
|
40
|
+
}
|
|
41
|
+
return bytes;
|
|
42
|
+
}
|
|
43
|
+
function concat(...arrays) {
|
|
44
|
+
const totalLen = arrays.reduce((sum, a) => sum + a.length, 0);
|
|
45
|
+
const result = new Uint8Array(totalLen);
|
|
46
|
+
let offset = 0;
|
|
47
|
+
for (const a of arrays) {
|
|
48
|
+
result.set(a, offset);
|
|
49
|
+
offset += a.length;
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
function hkdf(chainingKey, inputKeyMaterial, numOutputs) {
|
|
54
|
+
const tempKey = hmacBlake2s(chainingKey, inputKeyMaterial);
|
|
55
|
+
const outputs = [];
|
|
56
|
+
let prev = new Uint8Array(0);
|
|
57
|
+
for (let i = 1; i <= numOutputs; i++) {
|
|
58
|
+
const input = concat(prev, new Uint8Array([i]));
|
|
59
|
+
prev = new Uint8Array(hmacBlake2s(tempKey, input));
|
|
60
|
+
outputs.push(prev);
|
|
61
|
+
}
|
|
62
|
+
return outputs;
|
|
63
|
+
}
|
|
64
|
+
function hmacBlake2s(key, data) {
|
|
65
|
+
const blockSize = 64;
|
|
66
|
+
let paddedKey;
|
|
67
|
+
if (key.length > blockSize) {
|
|
68
|
+
paddedKey = new Uint8Array(blockSize);
|
|
69
|
+
paddedKey.set(blake2sHash(key, HASHLEN));
|
|
70
|
+
} else {
|
|
71
|
+
paddedKey = new Uint8Array(blockSize);
|
|
72
|
+
paddedKey.set(key);
|
|
73
|
+
}
|
|
74
|
+
const iPad = new Uint8Array(blockSize);
|
|
75
|
+
const oPad = new Uint8Array(blockSize);
|
|
76
|
+
for (let i = 0; i < blockSize; i++) {
|
|
77
|
+
iPad[i] = paddedKey[i] ^ 54;
|
|
78
|
+
oPad[i] = paddedKey[i] ^ 92;
|
|
79
|
+
}
|
|
80
|
+
const inner = blake2sHash(concat(iPad, data), HASHLEN);
|
|
81
|
+
return blake2sHash(concat(oPad, inner), HASHLEN);
|
|
82
|
+
}
|
|
83
|
+
function nonceBytes(n) {
|
|
84
|
+
const nonce = new Uint8Array(12);
|
|
85
|
+
const view = new DataView(nonce.buffer);
|
|
86
|
+
view.setUint32(4, Number(n & 0xffffffffn), true);
|
|
87
|
+
view.setUint32(8, Number(n >> 32n & 0xffffffffn), true);
|
|
88
|
+
return nonce;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// src/crypto/index.ts
|
|
92
|
+
function createEncryptFn() {
|
|
93
|
+
return encryptForGateway;
|
|
94
|
+
}
|
|
95
|
+
export {
|
|
96
|
+
createEncryptFn,
|
|
97
|
+
encryptForGateway
|
|
98
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/ethers/index.ts
|
|
2
|
+
function wrapSigner(signer, options) {
|
|
3
|
+
return new Proxy(signer, {
|
|
4
|
+
get(target, prop, receiver) {
|
|
5
|
+
if (prop === "sendTransaction") {
|
|
6
|
+
return async (tx) => {
|
|
7
|
+
const populated = await target.populateTransaction(tx);
|
|
8
|
+
const signedTx = await target.signTransaction(populated);
|
|
9
|
+
const relayResponse = await options.client.submit(
|
|
10
|
+
options.chain,
|
|
11
|
+
signedTx
|
|
12
|
+
);
|
|
13
|
+
if (options.waitForConfirmation) {
|
|
14
|
+
const result = await options.client.waitForConfirmation(
|
|
15
|
+
relayResponse.relay_id
|
|
16
|
+
);
|
|
17
|
+
return {
|
|
18
|
+
...relayResponse,
|
|
19
|
+
hash: _nullishCoalesce(result.tx_hash, () => ( relayResponse.relay_id))
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
...relayResponse,
|
|
24
|
+
hash: relayResponse.relay_id
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
return Reflect.get(target, prop, receiver);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
var KeldraBroadcaster = class {
|
|
33
|
+
constructor(client, chain) {
|
|
34
|
+
this.client = client;
|
|
35
|
+
this.chain = chain;
|
|
36
|
+
}
|
|
37
|
+
async broadcastTransaction(signedTx) {
|
|
38
|
+
return this.client.submit(this.chain, signedTx);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
exports.KeldraBroadcaster = KeldraBroadcaster; exports.wrapSigner = wrapSigner;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Signer } from 'ethers';
|
|
2
|
+
import { K as KeldraClient } from '../client-Bm1hg0EA.cjs';
|
|
3
|
+
import { C as Chain, g as RelayResponse } from '../types-CL-VpP9K.cjs';
|
|
4
|
+
|
|
5
|
+
interface KeldraBroadcasterOptions {
|
|
6
|
+
client: KeldraClient;
|
|
7
|
+
chain: Chain;
|
|
8
|
+
waitForConfirmation?: boolean;
|
|
9
|
+
}
|
|
10
|
+
declare function wrapSigner(signer: Signer, options: KeldraBroadcasterOptions): Signer;
|
|
11
|
+
declare class KeldraBroadcaster {
|
|
12
|
+
private readonly client;
|
|
13
|
+
private readonly chain;
|
|
14
|
+
constructor(client: KeldraClient, chain: Chain);
|
|
15
|
+
broadcastTransaction(signedTx: string): Promise<RelayResponse>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { KeldraBroadcaster, type KeldraBroadcasterOptions, wrapSigner };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Signer } from 'ethers';
|
|
2
|
+
import { K as KeldraClient } from '../client-03PUOnb6.js';
|
|
3
|
+
import { C as Chain, g as RelayResponse } from '../types-CL-VpP9K.js';
|
|
4
|
+
|
|
5
|
+
interface KeldraBroadcasterOptions {
|
|
6
|
+
client: KeldraClient;
|
|
7
|
+
chain: Chain;
|
|
8
|
+
waitForConfirmation?: boolean;
|
|
9
|
+
}
|
|
10
|
+
declare function wrapSigner(signer: Signer, options: KeldraBroadcasterOptions): Signer;
|
|
11
|
+
declare class KeldraBroadcaster {
|
|
12
|
+
private readonly client;
|
|
13
|
+
private readonly chain;
|
|
14
|
+
constructor(client: KeldraClient, chain: Chain);
|
|
15
|
+
broadcastTransaction(signedTx: string): Promise<RelayResponse>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { KeldraBroadcaster, type KeldraBroadcasterOptions, wrapSigner };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// src/ethers/index.ts
|
|
2
|
+
function wrapSigner(signer, options) {
|
|
3
|
+
return new Proxy(signer, {
|
|
4
|
+
get(target, prop, receiver) {
|
|
5
|
+
if (prop === "sendTransaction") {
|
|
6
|
+
return async (tx) => {
|
|
7
|
+
const populated = await target.populateTransaction(tx);
|
|
8
|
+
const signedTx = await target.signTransaction(populated);
|
|
9
|
+
const relayResponse = await options.client.submit(
|
|
10
|
+
options.chain,
|
|
11
|
+
signedTx
|
|
12
|
+
);
|
|
13
|
+
if (options.waitForConfirmation) {
|
|
14
|
+
const result = await options.client.waitForConfirmation(
|
|
15
|
+
relayResponse.relay_id
|
|
16
|
+
);
|
|
17
|
+
return {
|
|
18
|
+
...relayResponse,
|
|
19
|
+
hash: result.tx_hash ?? relayResponse.relay_id
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
...relayResponse,
|
|
24
|
+
hash: relayResponse.relay_id
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
return Reflect.get(target, prop, receiver);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
var KeldraBroadcaster = class {
|
|
33
|
+
constructor(client, chain) {
|
|
34
|
+
this.client = client;
|
|
35
|
+
this.chain = chain;
|
|
36
|
+
}
|
|
37
|
+
async broadcastTransaction(signedTx) {
|
|
38
|
+
return this.client.submit(this.chain, signedTx);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
export {
|
|
42
|
+
KeldraBroadcaster,
|
|
43
|
+
wrapSigner
|
|
44
|
+
};
|