/
init.ts
63 lines (51 loc) · 1.68 KB
/
init.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { emptyWallet } from './initializers/emptyWallet';
import { walletFromKey } from './initializers/walletFromKey';
import { walletFromApiUrl } from './initializers/apiWallet';
import { InitLearnCard, EmptyWallet, WalletFromKey, WalletFromVcApi } from 'types/LearnCard';
export * from './initializers/emptyWallet';
export * from './initializers/walletFromKey';
export * from './initializers/apiWallet';
// Overloads (Unfortunately necessary boilerplate 😢)
/**
* Generates an Empty Wallet
*
* @group Init Functions
*/
export function initLearnCard(config?: EmptyWallet['args']): Promise<EmptyWallet['returnValue']>;
/**
* Generates a full wallet from a 32 byte seed
*
* @group Init Functions
*/
export function initLearnCard(config: WalletFromKey['args']): Promise<WalletFromKey['returnValue']>;
/**
* Generates a wallet that can sign VCs/VPs from a VC API
*
* @group Init Functions
*/
export function initLearnCard(
config: WalletFromVcApi['args']
): Promise<WalletFromVcApi['returnValue']>;
// Implementation
/**
* Generates a new LearnCard wallet
*
* @group Init Functions
*/
export async function initLearnCard(
config: InitLearnCard['args'] = {}
): InitLearnCard['returnValue'] {
if ('vcApi' in config) {
const { vcApi, did, ...apiConfig } = config;
return walletFromApiUrl(
typeof vcApi === 'string' ? vcApi : 'https://bridge.learncard.com',
vcApi === true ? 'did:key:z6MkjSz4mYqcn7dePGuktJ5PxecMkXQQHWRg8Lm6okATyFVh' : did,
apiConfig
);
}
if ('seed' in config) {
const { seed, ...keyConfig } = config;
return walletFromKey(seed, keyConfig);
}
return emptyWallet(config);
}