@bitgo-beta/key-card 0.0.1-beta.9 → 0.1.2-alpha.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bitgo-beta/key-card",
3
- "version": "0.0.1-beta.9",
3
+ "version": "0.1.2-alpha.0",
4
4
  "description": "key card generator for BitGo wallets",
5
5
  "main": "./dist/src/index.js",
6
6
  "types": "./dist/src/index.d.ts",
@@ -32,10 +32,5 @@
32
32
  ".ts"
33
33
  ]
34
34
  },
35
- "dependencies": {
36
- "@bitgo-beta/sdk-api": "1.1.1-beta.134",
37
- "@bitgo-beta/sdk-core": "1.1.1-beta.134",
38
- "@bitgo-beta/statics": "7.0.1-beta.134"
39
- },
40
- "gitHead": "2a8f20b3ca0aa4498def41930539fce61847f764"
35
+ "gitHead": "54b088879459721d54764501dcd2376c59b8450f"
41
36
  }
package/tsconfig.json CHANGED
@@ -5,16 +5,5 @@
5
5
  "rootDir": "./"
6
6
  },
7
7
  "include": ["src/**/*"],
8
- "exclude": ["node_modules"],
9
- "references": [
10
- {
11
- "path": "../statics"
12
- },
13
- {
14
- "path": "../sdk-api"
15
- },
16
- {
17
- "path": "../sdk-core"
18
- }
19
- ]
8
+ "exclude": ["node_modules"]
20
9
  }
