@1sat/wallet-remote 0.0.2

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.
@@ -0,0 +1,39 @@
1
+ import { OneSatServices } from '@1sat/client';
2
+ import { PrivateKey } from '@bsv/sdk';
3
+ import { Wallet, WalletStorageManager } from '@bsv/wallet-toolbox-mobile/out/src/index.client.js';
4
+ type Chain = 'main' | 'test';
5
+ export interface RemoteWalletConfig {
6
+ /** Private key - can be PrivateKey instance, WIF string, or hex string */
7
+ privateKey: PrivateKey | string;
8
+ /** Network: 'main' or 'test' */
9
+ chain: Chain;
10
+ /** Remote storage server URL */
11
+ remoteStorageUrl: string;
12
+ /** Fee model. Default: { model: 'sat/kb', value: 100 } */
13
+ feeModel?: {
14
+ model: 'sat/kb';
15
+ value: number;
16
+ };
17
+ /** Connection timeout in milliseconds. Default: 5000 */
18
+ connectionTimeout?: number;
19
+ }
20
+ export interface RemoteWalletResult {
21
+ /** Wallet instance */
22
+ wallet: Wallet;
23
+ /** 1Sat services for API access */
24
+ services: OneSatServices;
25
+ /** Cleanup function - destroys wallet */
26
+ destroy: () => Promise<void>;
27
+ /** Storage manager (for diagnostics) */
28
+ storage: WalletStorageManager;
29
+ }
30
+ /**
31
+ * Create a wallet that uses a remote storage server as its sole storage.
32
+ *
33
+ * No local storage (IndexedDB/SQLite) is created. No Monitor is started
34
+ * client-side — the server handles transaction lifecycle (broadcasting,
35
+ * proof checking, failure management).
36
+ */
37
+ export declare function createRemoteWallet(config: RemoteWalletConfig): Promise<RemoteWalletResult>;
38
+ export {};
39
+ //# sourceMappingURL=createRemoteWallet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createRemoteWallet.d.ts","sourceRoot":"","sources":["../src/createRemoteWallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAc,UAAU,EAAwB,MAAM,UAAU,CAAA;AAEvE,OAAO,EAGN,MAAM,EACN,oBAAoB,EACpB,MAAM,oDAAoD,CAAA;AAE3D,KAAK,KAAK,GAAG,MAAM,GAAG,MAAM,CAAA;AAM5B,MAAM,WAAW,kBAAkB;IAClC,0EAA0E;IAC1E,UAAU,EAAE,UAAU,GAAG,MAAM,CAAA;IAC/B,gCAAgC;IAChC,KAAK,EAAE,KAAK,CAAA;IACZ,gCAAgC;IAChC,gBAAgB,EAAE,MAAM,CAAA;IACxB,0DAA0D;IAC1D,QAAQ,CAAC,EAAE;QAAE,KAAK,EAAE,QAAQ,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;IAC7C,wDAAwD;IACxD,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAC1B;AAED,MAAM,WAAW,kBAAkB;IAClC,sBAAsB;IACtB,MAAM,EAAE,MAAM,CAAA;IACd,mCAAmC;IACnC,QAAQ,EAAE,cAAc,CAAA;IACxB,yCAAyC;IACzC,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAC5B,wCAAwC;IACxC,OAAO,EAAE,oBAAoB,CAAA;CAC7B;AAwBD;;;;;;GAMG;AACH,wBAAsB,kBAAkB,CACvC,MAAM,EAAE,kBAAkB,GACxB,OAAO,CAAC,kBAAkB,CAAC,CA+D7B"}
@@ -0,0 +1,77 @@
1
+ import { OneSatServices } from '@1sat/client';
2
+ import { KeyDeriver, PrivateKey } from '@bsv/sdk';
3
+ import { Services, StorageClient, Wallet, WalletStorageManager, } from '@bsv/wallet-toolbox-mobile/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 sole storage.
25
+ *
26
+ * No local storage (IndexedDB/SQLite) is created. No Monitor is started
27
+ * client-side — the server handles transaction lifecycle (broadcasting,
28
+ * proof checking, failure management).
29
+ */
30
+ export async function createRemoteWallet(config) {
31
+ const { chain } = config;
32
+ const feeModel = config.feeModel ?? DEFAULT_FEE_MODEL;
33
+ const timeout = config.connectionTimeout ?? DEFAULT_CONNECTION_TIMEOUT;
34
+ const privateKey = parsePrivateKey(config.privateKey);
35
+ const identityPubKey = privateKey.toPublicKey().toString();
36
+ const keyDeriver = new KeyDeriver(privateKey);
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,
50
+ });
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
+ const destroy = async () => {
68
+ await wallet.destroy();
69
+ };
70
+ return {
71
+ wallet,
72
+ services: oneSatServices,
73
+ destroy,
74
+ storage,
75
+ };
76
+ }
77
+ //# sourceMappingURL=createRemoteWallet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createRemoteWallet.js","sourceRoot":"","sources":["../src/createRemoteWallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAwB,MAAM,UAAU,CAAA;AAEvE,OAAO,EACN,QAAQ,EACR,aAAa,EACb,MAAM,EACN,oBAAoB,GACpB,MAAM,oDAAoD,CAAA;AAK3D,MAAM,iBAAiB,GAAG,EAAE,KAAK,EAAE,QAAiB,EAAE,KAAK,EAAE,GAAG,EAAE,CAAA;AAClE,MAAM,0BAA0B,GAAG,IAAI,CAAA;AA0BvC,SAAS,eAAe,CAAC,KAA0B;IAClD,IAAI,KAAK,YAAY,UAAU,EAAE,CAAC;QACjC,OAAO,KAAK,CAAA;IACb,CAAC;IAED,IAAI,qCAAqC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACvD,OAAO,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IACjC,CAAC;IAED,IAAI,mBAAmB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACrC,OAAO,IAAI,UAAU,CAAC,KAAK,CAAC,CAAA;IAC7B,CAAC;IAED,IAAI,CAAC;QACJ,OAAO,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IACjC,CAAC;IAAC,MAAM,CAAC;QACR,MAAM,IAAI,KAAK,CACd,8FAA8F,CAC9F,CAAA;IACF,CAAC;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,IAAI,CAAC;QAClB,OAAO,CAAC,wBAAwB,CAAC,YAAY,CAAC;QAC9C,cAAc;KACd,CAAC,CAAA;IAEF,4EAA4E;IAC5E,oFAAoF;IACpF,MAAM,cAAc,GAAG,YAAY,CAAC,WAAW,EAAE,CAAA;IACjD,IAAI,cAAc,EAAE,kBAAkB,EAAE,CAAC;QACxC,MAAM,OAAO,CAAC,SAAS,CAAC,cAAc,CAAC,kBAAkB,CAAC,CAAA;IAC3D,CAAC;IAED,MAAM,OAAO,GAAG,KAAK,IAAmB,EAAE;QACzC,MAAM,MAAM,CAAC,OAAO,EAAE,CAAA;IACvB,CAAC,CAAA;IAED,OAAO;QACN,MAAM;QACN,QAAQ,EAAE,cAAc;QACxB,OAAO;QACP,OAAO;KACP,CAAA;AACF,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from '@1sat/wallet';
2
+ export { createRemoteWallet } from './createRemoteWallet';
3
+ export type { RemoteWalletConfig, RemoteWalletResult } from './createRemoteWallet';
4
+ export { Services, StorageClient, Wallet, WalletStorageManager, type sdk as walletSdk, } from '@bsv/wallet-toolbox-mobile/out/src/index.client.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAElF,OAAO,EACN,QAAQ,EACR,aAAa,EACb,MAAM,EACN,oBAAoB,EACpB,KAAK,GAAG,IAAI,SAAS,GACrB,MAAM,oDAAoD,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from '@1sat/wallet';
2
+ export { createRemoteWallet } from './createRemoteWallet';
3
+ export { Services, StorageClient, Wallet, WalletStorageManager, } from '@bsv/wallet-toolbox-mobile/out/src/index.client.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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;AAGzD,OAAO,EACN,QAAQ,EACR,aAAa,EACb,MAAM,EACN,oBAAoB,GAEpB,MAAM,oDAAoD,CAAA"}
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@1sat/wallet-remote",
3
+ "version": "0.0.2",
4
+ "description": "Remote-only wallet factory for 1Sat Ordinals SDK",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "scripts": {
18
+ "build": "tsc",
19
+ "dev": "tsc --watch",
20
+ "clean": "rm -rf dist"
21
+ },
22
+ "keywords": [
23
+ "1sat",
24
+ "bsv",
25
+ "ordinals",
26
+ "wallet",
27
+ "remote"
28
+ ],
29
+ "license": "MIT",
30
+ "dependencies": {
31
+ "@1sat/wallet": "^0.0.13"
32
+ },
33
+ "peerDependencies": {
34
+ "@1sat/client": "^0.0.6",
35
+ "@bsv/sdk": "^2.0.1",
36
+ "@bsv/wallet-toolbox-mobile": "npm:@bopen-io/wallet-toolbox-mobile@2.0.5-idb-fix.2"
37
+ },
38
+ "devDependencies": {
39
+ "@bsv/sdk": "^2.0.1",
40
+ "@bsv/wallet-toolbox-mobile": "npm:@bopen-io/wallet-toolbox-mobile@2.0.5-idb-fix.2",
41
+ "typescript": "^5.9.3"
42
+ }
43
+ }