@1sat/wallet-remote 0.0.10 → 0.0.12
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/dist/createRemoteWallet.d.ts +7 -32
- package/dist/createRemoteWallet.d.ts.map +1 -1
- package/dist/createRemoteWallet.js +14 -101
- package/dist/createRemoteWallet.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
|
@@ -1,52 +1,27 @@
|
|
|
1
|
-
import { OneSatServices } from '@1sat/client';
|
|
2
|
-
import { PrivateKey } from '@bsv/sdk';
|
|
3
|
-
import {
|
|
4
|
-
type Chain = 'main' | 'test';
|
|
5
|
-
export interface LocalBackupConfig {
|
|
6
|
-
/** IndexedDB database name. Default: 'wallet-backup-{chain}net' */
|
|
7
|
-
databaseName?: string;
|
|
8
|
-
}
|
|
1
|
+
import type { OneSatServices } from '@1sat/client';
|
|
2
|
+
import type { PrivateKey } from '@bsv/sdk';
|
|
3
|
+
import { Wallet, WalletStorageManager } from '@bsv/wallet-toolbox/out/src/index.client.js';
|
|
9
4
|
export interface RemoteWalletConfig {
|
|
10
|
-
/** Private key - can be PrivateKey instance, WIF string, or hex string */
|
|
11
5
|
privateKey: PrivateKey | string;
|
|
12
|
-
|
|
13
|
-
chain: Chain;
|
|
14
|
-
/** Remote storage server URL */
|
|
15
|
-
remoteStorageUrl: string;
|
|
16
|
-
/** Fee model. Default: { model: 'sat/kb', value: 100 } */
|
|
6
|
+
chain: 'main' | 'test';
|
|
17
7
|
feeModel?: {
|
|
18
8
|
model: 'sat/kb';
|
|
19
9
|
value: number;
|
|
20
10
|
};
|
|
21
|
-
|
|
11
|
+
activeRemote: string;
|
|
12
|
+
backups?: string[];
|
|
22
13
|
connectionTimeout?: number;
|
|
23
|
-
/** Enable local IndexedDB backup. true = defaults, or pass options. */
|
|
24
|
-
localBackup?: boolean | LocalBackupConfig;
|
|
25
14
|
}
|
|
26
15
|
export interface RemoteWalletResult {
|
|
27
|
-
/** Wallet instance */
|
|
28
16
|
wallet: Wallet;
|
|
29
|
-
/** 1Sat services for API access */
|
|
30
17
|
services: OneSatServices;
|
|
31
|
-
/** Cleanup function - destroys wallet */
|
|
32
18
|
destroy: () => Promise<void>;
|
|
33
|
-
/** Storage manager (for diagnostics) */
|
|
34
19
|
storage: WalletStorageManager;
|
|
35
|
-
/** Effective fee model used by this wallet */
|
|
36
20
|
feeModel: {
|
|
37
21
|
model: 'sat/kb';
|
|
38
22
|
value: number;
|
|
39
23
|
};
|
|
40
|
-
|
|
41
|
-
backupStorage?: StorageIdb;
|
|
24
|
+
migrateRemote: (url: string) => Promise<void>;
|
|
42
25
|
}
|
|
43
|
-
/**
|
|
44
|
-
* Create a wallet that uses a remote storage server as its primary storage.
|
|
45
|
-
*
|
|
46
|
-
* When `localBackup` is enabled, a local IndexedDB backup is created and
|
|
47
|
-
* kept in sync after each state-changing operation. The remote remains the
|
|
48
|
-
* active storage — the local copy is for data safety and provider migration.
|
|
49
|
-
*/
|
|
50
26
|
export declare function createRemoteWallet(config: RemoteWalletConfig): Promise<RemoteWalletResult>;
|
|
51
|
-
export {};
|
|
52
27
|
//# sourceMappingURL=createRemoteWallet.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRemoteWallet.d.ts","sourceRoot":"","sources":["../src/createRemoteWallet.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createRemoteWallet.d.ts","sourceRoot":"","sources":["../src/createRemoteWallet.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAC1C,OAAO,EAIN,MAAM,EACN,oBAAoB,EACpB,MAAM,6CAA6C,CAAA;AAEpD,MAAM,WAAW,kBAAkB;IAClC,UAAU,EAAE,UAAU,GAAG,MAAM,CAAA;IAC/B,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;IACtB,QAAQ,CAAC,EAAE;QAAE,KAAK,EAAE,QAAQ,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;IAC7C,YAAY,EAAE,MAAM,CAAA;IACpB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAC1B;AAED,MAAM,WAAW,kBAAkB;IAClC,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,cAAc,CAAA;IACxB,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAC5B,OAAO,EAAE,oBAAoB,CAAA;IAC7B,QAAQ,EAAE;QAAE,KAAK,EAAE,QAAQ,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;IAC5C,aAAa,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CAC7C;AAED,wBAAsB,kBAAkB,CACvC,MAAM,EAAE,kBAAkB,GACxB,OAAO,CAAC,kBAAkB,CAAC,CAqB7B"}
|
|
@@ -1,107 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Services, StorageClient, StorageIdb, StorageProvider, Wallet, WalletStorageManager, } from '@bsv/wallet-toolbox/out/src/index.client.js';
|
|
4
|
-
const DEFAULT_FEE_MODEL = { model: 'sat/kb', value: 100 };
|
|
5
|
-
const DEFAULT_CONNECTION_TIMEOUT = 5000;
|
|
6
|
-
function parsePrivateKey(input) {
|
|
7
|
-
if (input instanceof PrivateKey) {
|
|
8
|
-
return input;
|
|
9
|
-
}
|
|
10
|
-
if (/^[5KLc][1-9A-HJ-NP-Za-km-z]{50,51}$/.test(input)) {
|
|
11
|
-
return PrivateKey.fromWif(input);
|
|
12
|
-
}
|
|
13
|
-
if (/^[0-9a-fA-F]{64}$/.test(input)) {
|
|
14
|
-
return new PrivateKey(input);
|
|
15
|
-
}
|
|
16
|
-
try {
|
|
17
|
-
return PrivateKey.fromWif(input);
|
|
18
|
-
}
|
|
19
|
-
catch {
|
|
20
|
-
throw new Error('Invalid private key format. Expected PrivateKey instance, WIF string, or 64-char hex string.');
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Create a wallet that uses a remote storage server as its primary storage.
|
|
25
|
-
*
|
|
26
|
-
* When `localBackup` is enabled, a local IndexedDB backup is created and
|
|
27
|
-
* kept in sync after each state-changing operation. The remote remains the
|
|
28
|
-
* active storage — the local copy is for data safety and provider migration.
|
|
29
|
-
*/
|
|
1
|
+
import { createWalletCore, } from '@1sat/wallet';
|
|
2
|
+
import { Services, StorageClient, StorageProvider, Wallet, WalletStorageManager, } from '@bsv/wallet-toolbox/out/src/index.client.js';
|
|
30
3
|
export async function createRemoteWallet(config) {
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const fallbackServices = new Services(chain);
|
|
38
|
-
const oneSatServices = new OneSatServices(chain, undefined, fallbackServices);
|
|
39
|
-
// Create storage manager without any stores initially.
|
|
40
|
-
// _authId is set from identityKey, which is all the Wallet constructor needs.
|
|
41
|
-
const storage = new WalletStorageManager(identityPubKey);
|
|
42
|
-
// Create wallet — needed by StorageClient for AuthFetch signing.
|
|
43
|
-
// The Wallet constructor only checks storage._authId.identityKey and calls
|
|
44
|
-
// storage.setServices(), both of which work on an empty manager.
|
|
45
|
-
const wallet = new Wallet({
|
|
46
|
-
chain,
|
|
47
|
-
keyDeriver,
|
|
48
|
-
storage,
|
|
49
|
-
services: oneSatServices,
|
|
4
|
+
const core = await createWalletCore(config, undefined, {
|
|
5
|
+
Services,
|
|
6
|
+
StorageClient,
|
|
7
|
+
StorageProvider,
|
|
8
|
+
Wallet,
|
|
9
|
+
WalletStorageManager,
|
|
50
10
|
});
|
|
51
|
-
// Create remote storage client using the wallet for authenticated requests.
|
|
52
|
-
const remoteClient = new StorageClient(wallet, config.remoteStorageUrl);
|
|
53
|
-
// Connect and make the remote storage the active (and only) store.
|
|
54
|
-
// addWalletStorageProvider calls remoteClient.makeAvailable() internally,
|
|
55
|
-
// which triggers AuthFetch using the wallet for signing.
|
|
56
|
-
const timeoutPromise = new Promise((_, reject) => setTimeout(() => reject(new Error('Remote storage connection timeout')), timeout));
|
|
57
|
-
await Promise.race([
|
|
58
|
-
storage.addWalletStorageProvider(remoteClient),
|
|
59
|
-
timeoutPromise,
|
|
60
|
-
]);
|
|
61
|
-
// Ensure user.activeStorage matches the remote server's storageIdentityKey.
|
|
62
|
-
// Without this, isActiveEnabled returns false and writes fail with WERR_NOT_ACTIVE.
|
|
63
|
-
const remoteSettings = remoteClient.getSettings();
|
|
64
|
-
if (remoteSettings?.storageIdentityKey) {
|
|
65
|
-
await storage.setActive(remoteSettings.storageIdentityKey);
|
|
66
|
-
}
|
|
67
|
-
// Set up local backup if requested
|
|
68
|
-
let backupStorage;
|
|
69
|
-
if (config.localBackup) {
|
|
70
|
-
const opts = typeof config.localBackup === 'object' ? config.localBackup : {};
|
|
71
|
-
const dbName = opts.databaseName ?? `wallet-backup-${chain}net`;
|
|
72
|
-
const storageOptions = StorageProvider.createStorageBaseOptions(chain);
|
|
73
|
-
storageOptions.feeModel = feeModel;
|
|
74
|
-
backupStorage = new StorageIdb(storageOptions);
|
|
75
|
-
await backupStorage.migrate(dbName, `${identityPubKey}-backup`);
|
|
76
|
-
await storage.addWalletStorageProvider(backupStorage);
|
|
77
|
-
await storage.updateBackups();
|
|
78
|
-
const originalCreateAction = wallet.createAction.bind(wallet);
|
|
79
|
-
wallet.createAction = async (args) => {
|
|
80
|
-
const result = await originalCreateAction(args);
|
|
81
|
-
if (result.txid) {
|
|
82
|
-
storage.updateBackups().catch(() => { });
|
|
83
|
-
}
|
|
84
|
-
return result;
|
|
85
|
-
};
|
|
86
|
-
const originalSignAction = wallet.signAction.bind(wallet);
|
|
87
|
-
wallet.signAction = async (args) => {
|
|
88
|
-
const result = await originalSignAction(args);
|
|
89
|
-
if (result.txid) {
|
|
90
|
-
storage.updateBackups().catch(() => { });
|
|
91
|
-
}
|
|
92
|
-
return result;
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
const destroy = async () => {
|
|
96
|
-
await wallet.destroy();
|
|
97
|
-
};
|
|
98
11
|
return {
|
|
99
|
-
wallet,
|
|
100
|
-
services:
|
|
101
|
-
destroy,
|
|
102
|
-
storage,
|
|
103
|
-
feeModel,
|
|
104
|
-
|
|
12
|
+
wallet: core.wallet,
|
|
13
|
+
services: core.services,
|
|
14
|
+
destroy: core.destroy,
|
|
15
|
+
storage: core.storage,
|
|
16
|
+
feeModel: core.feeModel,
|
|
17
|
+
migrateRemote: core.migrateRemote,
|
|
105
18
|
};
|
|
106
19
|
}
|
|
107
20
|
//# sourceMappingURL=createRemoteWallet.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRemoteWallet.js","sourceRoot":"","sources":["../src/createRemoteWallet.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"createRemoteWallet.js","sourceRoot":"","sources":["../src/createRemoteWallet.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,gBAAgB,GAEhB,MAAM,cAAc,CAAA;AAGrB,OAAO,EACN,QAAQ,EACR,aAAa,EACb,eAAe,EACf,MAAM,EACN,oBAAoB,GACpB,MAAM,6CAA6C,CAAA;AAoBpD,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACvC,MAA0B;IAE1B,MAAM,IAAI,GAAG,MAAM,gBAAgB,CAClC,MAAM,EACN,SAAS,EACT;QACC,QAAQ;QACR,aAAa;QACb,eAAe;QACf,MAAM;QACN,oBAAoB;KACpB,CACD,CAAA;IAED,OAAO;QACN,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,aAAa,EAAE,IAAI,CAAC,aAAa;KACjC,CAAA;AACF,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from '@1sat/wallet';
|
|
2
2
|
export { createRemoteWallet } from './createRemoteWallet';
|
|
3
|
-
export type {
|
|
3
|
+
export type { RemoteWalletConfig, RemoteWalletResult, } from './createRemoteWallet';
|
|
4
4
|
export { Services, StorageClient, Wallet, WalletStorageManager, type sdk as walletSdk, } from '@bsv/wallet-toolbox/out/src/index.client.js';
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAE5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACzD,YAAY,EACX,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAE5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACzD,YAAY,EACX,kBAAkB,EAClB,kBAAkB,GAClB,MAAM,sBAAsB,CAAA;AAE7B,OAAO,EACN,QAAQ,EACR,aAAa,EACb,MAAM,EACN,oBAAoB,EACpB,KAAK,GAAG,IAAI,SAAS,GACrB,MAAM,6CAA6C,CAAA"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAE5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAE5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAMzD,OAAO,EACN,QAAQ,EACR,aAAa,EACb,MAAM,EACN,oBAAoB,GAEpB,MAAM,6CAA6C,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1sat/wallet-remote",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"description": "Remote-only wallet factory for 1Sat Ordinals SDK",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -20,16 +20,16 @@
|
|
|
20
20
|
"keywords": ["1sat", "bsv", "ordinals", "wallet", "remote"],
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@1sat/wallet": "0.0.
|
|
23
|
+
"@1sat/wallet": "0.0.32"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"@1sat/client": "0.0.
|
|
27
|
-
"@bsv/sdk": "^2.0.
|
|
28
|
-
"@bsv/wallet-toolbox": "^2.
|
|
26
|
+
"@1sat/client": "0.0.17",
|
|
27
|
+
"@bsv/sdk": "^2.0.6",
|
|
28
|
+
"@bsv/wallet-toolbox": "^2.1.8"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@bsv/sdk": "^2.0.
|
|
32
|
-
"@bsv/wallet-toolbox": "^2.
|
|
31
|
+
"@bsv/sdk": "^2.0.6",
|
|
32
|
+
"@bsv/wallet-toolbox": "^2.1.8",
|
|
33
33
|
"typescript": "^5.9.3"
|
|
34
34
|
}
|
|
35
35
|
}
|