@ldgr/client 0.1.1 → 0.2.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 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
- `generateLocalWallet()` creates caller-owned key material for a service wallet
12
- and returns its recovery key exactly to the caller. Store it in your own secret
13
- manager or HSM integration; never log it or send it to LDGR.
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
@@ -70,5 +70,5 @@ export declare function createLdgrClient(options: LdgrClientOptions): {
70
70
  };
71
71
  export { LdgrClientError } from "./types";
72
72
  export type { LdgrClientOptions, LdgrNetwork, LdgrTransaction, PaymentExpectation, PaymentVerification, SignedSubmission } from "./types";
73
- export { createWebCryptoSigner, generateLocalWallet } from "./signer";
73
+ export { createWebCryptoSigner, generateLocalWallet, loadLocalWallet } from "./signer";
74
74
  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) {
@@ -231,6 +238,7 @@ function createLdgrClient(options) {
231
238
  };
232
239
  }
233
240
  export {
241
+ loadLocalWallet,
234
242
  generateLocalWallet,
235
243
  createWebCryptoSigner,
236
244
  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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ldgr/client",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "types": "./dist/index.d.ts",
6
6
  "exports": {
@@ -17,7 +17,7 @@
17
17
  "node": ">=20.19.0"
18
18
  },
19
19
  "dependencies": {
20
- "@ldgr/protocol": "^0.1.1"
20
+ "@ldgr/protocol": "^0.2.0"
21
21
  },
22
22
  "scripts": {
23
23
  "build": "rm -rf dist && bun build src/index.ts --outdir dist --target node --format esm --packages external && tsc -p tsconfig.build.json",