@@ -1,197 +0,0 @@
1
- import { BaseCoin } from '@bitgo-beta/statics';
2
- import { Keychain } from '@bitgo-beta/sdk-core';
3
- import { encrypt } from '@bitgo-beta/sdk-api';
4
- import * as assert from 'assert';
5
-
6
- export interface GenerateQrDataParams {
7
- // The backup keychain as it is returned from the BitGo API upon creation
8
- backupKeychain: Keychain,
9
- // The 3rd party provider of the backup key if neither the user nor BitGo stores it
10
- backupKeyProvider?: string;
11
- // The key id of the backup key, only used for cold keys
12
- backupMasterKey?: string;
13
- // The BitGo keychain as it is returned from the BitGo API upon creation
14
- bitgoKeychain: Keychain,
15
- // The coin of the wallet that was/ is about to be created
16
- coin: Readonly<BaseCoin>;
17
- // A code that can be used to encrypt the wallet password to.
18
- // If both the passphrase and passcodeEncryptionCode are passed, then this code encrypts the passphrase with the
19
- // passcodeEncryptionCode and puts the result into Box D. Allows recoveries of the wallet password.
20
- passcodeEncryptionCode?: string;
21
- // The wallet password
22
- // If both the passphrase and passcodeEncryptionCode are passed, then this code encrypts the passphrase with the
23
- // passcodeEncryptionCode and puts the result into Box D. Allows recoveries of the wallet password.
24
- passphrase?: string;
25
- // The user keychain as it is returned from the BitGo API upon creation
26
- userKeychain: Keychain;
27
- // The key id of the user key, only used for cold keys
28
- userMasterKey?: string;
29
- }
30
-
31
- interface QrDataEntry {
32
- data: string;
33
- description: string;
34
- image: string;
35
- title: string;
36
- publicMasterKey?: string;
37
- }
38
-
39
- export interface QrData {
40
- backup?: QrDataEntry;
41
- bitgo?: QrDataEntry;
42
- passcode?: QrDataEntry;
43
- user: QrDataEntry;
44
- }
45
-
46
- function getPubFromKey(key: Keychain): string | undefined {
47
- switch (key.type) {
48
- case 'blsdkg':
49
- return key.commonPub;
50
- case 'tss':
51
- return key.commonKeychain;
52
- case 'independent':
53
- return key.pub;
54
- }
55
- }
56
-
57
- function generateUserQrData(userKeychain: Keychain, userMasterKey?: string): QrDataEntry {
58
- if (userKeychain.encryptedPrv) {
59
- return {
60
- title: 'A: User Key',
61
- image: '.qrEncryptedUserKey',
62
- description: 'This is your private key, encrypted with your wallet password.',
63
- data: userKeychain.encryptedPrv,
64
- };
65
- }
66
-
67
- const pub = getPubFromKey(userKeychain);
68
- assert(pub);
69
-
70
- return {
71
- title: 'A: Provided User Key',
72
- image: '.qrPublicUserKey',
73
- description: 'This is the public key you provided for your wallet.',
74
- data: pub,
75
- publicMasterKey: userMasterKey,
76
- };
77
- }
78
-
79
- function generateBackupQrData(coin: Readonly<BaseCoin>, backupKeychain: Keychain, {
80
- backupKeyProvider,
81
- backupMasterKey,
82
- }: {
83
- backupKeyProvider?: string;
84
- backupMasterKey?: string;
85
- } = {}): QrDataEntry {
86
- const title = 'B: Backup Key';
87
- if (backupKeychain.encryptedPrv) {
88
- return {
89
- title,
90
- image: '.qrEncryptedBackupKey',
91
- description: 'This is your backup private key, encrypted with your wallet password.',
92
- data: backupKeychain.encryptedPrv,
93
- };
94
- }
95
-
96
- if (backupKeyProvider === 'BitGo Trust' && backupKeychain.type === 'tss') {
97
- const userToBackupShare = backupKeychain.keyShares?.find((keyShare) => keyShare.from === 'user' && keyShare.to === 'backup');
98
- assert(userToBackupShare);
99
- return {
100
- title: 'B: User To Backup Key Share',
101
- image: '.qrUserToBackupKeyShare',
102
- description: `This is the key share from you for ${backupKeyProvider}. If BitGo Inc goes out of business,` +
103
- `\r\ncontact ${backupKeyProvider} and they will help you recover your funds.`,
104
- data: JSON.stringify(userToBackupShare),
105
- };
106
- }
107
-
108
- const pub = getPubFromKey(backupKeychain);
109
- assert(pub);
110
-
111
- if (backupKeyProvider) {
112
- return {
113
- title: 'B: Backup Key',
114
- image: '.qrPublicBackupKey',
115
- description: `This is the public key held at ${backupKeyProvider}, an ${coin.name} recovery service. ` +
116
- `If you lose\r\nyour key, ${backupKeyProvider} will be able to sign transactions to recover funds.`,
117
- data: pub,
118
- };
119
- }
120
-
121
- return {
122
- title: 'B: Provided Backup Key',
123
- image: '.qrEncryptedUserProvidedXpub',
124
- description: 'This is the public key you provided for your wallet.',
125
- data: pub,
126
- publicMasterKey: backupMasterKey,
127
- };
128
- }
129
-
130
- function generateBitGoQrData(bitgoKeychain: Keychain, {
131
- backupKeychain,
132
- backupKeyProvider,
133
- }: {
134
- backupKeychain?: Keychain,
135
- backupKeyProvider?: string;
136
- }): QrDataEntry {
137
- if (backupKeyProvider === 'BitGo Trust' && backupKeychain?.type === 'tss') {
138
- const bitgoToBackupShare = backupKeychain.keyShares?.find((keyShare) => keyShare.from === 'bitgo' && keyShare.to === 'backup');
139
- assert(bitgoToBackupShare);
140
- return {
141
- title: 'C: BitGo To Backup Key Share',
142
- image: '.qrBitGoToBackupKeyShare',
143
- description: `This is the key share from BitGo Inc for ${backupKeyProvider}. If BitGo Inc goes out of business,` +
144
- `\r\ncontact ${backupKeyProvider} and they will help you recover your funds.`,
145
- data: JSON.stringify(bitgoToBackupShare),
146
- };
147
- }
148
-
149
- const bitgoData = getPubFromKey(bitgoKeychain);
150
- assert(bitgoData);
151
-
152
- return {
153
- title: 'C: BitGo Public Key',
154
- image: '.qrBitgoKey',
155
- description:
156
- 'This is the public part of the key that BitGo will use to ' +
157
- 'co-sign transactions\r\nwith you on your wallet.',
158
- data: bitgoData,
159
- };
160
- }
161
-
162
- export function generateQrData({
163
- backupKeychain,
164
- backupKeyProvider,
165
- backupMasterKey,
166
- bitgoKeychain,
167
- coin,
168
- passcodeEncryptionCode,
169
- passphrase,
170
- userKeychain,
171
- userMasterKey,
172
- }: GenerateQrDataParams): QrData {
173
- const qrData: QrData = {
174
- user: generateUserQrData(userKeychain, userMasterKey),
175
- backup: generateBackupQrData(coin, backupKeychain, {
176
- backupKeyProvider,
177
- backupMasterKey,
178
- }),
179
- bitgo: generateBitGoQrData(bitgoKeychain, {
180
- backupKeychain,
181
- backupKeyProvider,
182
- }),
183
- };
184
-
185
- if (passphrase && passcodeEncryptionCode) {
186
- const encryptedWalletPasscode = encrypt(passcodeEncryptionCode, passphrase);
187
-
188
- qrData.passcode = {
189
- title: 'D: Encrypted wallet Password',
190
- image: '.qrEncryptedWalletPasscode',
191
- description: 'This is the wallet password, encrypted client-side with a key held by\r\nBitGo.',
192
- data: encryptedWalletPasscode,
193
- };
194
- }
195
-
196
- return qrData;
197
- }
@@ -1,220 +0,0 @@
1
- import * as assert from 'assert';
2
- import * as should from 'should';
3
- import { generateQrData } from '../../src/generateQrData';
4
- import { decrypt } from '@bitgo-beta/sdk-api';
5
- import { ApiKeyShare, Keychain, KeyType } from '@bitgo-beta/sdk-core';
6
- import { coins } from '@bitgo-beta/statics';
7
-
8
- function createKeychain({
9
- commonKeychain,
10
- commonPub,
11
- encryptedPrv,
12
- keyShares,
13
- provider,
14
- pub,
15
- type,
16
- }: {
17
- commonKeychain?: string;
18
- commonPub?: string;
19
- encryptedPrv?: string;
20
- keyShares?: ApiKeyShare[];
21
- provider?: string;
22
- pub?: string;
23
- type?: KeyType;
24
- }): Keychain {
25
- return {
26
- commonKeychain,
27
- commonPub,
28
- encryptedPrv,
29
- id: 'id',
30
- keyShares,
31
- provider,
32
- pub: pub ?? 'pub',
33
- type: type ?? 'independent',
34
- };
35
- }
36
-
37
- describe('generateQrData', function () {
38
- it('hot wallet, backup key provided by user with encryptedPrv', function () {
39
- const userEncryptedPrv = 'prv123encrypted';
40
- const backupEncryptedPrv = 'prv456encrypted';
41
- const bitgoPub = 'pub789bitgo';
42
- const passphrase = 'testingIsFun';
43
- const passcodeEncryptionCode = '123456';
44
- const qrData = generateQrData({
45
- backupKeychain: createKeychain({
46
- encryptedPrv: backupEncryptedPrv,
47
- }),
48
- bitgoKeychain: createKeychain({
49
- pub: bitgoPub,
50
- }),
51
- coin: coins.get('btc'),
52
- passcodeEncryptionCode,
53
- passphrase,
54
- userKeychain: createKeychain({
55
- encryptedPrv: userEncryptedPrv,
56
- }),
57
- });
58
-
59
- qrData.user.title.should.equal('A: User Key');
60
- qrData.user.image.should.equal('.qrEncryptedUserKey');
61
- qrData.user.description.should.equal('This is your private key, encrypted with your wallet password.');
62
- qrData.user.data.should.equal(userEncryptedPrv);
63
-
64
- assert(qrData.backup);
65
- qrData.backup.title.should.equal('B: Backup Key');
66
- qrData.backup.image.should.equal('.qrEncryptedBackupKey');
67
- qrData.backup.description.should.equal('This is your backup private key, encrypted with your wallet password.');
68
- qrData.backup.data.should.equal(backupEncryptedPrv);
69
-
70
- assert(qrData.bitgo);
71
- qrData.bitgo.title.should.equal('C: BitGo Public Key');
72
- qrData.bitgo.image.should.equal('.qrBitgoKey');
73
- qrData.bitgo.description.should.equal('This is the public part of the key that BitGo will use to ' +
74
- 'co-sign transactions\r\nwith you on your wallet.');
75
- qrData.bitgo.data.should.equal(bitgoPub);
76
-
77
- assert(qrData.passcode);
78
- qrData.passcode.title.should.equal('D: Encrypted wallet Password');
79
- qrData.passcode.image.should.equal('.qrEncryptedWalletPasscode');
80
- qrData.passcode.description.should.equal('This is the wallet password, encrypted client-side with a key held by\r\nBitGo.');
81
- const decryptedData = decrypt(passcodeEncryptionCode, qrData.passcode.data);
82
- decryptedData.should.equal(passphrase);
83
- });
84
-
85
- describe('cold wallet', function () {
86
- const testSets: { coinName: string; keyType: KeyType }[] = [
87
- { coinName: 'btc', keyType: 'independent' },
88
- { coinName: 'sol', keyType: 'tss' },
89
- { coinName: 'eth', keyType: 'blsdkg' },
90
- ];
91
- for (const testSet of testSets) {
92
- it(`key type ${testSet.keyType}`, function () {
93
- const userPub = 'pub012user';
94
- const userMasterKey = 'userMasterKey';
95
- const backupPub = 'pub345backup';
96
- const backupMasterKey = 'backupMasterKey';
97
- const bitgoPub = 'pub789bitgo';
98
- const qrData = generateQrData({
99
- backupKeychain: createKeychain({
100
- commonKeychain: testSet.keyType === 'tss' ? backupPub : undefined,
101
- commonPub: testSet.keyType === 'blsdkg' ? backupPub : undefined,
102
- pub: testSet.keyType === 'independent' ? backupPub : undefined,
103
- type: testSet.keyType,
104
- }),
105
- backupMasterKey,
106
- bitgoKeychain: createKeychain({
107
- commonKeychain: testSet.keyType === 'tss' ? bitgoPub : undefined,
108
- commonPub: testSet.keyType === 'blsdkg' ? bitgoPub : undefined,
109
- pub: testSet.keyType === 'independent' ? bitgoPub : undefined,
110
- type: testSet.keyType,
111
- }),
112
- coin: coins.get('btc'),
113
- userKeychain: createKeychain({
114
- commonKeychain: testSet.keyType === 'tss' ? userPub : undefined,
115
- commonPub: testSet.keyType === 'blsdkg' ? userPub : undefined,
116
- pub: testSet.keyType === 'independent' ? userPub : undefined,
117
- type: testSet.keyType,
118
- }),
119
- userMasterKey,
120
- });
121
-
122
- qrData.user.title.should.equal('A: Provided User Key');
123
- qrData.user.image.should.equal('.qrPublicUserKey');
124
- qrData.user.description.should.equal('This is the public key you provided for your wallet.');
125
- qrData.user.data.should.equal(userPub);
126
- should.equal(qrData.user.publicMasterKey, userMasterKey);
127
-
128
- assert(qrData.backup);
129
- qrData.backup.title.should.equal('B: Provided Backup Key');
130
- qrData.backup.image.should.equal('.qrEncryptedUserProvidedXpub');
131
- qrData.backup.description.should.equal('This is the public key you provided for your wallet.');
132
- qrData.backup.data.should.equal(backupPub);
133
- should.equal(qrData.backup?.publicMasterKey, backupMasterKey);
134
-
135
- assert(qrData.bitgo);
136
- qrData.bitgo.data.should.equal(bitgoPub);
137
-
138
- should.not.exist(qrData.passcode);
139
- });
140
- }
141
- });
142
-
143
- it('backup key from provider', function () {
144
- const coin = coins.get('btc');
145
- const userEncryptedPrv = 'prv123encrypted';
146
- const backupPub = 'pub673backup';
147
- const provider = '3rd Party Provider';
148
- const bitgoPub = 'pub789bitgo';
149
- const qrData = generateQrData({
150
- backupKeychain: createKeychain({
151
- pub: backupPub,
152
- provider,
153
- }),
154
- backupKeyProvider: provider,
155
- bitgoKeychain: createKeychain({
156
- pub: bitgoPub,
157
- }),
158
- coin,
159
- userKeychain: createKeychain({
160
- encryptedPrv: userEncryptedPrv,
161
- }),
162
- });
163
-
164
- qrData.user.data.should.equal(userEncryptedPrv);
165
-
166
- assert(qrData.backup);
167
- qrData.backup.title.should.equal('B: Backup Key');
168
- qrData.backup.image.should.equal('.qrPublicBackupKey');
169
- qrData.backup.description.should.equal('This is the public key held at ' +
170
- provider +
171
- ', an ' +
172
- coin.name +
173
- ' recovery service. If you lose\r\nyour key, ' +
174
- provider +
175
- ' will be able to sign transactions to recover funds.');
176
- qrData.backup.data.should.equal(backupPub);
177
-
178
- assert(qrData.bitgo);
179
- qrData.bitgo.data.should.equal(bitgoPub);
180
- });
181
-
182
- it('tss backup key held at BitGo Trust', function () {
183
- const coin = coins.get('btc');
184
- const userEncryptedPrv = 'prv123encrypted';
185
- const provider = 'BitGoTrustAsKRS';
186
- const backupKeyProvider = 'BitGo Trust';
187
- const userToBackupKeyShare: ApiKeyShare = { from: 'user', to: 'backup', publicShare: 'userToBackupPublic', privateShare: 'userToBackupPrivate' };
188
- const bitgoToBackupKeyShare: ApiKeyShare = { from: 'bitgo', to: 'backup', publicShare: 'bitgoToBackupPublic', privateShare: 'bitgoToBackupPrivate' };
189
- const qrData = generateQrData({
190
- backupKeychain: createKeychain({
191
- provider,
192
- keyShares: [userToBackupKeyShare, bitgoToBackupKeyShare],
193
- type: 'tss',
194
- }),
195
- backupKeyProvider,
196
- bitgoKeychain: createKeychain({
197
- type: 'tss',
198
- }),
199
- coin,
200
- userKeychain: createKeychain({
201
- encryptedPrv: userEncryptedPrv,
202
- type: 'tss',
203
- }),
204
- });
205
-
206
- qrData.user.data.should.equal(userEncryptedPrv);
207
-
208
- assert(qrData.backup);
209
- qrData.backup.title.should.equal('B: User To Backup Key Share');
210
- qrData.backup.image.should.equal('.qrUserToBackupKeyShare');
211
- qrData.backup.description.should.equal(`This is the key share from you for ${backupKeyProvider}. If BitGo Inc goes out of business,\r\ncontact ${backupKeyProvider} and they will help you recover your funds.`);
212
- qrData.backup.data.should.equal(JSON.stringify(userToBackupKeyShare));
213
-
214
- assert(qrData.bitgo);
215
- qrData.bitgo.title.should.equal('C: BitGo To Backup Key Share');
216
- qrData.bitgo.image.should.equal('.qrBitGoToBackupKeyShare');
217
- qrData.bitgo.description.should.equal(`This is the key share from BitGo Inc for ${backupKeyProvider}. If BitGo Inc goes out of business,\r\ncontact ${backupKeyProvider} and they will help you recover your funds.`);
218
- qrData.bitgo.data.should.equal(JSON.stringify(bitgoToBackupKeyShare));
219
- });
220
- });