@ldgr/client 0.1.1 → 0.2.1
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 +26 -3
- package/dist/index.d.ts +8 -4
- package/dist/index.js +12 -1
- package/dist/signer.d.ts +5 -0
- package/dist/types.d.ts +11 -1
- package/package.json +13 -16
package/README.md
CHANGED
|
@@ -8,9 +8,32 @@ It does not create a hosted wallet, persist a private key, or replace the
|
|
|
8
8
|
browser extension. Use `@ldgr/wallet-sdk` when a website needs an explicit
|
|
9
9
|
user confirmation in the LDGR extension.
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
## Service wallets and recovery keys
|
|
12
|
+
|
|
13
|
+
`generateLocalWallet()` creates caller-owned key material for a service wallet.
|
|
14
|
+
Save its recovery key directly to your secret manager exactly once, then use
|
|
15
|
+
`loadLocalWallet()` on service startup to recreate the signer. The recovery key
|
|
16
|
+
is bearer private-key material: never log, commit, pass it in arguments or
|
|
17
|
+
browser storage, send it to LDGR, or use it for a customer wallet.
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { generateLocalWallet, loadLocalWallet } from "@ldgr/client";
|
|
21
|
+
|
|
22
|
+
// Provision once. `secretStore` represents your secret-manager or HSM workflow.
|
|
23
|
+
const created = await generateLocalWallet({ ledgerId: 1 });
|
|
24
|
+
await secretStore.writeOnce("ldgr-service-wallet", created.recoveryKey);
|
|
25
|
+
|
|
26
|
+
// On each service startup, recover the same signer without printing the key.
|
|
27
|
+
const serviceWallet = await loadLocalWallet({
|
|
28
|
+
ledgerId: 1,
|
|
29
|
+
recoveryKey: await secretStore.read("ldgr-service-wallet"),
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
console.log(serviceWallet.address); // safe to identify the service wallet
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
This is for backend/Bun service wallets only. Websites should use
|
|
36
|
+
`@ldgr/wallet-sdk` and an extension-confirmed customer wallet instead.
|
|
14
37
|
|
|
15
38
|
```ts
|
|
16
39
|
import { createLdgrClient } from "@ldgr/client";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type LdgrClientOptions, type LdgrTransaction, type PaymentExpectation, type PaymentVerification, type SignedSubmission } from "./types";
|
|
1
|
+
import { type LdgrClientOptions, type LdgrAsset, type LdgrTransaction, type PaymentExpectation, type PaymentVerification, type SignedSubmission } from "./types";
|
|
2
2
|
export declare function createLdgrClient(options: LdgrClientOptions): {
|
|
3
3
|
ledger: {
|
|
4
4
|
get: () => Promise<{
|
|
@@ -25,12 +25,16 @@ export declare function createLdgrClient(options: LdgrClientOptions): {
|
|
|
25
25
|
readonly nextNonce: string;
|
|
26
26
|
}>;
|
|
27
27
|
};
|
|
28
|
+
assets: {
|
|
29
|
+
get: (asset: string) => Promise<LdgrAsset>;
|
|
30
|
+
};
|
|
28
31
|
transactions: {
|
|
29
32
|
get: (transactionHash: string) => Promise<LdgrTransaction>;
|
|
30
33
|
};
|
|
31
34
|
amm: {
|
|
32
|
-
listPools: () => Promise<{
|
|
35
|
+
listPools: (cursor?: string, limit?: number) => Promise<{
|
|
33
36
|
readonly pools: readonly Record<string, unknown>[];
|
|
37
|
+
readonly nextCursor?: string;
|
|
34
38
|
}>;
|
|
35
39
|
getPool: (poolId: string) => Promise<Record<string, unknown>>;
|
|
36
40
|
getPoolByPair: (assetA: string, assetB: string) => Promise<Record<string, unknown>>;
|
|
@@ -69,6 +73,6 @@ export declare function createLdgrClient(options: LdgrClientOptions): {
|
|
|
69
73
|
}>(path: string, signed: SignedSubmission) => Promise<T>;
|
|
70
74
|
};
|
|
71
75
|
export { LdgrClientError } from "./types";
|
|
72
|
-
export type { LdgrClientOptions, LdgrNetwork, LdgrTransaction, PaymentExpectation, PaymentVerification, SignedSubmission } from "./types";
|
|
73
|
-
export { createWebCryptoSigner, generateLocalWallet } from "./signer";
|
|
76
|
+
export type { LdgrAsset, LdgrClientOptions, LdgrNetwork, LdgrTransaction, PaymentExpectation, PaymentVerification, SignedSubmission } from "./types";
|
|
77
|
+
export { createWebCryptoSigner, generateLocalWallet, loadLocalWallet } from "./signer";
|
|
74
78
|
export type { LdgrSigner, LocalLdgrWallet } from "./signer";
|
package/dist/index.js
CHANGED
|
@@ -82,9 +82,11 @@ import { resolveLdgrNetwork as resolveLdgrNetwork2, resolvePublicAssetCode } fro
|
|
|
82
82
|
// src/signer.ts
|
|
83
83
|
import {
|
|
84
84
|
deriveAddress,
|
|
85
|
+
decodeEd25519RecoveryKey,
|
|
85
86
|
encodeEd25519RecoveryKey,
|
|
86
87
|
exportEd25519PublicKey,
|
|
87
88
|
generateEd25519KeyPair,
|
|
89
|
+
importEd25519PrivateSeed,
|
|
88
90
|
signCanonicalPayload
|
|
89
91
|
} from "@ldgr/protocol";
|
|
90
92
|
function encodeBase64Url(bytes) {
|
|
@@ -121,6 +123,11 @@ async function generateLocalWallet(input) {
|
|
|
121
123
|
recoveryKey: encodeEd25519RecoveryKey(privateKeyJwk)
|
|
122
124
|
};
|
|
123
125
|
}
|
|
126
|
+
async function loadLocalWallet(input) {
|
|
127
|
+
const { privateSeed } = decodeEd25519RecoveryKey(input.recoveryKey);
|
|
128
|
+
const keyPair = await importEd25519PrivateSeed(privateSeed);
|
|
129
|
+
return createWebCryptoSigner({ ...input, ...keyPair });
|
|
130
|
+
}
|
|
124
131
|
|
|
125
132
|
// src/index.ts
|
|
126
133
|
function normalizedHash(transactionHash) {
|
|
@@ -168,11 +175,14 @@ function createLdgrClient(options) {
|
|
|
168
175
|
getBalance: (address, asset) => transport.get(`/api/v1/balances/${encodePathSegment(address)}/${encodePathSegment(resolveAsset(asset))}`),
|
|
169
176
|
getNextNonce: (address, asset) => transport.get(`/api/v1/nonces/${encodePathSegment(address)}/${encodePathSegment(resolveAsset(asset))}`)
|
|
170
177
|
},
|
|
178
|
+
assets: {
|
|
179
|
+
get: (asset) => transport.get(`/api/v1/assets/${encodePathSegment(resolveAsset(asset))}`)
|
|
180
|
+
},
|
|
171
181
|
transactions: {
|
|
172
182
|
get: (transactionHash) => transport.get(`/api/v1/transactions/${normalizedHash(transactionHash)}`)
|
|
173
183
|
},
|
|
174
184
|
amm: {
|
|
175
|
-
listPools: () => transport.get("/api/v1/amm/pools"),
|
|
185
|
+
listPools: (cursor, limit) => transport.get(queryPath("/api/v1/amm/pools", { cursor, limit })),
|
|
176
186
|
getPool: (poolId) => transport.get(`/api/v1/amm/pools/${encodePathSegment(poolId)}`),
|
|
177
187
|
getPoolByPair: (assetA, assetB) => transport.get(`/api/v1/amm/pools/by-pair/${encodePathSegment(resolveAsset(assetA))}/${encodePathSegment(resolveAsset(assetB))}`),
|
|
178
188
|
quoteSwap: (poolId, assetIn, amountIn) => transport.get(queryPath(`/api/v1/amm/pools/${encodePathSegment(poolId)}/quote`, { assetIn: resolveAsset(assetIn), amountIn })),
|
|
@@ -231,6 +241,7 @@ function createLdgrClient(options) {
|
|
|
231
241
|
};
|
|
232
242
|
}
|
|
233
243
|
export {
|
|
244
|
+
loadLocalWallet,
|
|
234
245
|
generateLocalWallet,
|
|
235
246
|
createWebCryptoSigner,
|
|
236
247
|
createLdgrClient,
|
package/dist/signer.d.ts
CHANGED
|
@@ -17,3 +17,8 @@ export declare function createWebCryptoSigner(input: {
|
|
|
17
17
|
export declare function generateLocalWallet(input: {
|
|
18
18
|
readonly ledgerId: LedgerId;
|
|
19
19
|
}): Promise<LocalLdgrWallet>;
|
|
20
|
+
/** Restores a caller-owned signer from canonical LDGR recovery material. */
|
|
21
|
+
export declare function loadLocalWallet(input: {
|
|
22
|
+
readonly recoveryKey: string;
|
|
23
|
+
readonly ledgerId: LedgerId;
|
|
24
|
+
}): Promise<LdgrSigner>;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { LdgrNetwork } from "@ldgr/protocol";
|
|
1
|
+
import type { AssetBridgePolicy, LdgrNetwork } from "@ldgr/protocol";
|
|
2
2
|
export type LedgerId = 0 | 1;
|
|
3
3
|
export type { LdgrNetwork } from "@ldgr/protocol";
|
|
4
4
|
export type LdgrTransaction = {
|
|
@@ -12,6 +12,16 @@ export type LdgrTransaction = {
|
|
|
12
12
|
readonly transactionHash: string;
|
|
13
13
|
readonly [key: string]: unknown;
|
|
14
14
|
};
|
|
15
|
+
/** Public asset metadata used to format user-facing balances and transfer amounts. */
|
|
16
|
+
export type LdgrAsset = {
|
|
17
|
+
readonly code: string;
|
|
18
|
+
readonly displayName: string;
|
|
19
|
+
readonly ticker?: string;
|
|
20
|
+
readonly decimals: number;
|
|
21
|
+
readonly active: boolean;
|
|
22
|
+
readonly bridgePolicy: AssetBridgePolicy;
|
|
23
|
+
readonly [key: string]: unknown;
|
|
24
|
+
};
|
|
15
25
|
export type PaymentExpectation = {
|
|
16
26
|
readonly to: string;
|
|
17
27
|
readonly asset?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ldgr/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -10,19 +10,16 @@
|
|
|
10
10
|
}
|
|
11
11
|
},
|
|
12
12
|
"files": ["dist", "README.md"],
|
|
13
|
-
"publishConfig": {
|
|
14
|
-
"
|
|
15
|
-
},
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
},
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"test": "bun test",
|
|
26
|
-
"typecheck": "tsc -p tsconfig.json"
|
|
27
|
-
}
|
|
13
|
+
"publishConfig": { "access": "public" },
|
|
14
|
+
"engines": { "node": ">=20.19.0" },
|
|
15
|
+
"dependencies": { "@ldgr/protocol": "^0.2.0" },
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "rm -rf dist && bun build src/index.ts --outdir dist --target node --format esm --packages external && tsc -p tsconfig.build.json",
|
|
18
|
+
"prepack": "bun run build",
|
|
19
|
+
"test": "bun test",
|
|
20
|
+
"typecheck": "tsc -p tsconfig.json"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"typescript": "^5.9.3"
|
|
24
|
+
}
|
|
28
25
|
}
|