@guveno/wallet-sdk 1.0.0 → 1.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.
- package/README.md +2 -1
- package/dist/api/client.d.ts +3 -17
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +15 -76
- package/dist/api/client.js.map +1 -1
- package/dist/api/types.d.ts +9 -31
- package/dist/api/types.d.ts.map +1 -1
- package/dist/api/types.js.map +1 -1
- package/dist/config/file-store.d.ts +40 -0
- package/dist/config/file-store.d.ts.map +1 -0
- package/dist/config/file-store.js +118 -0
- package/dist/config/file-store.js.map +1 -0
- package/dist/constants.d.ts +8 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +17 -1
- package/dist/constants.js.map +1 -1
- package/dist/crypto/sealed-box.d.ts +7 -0
- package/dist/crypto/sealed-box.d.ts.map +1 -1
- package/dist/crypto/sealed-box.js +36 -1
- package/dist/crypto/sealed-box.js.map +1 -1
- package/dist/crypto/user-keys.d.ts +31 -0
- package/dist/crypto/user-keys.d.ts.map +1 -0
- package/dist/crypto/user-keys.js +36 -0
- package/dist/crypto/user-keys.js.map +1 -0
- package/dist/encryption-session.d.ts +33 -0
- package/dist/encryption-session.d.ts.map +1 -0
- package/dist/encryption-session.js +59 -0
- package/dist/encryption-session.js.map +1 -0
- package/dist/hot-wallet.d.ts +19 -2
- package/dist/hot-wallet.d.ts.map +1 -1
- package/dist/hot-wallet.js +26 -3
- package/dist/hot-wallet.js.map +1 -1
- package/dist/index.d.ts +12 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +1 -177
- package/dist/types.d.ts.map +1 -1
- package/dist/wallet-service.d.ts +75 -0
- package/dist/wallet-service.d.ts.map +1 -0
- package/dist/wallet-service.js +113 -0
- package/dist/wallet-service.js.map +1 -0
- package/package.json +2 -9
- package/dist/manager.d.ts +0 -28
- package/dist/manager.d.ts.map +0 -1
- package/dist/manager.js +0 -499
- package/dist/manager.js.map +0 -1
- package/dist/session/file-store.d.ts +0 -10
- package/dist/session/file-store.d.ts.map +0 -1
- package/dist/session/file-store.js +0 -88
- package/dist/session/file-store.js.map +0 -1
- package/dist/storage/crypto.d.ts +0 -7
- package/dist/storage/crypto.d.ts.map +0 -1
- package/dist/storage/crypto.js +0 -80
- package/dist/storage/crypto.js.map +0 -1
- package/dist/storage/file-store.d.ts +0 -21
- package/dist/storage/file-store.d.ts.map +0 -1
- package/dist/storage/file-store.js +0 -219
- package/dist/storage/file-store.js.map +0 -1
package/dist/types.d.ts
CHANGED
|
@@ -1,187 +1,11 @@
|
|
|
1
1
|
export type MnemonicWordCount = 12 | 24;
|
|
2
2
|
export type SupportedChain = 'ethereum' | 'bitcoin' | 'xrp' | 'polkadot';
|
|
3
3
|
export type SupportedNetwork = 'mainnet' | 'sepolia' | 'testnet' | 'paseo';
|
|
4
|
-
|
|
5
|
-
enabled: boolean;
|
|
6
|
-
algorithm: 'aes-256-gcm' | null;
|
|
7
|
-
kdf: 'scrypt' | null;
|
|
8
|
-
}
|
|
9
|
-
export interface DerivedAccount {
|
|
10
|
-
chain: SupportedChain;
|
|
11
|
-
network: SupportedNetwork;
|
|
12
|
-
address: string;
|
|
13
|
-
derivationPath: string;
|
|
14
|
-
index: number;
|
|
15
|
-
label: string | null;
|
|
16
|
-
createdAt: string;
|
|
17
|
-
updatedAt: string;
|
|
18
|
-
}
|
|
19
|
-
export interface WalletGroupSummary {
|
|
20
|
-
id: string;
|
|
21
|
-
keyId: string;
|
|
22
|
-
keyFingerprint: string;
|
|
23
|
-
name: string;
|
|
24
|
-
chain: SupportedChain;
|
|
25
|
-
network: SupportedNetwork;
|
|
26
|
-
firstAddress: string;
|
|
27
|
-
addressCount: number;
|
|
28
|
-
createdAt: string;
|
|
29
|
-
updatedAt: string;
|
|
30
|
-
encryption: EncryptionStatus;
|
|
31
|
-
}
|
|
32
|
-
export interface WalletGroup extends WalletGroupSummary {
|
|
33
|
-
accounts: DerivedAccount[];
|
|
34
|
-
}
|
|
35
|
-
export interface WalletKeySummary {
|
|
36
|
-
id: string;
|
|
37
|
-
fingerprint: string;
|
|
38
|
-
walletCount: number;
|
|
39
|
-
createdAt: string;
|
|
40
|
-
updatedAt: string;
|
|
41
|
-
encryption: EncryptionStatus;
|
|
42
|
-
}
|
|
43
|
-
export interface WalletGroupMetadataExport {
|
|
44
|
-
version: number;
|
|
45
|
-
exportedAt: string;
|
|
46
|
-
key: WalletKeySummary;
|
|
47
|
-
wallet: WalletGroupSummary;
|
|
48
|
-
addresses: DerivedAccount[];
|
|
49
|
-
}
|
|
50
|
-
export interface CreateWalletGroupOptions {
|
|
51
|
-
name: string;
|
|
52
|
-
chain?: SupportedChain;
|
|
53
|
-
network?: SupportedNetwork;
|
|
54
|
-
words?: MnemonicWordCount;
|
|
55
|
-
accountLabel?: string | null;
|
|
56
|
-
encryptionPassword?: string;
|
|
57
|
-
}
|
|
58
|
-
export interface CreateWalletGroupResult {
|
|
59
|
-
group: WalletGroup;
|
|
60
|
-
firstAccount: DerivedAccount;
|
|
61
|
-
mnemonic: string;
|
|
62
|
-
}
|
|
63
|
-
export interface ImportWalletGroupOptions {
|
|
64
|
-
name: string;
|
|
65
|
-
chain?: SupportedChain;
|
|
66
|
-
network?: SupportedNetwork;
|
|
67
|
-
mnemonic: string;
|
|
68
|
-
accountLabel?: string | null;
|
|
69
|
-
encryptionPassword?: string;
|
|
70
|
-
}
|
|
71
|
-
export interface ImportWalletGroupResult {
|
|
72
|
-
group: WalletGroup;
|
|
73
|
-
account: DerivedAccount;
|
|
74
|
-
reusedExistingGroup: boolean;
|
|
75
|
-
}
|
|
76
|
-
export interface DeriveAddressOptions {
|
|
77
|
-
group: string;
|
|
78
|
-
label?: string | null;
|
|
79
|
-
encryptionPassword?: string;
|
|
80
|
-
}
|
|
81
|
-
export interface LabelAccountOptions {
|
|
82
|
-
group: string;
|
|
83
|
-
index: number;
|
|
84
|
-
label?: string | null;
|
|
85
|
-
}
|
|
86
|
-
export interface WalletManagerOptions {
|
|
87
|
-
storageDir?: string;
|
|
88
|
-
store?: WalletStore;
|
|
89
|
-
}
|
|
90
|
-
export interface EncryptedSecretEnvelope {
|
|
91
|
-
algorithm: 'aes-256-gcm';
|
|
92
|
-
kdf: 'scrypt';
|
|
93
|
-
salt: string;
|
|
94
|
-
iv: string;
|
|
95
|
-
tag: string;
|
|
96
|
-
ciphertext: string;
|
|
97
|
-
kdfParams: {
|
|
98
|
-
cost: number;
|
|
99
|
-
blockSize: number;
|
|
100
|
-
parallelization: number;
|
|
101
|
-
keyLength: number;
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
export interface EncryptedStoredSecretRecord {
|
|
105
|
-
keyId: string;
|
|
106
|
-
type: 'encrypted';
|
|
107
|
-
envelope: EncryptedSecretEnvelope;
|
|
108
|
-
}
|
|
109
|
-
export type StoredSecretRecord = EncryptedStoredSecretRecord;
|
|
110
|
-
export interface StoredWalletKey {
|
|
111
|
-
id: string;
|
|
112
|
-
fingerprint: string;
|
|
113
|
-
encryption: EncryptionStatus;
|
|
114
|
-
createdAt: string;
|
|
115
|
-
updatedAt: string;
|
|
116
|
-
}
|
|
117
|
-
export interface StoredWallet {
|
|
118
|
-
id: string;
|
|
119
|
-
keyId: string;
|
|
120
|
-
name: string;
|
|
121
|
-
chain: SupportedChain;
|
|
122
|
-
network: SupportedNetwork;
|
|
123
|
-
nextAccountIndex: number;
|
|
124
|
-
createdAt: string;
|
|
125
|
-
updatedAt: string;
|
|
126
|
-
}
|
|
127
|
-
export interface StoredWalletAddress {
|
|
128
|
-
id: string;
|
|
129
|
-
walletId: string;
|
|
130
|
-
chain: SupportedChain;
|
|
131
|
-
network: SupportedNetwork;
|
|
132
|
-
address: string;
|
|
133
|
-
derivationPath: string;
|
|
134
|
-
index: number;
|
|
135
|
-
label: string | null;
|
|
136
|
-
createdAt: string;
|
|
137
|
-
updatedAt: string;
|
|
138
|
-
}
|
|
139
|
-
export interface StoredMetadataFile {
|
|
140
|
-
version: number;
|
|
141
|
-
keys: StoredWalletKey[];
|
|
142
|
-
wallets: StoredWallet[];
|
|
143
|
-
addresses: StoredWalletAddress[];
|
|
144
|
-
}
|
|
145
|
-
export interface StoredSecretsFile {
|
|
146
|
-
version: number;
|
|
147
|
-
keys: StoredSecretRecord[];
|
|
148
|
-
}
|
|
149
|
-
export interface StorageState {
|
|
150
|
-
metadata: StoredMetadataFile;
|
|
151
|
-
secrets: StoredSecretsFile;
|
|
152
|
-
}
|
|
153
|
-
export interface WalletGroupMetadataJson {
|
|
154
|
-
version: number;
|
|
155
|
-
key: StoredWalletKey;
|
|
156
|
-
wallet: StoredWallet;
|
|
157
|
-
addresses: StoredWalletAddress[];
|
|
158
|
-
}
|
|
159
|
-
export interface WalletGroupSecretsJson {
|
|
160
|
-
version: number;
|
|
161
|
-
secret: EncryptedStoredSecretRecord;
|
|
162
|
-
}
|
|
4
|
+
/** A derived address pushed to the server as part of a wallet record. */
|
|
163
5
|
export interface WalletRecordAddressExport {
|
|
164
6
|
address: string;
|
|
165
7
|
derivationPath: string;
|
|
166
8
|
accountIndex: number;
|
|
167
9
|
label: string | null;
|
|
168
10
|
}
|
|
169
|
-
export interface WalletGroupRecordExport {
|
|
170
|
-
groupName: string;
|
|
171
|
-
chain: SupportedChain;
|
|
172
|
-
keyFingerprint: string;
|
|
173
|
-
metadataJson: WalletGroupMetadataJson;
|
|
174
|
-
secretsJson: WalletGroupSecretsJson;
|
|
175
|
-
addresses: WalletRecordAddressExport[];
|
|
176
|
-
}
|
|
177
|
-
export interface WalletStore {
|
|
178
|
-
read(): Promise<StorageState>;
|
|
179
|
-
mutate<T>(mutator: (state: StorageState) => Promise<{
|
|
180
|
-
result: T;
|
|
181
|
-
state: StorageState;
|
|
182
|
-
}> | {
|
|
183
|
-
result: T;
|
|
184
|
-
state: StorageState;
|
|
185
|
-
}): Promise<T>;
|
|
186
|
-
}
|
|
187
11
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG,EAAE,GAAG,EAAE,CAAC;AACxC,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,SAAS,GAAG,KAAK,GAAG,UAAU,CAAC;AACzE,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC;AAE3E,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG,EAAE,GAAG,EAAE,CAAC;AACxC,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,SAAS,GAAG,KAAK,GAAG,UAAU,CAAC;AACzE,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC;AAE3E,yEAAyE;AACzE,MAAM,WAAW,yBAAyB;IACxC,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { EncryptionSession } from './encryption-session.js';
|
|
2
|
+
import type { GuvenoApiClient } from './api/client.js';
|
|
3
|
+
import type { ApiPageInfo, ApiWalletAddress, ApiWalletDetail, ApiWalletSummary, ListApiAddressOptions, ListApiWalletOptions } from './api/types.js';
|
|
4
|
+
import type { MnemonicWordCount, SupportedChain, SupportedNetwork, WalletRecordAddressExport } from './types.js';
|
|
5
|
+
export interface WalletServiceOptions {
|
|
6
|
+
/** API client configured with a `gv_live_...` key. */
|
|
7
|
+
api: GuvenoApiClient;
|
|
8
|
+
/** Unlocked encryption session used to seal/unseal wallet secrets. */
|
|
9
|
+
session: EncryptionSession;
|
|
10
|
+
}
|
|
11
|
+
export interface CreateWalletOptions {
|
|
12
|
+
name: string;
|
|
13
|
+
chain: SupportedChain;
|
|
14
|
+
network: SupportedNetwork;
|
|
15
|
+
/** Recovery-phrase length. Defaults to 12. */
|
|
16
|
+
words?: MnemonicWordCount;
|
|
17
|
+
/** Label for the first derived address. */
|
|
18
|
+
label?: string | null;
|
|
19
|
+
}
|
|
20
|
+
export interface CreateWalletResult {
|
|
21
|
+
wallet: ApiWalletDetail;
|
|
22
|
+
firstAddress: WalletRecordAddressExport;
|
|
23
|
+
/**
|
|
24
|
+
* The generated recovery phrase. Surface it to the user once for backup; it is
|
|
25
|
+
* also recoverable later from the server (sealed) via {@link WalletService.revealMnemonic}.
|
|
26
|
+
*/
|
|
27
|
+
mnemonic: string;
|
|
28
|
+
}
|
|
29
|
+
export interface ImportWalletOptions {
|
|
30
|
+
name: string;
|
|
31
|
+
chain: SupportedChain;
|
|
32
|
+
network: SupportedNetwork;
|
|
33
|
+
mnemonic: string;
|
|
34
|
+
label?: string | null;
|
|
35
|
+
}
|
|
36
|
+
export interface DeriveAddressOptions {
|
|
37
|
+
label?: string | null;
|
|
38
|
+
}
|
|
39
|
+
export interface DeriveAddressResult {
|
|
40
|
+
address: WalletRecordAddressExport;
|
|
41
|
+
wallet: ApiWalletDetail;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Server-source-of-truth wallet manager. Mirrors how the web client works: the
|
|
45
|
+
* recovery phrase is generated locally, sealed to the user's encryption key, and
|
|
46
|
+
* pushed to the server; it is re-fetched and unsealed on demand to derive
|
|
47
|
+
* addresses or reveal the phrase. Nothing authoritative is stored on disk — the
|
|
48
|
+
* server holds the wallet, its addresses, and the (sealed) secret.
|
|
49
|
+
*/
|
|
50
|
+
export declare class WalletService {
|
|
51
|
+
private readonly api;
|
|
52
|
+
private readonly session;
|
|
53
|
+
constructor(options: WalletServiceOptions);
|
|
54
|
+
/** Generate a new wallet, derive its first address, and register it on the server. */
|
|
55
|
+
createWallet(options: CreateWalletOptions): Promise<CreateWalletResult>;
|
|
56
|
+
/** Import an existing recovery phrase as a new server-side wallet. */
|
|
57
|
+
importWallet(options: ImportWalletOptions): Promise<ApiWalletDetail>;
|
|
58
|
+
/**
|
|
59
|
+
* Derive the next address for a wallet and register it on the server. Uses the
|
|
60
|
+
* server's `nextAccountIndex` as the source of truth, so concurrent machines
|
|
61
|
+
* stay consistent. Returns the new address and the refreshed wallet detail.
|
|
62
|
+
*/
|
|
63
|
+
deriveAddress(walletId: number, options?: DeriveAddressOptions): Promise<DeriveAddressResult>;
|
|
64
|
+
/** Fetch and decrypt a wallet's recovery phrase from the server (audited server-side). */
|
|
65
|
+
revealMnemonic(walletId: number): Promise<string>;
|
|
66
|
+
listWallets(options?: ListApiWalletOptions): Promise<ApiWalletSummary[]>;
|
|
67
|
+
getWallet(walletId: number): Promise<ApiWalletDetail>;
|
|
68
|
+
listAddresses(walletId: number, options?: ListApiAddressOptions): Promise<{
|
|
69
|
+
items: ApiWalletAddress[];
|
|
70
|
+
pageInfo: ApiPageInfo;
|
|
71
|
+
}>;
|
|
72
|
+
private pushNewWallet;
|
|
73
|
+
private revealMnemonicForWallet;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=wallet-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet-service.d.ts","sourceRoot":"","sources":["../src/wallet-service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,qBAAqB,EACrB,oBAAoB,EACrB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,gBAAgB,EAAE,yBAAyB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AC;IAgB1E;;;;OAIG;IACG,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,GAAE,oBAAyB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAoBvG,0FAA0F;IACpF,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIjD,WAAW,CAAC,OAAO,GAAE,oBAAyB,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAI5E,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAIrD,aAAa,CACjB,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC;QAAE,KAAK,EAAE,gBAAgB,EAAE,CAAC;QAAC,QAAQ,EAAE,WAAW,CAAA;KAAE,CAAC;YAIlD,aAAa;YA2Bb,uBAAuB;CAItC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { assertSupportedChain, assertSupportedNetwork } from './chains.js';
|
|
2
|
+
import { deriveAddress } from './derivation.js';
|
|
3
|
+
import { assertValidMnemonic, fingerprintMnemonic, generateRandomMnemonic } from './mnemonic.js';
|
|
4
|
+
function normalizeLabel(label) {
|
|
5
|
+
if (label == null) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
const normalized = label.trim();
|
|
9
|
+
return normalized.length === 0 ? null : normalized;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Server-source-of-truth wallet manager. Mirrors how the web client works: the
|
|
13
|
+
* recovery phrase is generated locally, sealed to the user's encryption key, and
|
|
14
|
+
* pushed to the server; it is re-fetched and unsealed on demand to derive
|
|
15
|
+
* addresses or reveal the phrase. Nothing authoritative is stored on disk — the
|
|
16
|
+
* server holds the wallet, its addresses, and the (sealed) secret.
|
|
17
|
+
*/
|
|
18
|
+
export class WalletService {
|
|
19
|
+
api;
|
|
20
|
+
session;
|
|
21
|
+
constructor(options) {
|
|
22
|
+
this.api = options.api;
|
|
23
|
+
this.session = options.session;
|
|
24
|
+
}
|
|
25
|
+
/** Generate a new wallet, derive its first address, and register it on the server. */
|
|
26
|
+
async createWallet(options) {
|
|
27
|
+
const chain = assertSupportedChain(options.chain);
|
|
28
|
+
const network = assertSupportedNetwork(options.network);
|
|
29
|
+
const words = options.words ?? 12;
|
|
30
|
+
const mnemonic = generateRandomMnemonic(words);
|
|
31
|
+
const { wallet, firstAddress } = await this.pushNewWallet({
|
|
32
|
+
name: options.name,
|
|
33
|
+
chain,
|
|
34
|
+
network,
|
|
35
|
+
mnemonic,
|
|
36
|
+
label: options.label
|
|
37
|
+
});
|
|
38
|
+
return { wallet, firstAddress, mnemonic };
|
|
39
|
+
}
|
|
40
|
+
/** Import an existing recovery phrase as a new server-side wallet. */
|
|
41
|
+
async importWallet(options) {
|
|
42
|
+
const chain = assertSupportedChain(options.chain);
|
|
43
|
+
const network = assertSupportedNetwork(options.network);
|
|
44
|
+
const mnemonic = assertValidMnemonic(options.mnemonic);
|
|
45
|
+
const { wallet } = await this.pushNewWallet({
|
|
46
|
+
name: options.name,
|
|
47
|
+
chain,
|
|
48
|
+
network,
|
|
49
|
+
mnemonic,
|
|
50
|
+
label: options.label
|
|
51
|
+
});
|
|
52
|
+
return wallet;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Derive the next address for a wallet and register it on the server. Uses the
|
|
56
|
+
* server's `nextAccountIndex` as the source of truth, so concurrent machines
|
|
57
|
+
* stay consistent. Returns the new address and the refreshed wallet detail.
|
|
58
|
+
*/
|
|
59
|
+
async deriveAddress(walletId, options = {}) {
|
|
60
|
+
const detail = await this.api.getWalletRecord(walletId);
|
|
61
|
+
const mnemonic = await this.revealMnemonicForWallet(walletId);
|
|
62
|
+
const derived = await deriveAddress(mnemonic, detail.nextAccountIndex, {
|
|
63
|
+
chain: detail.chain,
|
|
64
|
+
network: detail.network
|
|
65
|
+
});
|
|
66
|
+
const address = {
|
|
67
|
+
address: derived.address,
|
|
68
|
+
derivationPath: derived.derivationPath,
|
|
69
|
+
accountIndex: derived.index,
|
|
70
|
+
label: normalizeLabel(options.label)
|
|
71
|
+
};
|
|
72
|
+
// PATCH is additive — sending only the new address registers it without
|
|
73
|
+
// disturbing the existing ones.
|
|
74
|
+
const wallet = await this.api.updateWalletRecord(walletId, { addresses: [address] });
|
|
75
|
+
return { address, wallet };
|
|
76
|
+
}
|
|
77
|
+
/** Fetch and decrypt a wallet's recovery phrase from the server (audited server-side). */
|
|
78
|
+
async revealMnemonic(walletId) {
|
|
79
|
+
return this.revealMnemonicForWallet(walletId);
|
|
80
|
+
}
|
|
81
|
+
async listWallets(options = {}) {
|
|
82
|
+
return this.api.listWalletRecords(options);
|
|
83
|
+
}
|
|
84
|
+
async getWallet(walletId) {
|
|
85
|
+
return this.api.getWalletRecord(walletId);
|
|
86
|
+
}
|
|
87
|
+
async listAddresses(walletId, options = {}) {
|
|
88
|
+
return this.api.listWalletAddresses(walletId, options);
|
|
89
|
+
}
|
|
90
|
+
async pushNewWallet(input) {
|
|
91
|
+
const derived = await deriveAddress(input.mnemonic, 0, { chain: input.chain, network: input.network });
|
|
92
|
+
const firstAddress = {
|
|
93
|
+
address: derived.address,
|
|
94
|
+
derivationPath: derived.derivationPath,
|
|
95
|
+
accountIndex: derived.index,
|
|
96
|
+
label: normalizeLabel(input.label)
|
|
97
|
+
};
|
|
98
|
+
const wallet = await this.api.createWalletRecord({
|
|
99
|
+
name: input.name,
|
|
100
|
+
chain: input.chain,
|
|
101
|
+
network: input.network,
|
|
102
|
+
keyFingerprint: fingerprintMnemonic(input.mnemonic),
|
|
103
|
+
encryptedSecretJson: this.session.seal(input.mnemonic),
|
|
104
|
+
addresses: [firstAddress]
|
|
105
|
+
});
|
|
106
|
+
return { wallet, firstAddress };
|
|
107
|
+
}
|
|
108
|
+
async revealMnemonicForWallet(walletId) {
|
|
109
|
+
const secret = await this.api.getWalletKeySecret(walletId);
|
|
110
|
+
return this.session.unsealRecord(secret.encryptedSecretJson);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=wallet-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet-service.js","sourceRoot":"","sources":["../src/wallet-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAwDjG,SAAS,cAAc,CAAC,KAAgC;IACtD,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;QAClB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAChC,OAAO,UAAU,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC;AACrD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,OAAO,aAAa;IACP,GAAG,CAAkB;IACrB,OAAO,CAAoB;IAE5C,YAAY,OAA6B;QACvC,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IACjC,CAAC;IAED,sFAAsF;IACtF,KAAK,CAAC,YAAY,CAAC,OAA4B;QAC7C,MAAM,KAAK,GAAG,oBAAoB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAClD,MAAM,OAAO,GAAG,sBAAsB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACxD,MAAM,KAAK,GAAsB,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC;QACrD,MAAM,QAAQ,GAAG,sBAAsB,CAAC,KAAK,CAAC,CAAC;QAE/C,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,IAAI,CA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AM,MAAM,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,kBAAkB,CAAC;YAC/C,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,cAAc,EAAE,mBAAmB,CAAC,KAAK,CAAC,QAAQ,CAAC;YACnD,mBAAmB,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAuC;YAC5F,SAAS,EAAE,CAAC,YAAY,CAAC;SAC1B,CAAC,CAAC;QAEH,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC;IAClC,CAAC;IAEO,KAAK,CAAC,uBAAuB,CAAC,QAAgB;QACpD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC;QAC3D,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC;IAC/D,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guveno/wallet-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Add secure crypto custody to your app in minutes — create and manage multi-chain wallets, automate withdrawals, and receive real-time webhooks for Bitcoin, Ethereum, XRP, and Polkadot. Built for exchanges, fintechs, and platforms.",
|
|
5
5
|
"author": "Guveno LLC",
|
|
6
6
|
"license": "MIT",
|
|
@@ -26,14 +26,7 @@
|
|
|
26
26
|
"crypto",
|
|
27
27
|
"custody"
|
|
28
28
|
],
|
|
29
|
-
"
|
|
30
|
-
"type": "git",
|
|
31
|
-
"url": "git+https://github.com/hollaex/guveno-sdk.git"
|
|
32
|
-
},
|
|
33
|
-
"homepage": "https://github.com/hollaex/guveno-sdk#readme",
|
|
34
|
-
"bugs": {
|
|
35
|
-
"url": "https://github.com/hollaex/guveno-sdk/issues"
|
|
36
|
-
},
|
|
29
|
+
"homepage": "https://guveno.com",
|
|
37
30
|
"files": [
|
|
38
31
|
"dist",
|
|
39
32
|
"README.md",
|
package/dist/manager.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { CreateApiWalletInput } from './api/types.js';
|
|
2
|
-
import type { CreateWalletGroupOptions, CreateWalletGroupResult, DeriveAddressOptions, DerivedAccount, ImportWalletGroupOptions, ImportWalletGroupResult, LabelAccountOptions, WalletGroup, WalletGroupMetadataExport, WalletGroupRecordExport, WalletGroupSummary, WalletManagerOptions, WalletStore } from './types.js';
|
|
3
|
-
type EncryptionPasswordCarrier = {
|
|
4
|
-
encryptionPassword?: string;
|
|
5
|
-
};
|
|
6
|
-
export declare class WalletManager {
|
|
7
|
-
readonly store: WalletStore;
|
|
8
|
-
constructor(options?: WalletManagerOptions);
|
|
9
|
-
createWalletGroup(options: CreateWalletGroupOptions): Promise<CreateWalletGroupResult>;
|
|
10
|
-
importWalletGroup(options: ImportWalletGroupOptions): Promise<ImportWalletGroupResult>;
|
|
11
|
-
deriveAddress(options: DeriveAddressOptions): Promise<DerivedAccount>;
|
|
12
|
-
listWalletGroups(): Promise<WalletGroupSummary[]>;
|
|
13
|
-
getWalletGroup(groupIdentifier: string): Promise<WalletGroup>;
|
|
14
|
-
getFirstAddress(groupIdentifier: string): Promise<DerivedAccount>;
|
|
15
|
-
listDerivedAccounts(groupIdentifier: string): Promise<DerivedAccount[]>;
|
|
16
|
-
renameWalletGroup(groupIdentifier: string, newName: string): Promise<WalletGroup>;
|
|
17
|
-
labelAccount(options: LabelAccountOptions): Promise<DerivedAccount>;
|
|
18
|
-
exportWalletGroupMetadata(groupIdentifier: string): Promise<WalletGroupMetadataExport>;
|
|
19
|
-
exportWalletGroupRecord(groupIdentifier: string, options?: EncryptionPasswordCarrier): Promise<WalletGroupRecordExport>;
|
|
20
|
-
exportWalletForApi(groupIdentifier: string, options: EncryptionPasswordCarrier & {
|
|
21
|
-
recipientPublicKey: string;
|
|
22
|
-
}): Promise<CreateApiWalletInput>;
|
|
23
|
-
revealMnemonic(groupIdentifier: string, encryptionPassword?: string): Promise<string>;
|
|
24
|
-
}
|
|
25
|
-
export declare class EthereumWalletManager extends WalletManager {
|
|
26
|
-
}
|
|
27
|
-
export {};
|
|
28
|
-
//# sourceMappingURL=manager.d.ts.map
|
package/dist/manager.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../src/manager.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,KAAK,EACV,wBAAwB,EACxB,uBAAuB,EACvB,oBAAoB,EACpB,cAAc,EAEd,wBAAwB,EACxB,uBAAuB,EACvB,mBAAmB,EAQnB,WAAW,EACX,yBAAyB,EACzB,uBAAuB,EACvB,kBAAkB,EAElB,oBAAoB,EACpB,WAAW,EACZ,MAAM,YAAY,CAAC;AAgKpB,KAAK,yBAAyB,GAAG;IAC/B,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B,CAAC;AA+GF,qBAAa,aAAa;IACxB,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;gBAEhB,OAAO,GAAE,oBAAyB;IAIxC,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,uBAAuB,CAAC;IAyDtF,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,uBAAuB,CAAC;IA6GtF,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,cAAc,CAAC;IAiCrE,gBAAgB,IAAI,OAAO,CAAC,kBAAkB,EAAE,CAAC;IASjD,cAAc,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAW7D,eAAe,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,cAA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