@bitgo-beta/key-card 0.0.1-beta.16 → 0.0.1-beta.161

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.
@@ -1,211 +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.description.should.equal('This is your private key, encrypted with your wallet password.');
61
- qrData.user.data.should.equal(userEncryptedPrv);
62
-
63
- assert(qrData.backup);
64
- qrData.backup.title.should.equal('B: Backup Key');
65
- qrData.backup.description.should.equal('This is your backup private key, encrypted with your wallet password.');
66
- qrData.backup.data.should.equal(backupEncryptedPrv);
67
-
68
- assert(qrData.bitgo);
69
- qrData.bitgo.title.should.equal('C: BitGo Public Key');
70
- qrData.bitgo.description.should.equal('This is the public part of the key that BitGo will use to ' +
71
- 'co-sign transactions\r\nwith you on your wallet.');
72
- qrData.bitgo.data.should.equal(bitgoPub);
73
-
74
- assert(qrData.passcode);
75
- qrData.passcode.title.should.equal('D: Encrypted wallet Password');
76
- qrData.passcode.description.should.equal('This is the wallet password, encrypted client-side with a key held by\r\nBitGo.');
77
- const decryptedData = decrypt(passcodeEncryptionCode, qrData.passcode.data);
78
- decryptedData.should.equal(passphrase);
79
- });
80
-
81
- describe('cold wallet', function () {
82
- const testSets: { coinName: string; keyType: KeyType }[] = [
83
- { coinName: 'btc', keyType: 'independent' },
84
- { coinName: 'sol', keyType: 'tss' },
85
- { coinName: 'eth', keyType: 'blsdkg' },
86
- ];
87
- for (const testSet of testSets) {
88
- it(`key type ${testSet.keyType}`, function () {
89
- const userPub = 'pub012user';
90
- const userMasterKey = 'userMasterKey';
91
- const backupPub = 'pub345backup';
92
- const backupMasterKey = 'backupMasterKey';
93
- const bitgoPub = 'pub789bitgo';
94
- const qrData = generateQrData({
95
- backupKeychain: createKeychain({
96
- commonKeychain: testSet.keyType === 'tss' ? backupPub : undefined,
97
- commonPub: testSet.keyType === 'blsdkg' ? backupPub : undefined,
98
- pub: testSet.keyType === 'independent' ? backupPub : undefined,
99
- type: testSet.keyType,
100
- }),
101
- backupMasterKey,
102
- bitgoKeychain: createKeychain({
103
- commonKeychain: testSet.keyType === 'tss' ? bitgoPub : undefined,
104
- commonPub: testSet.keyType === 'blsdkg' ? bitgoPub : undefined,
105
- pub: testSet.keyType === 'independent' ? bitgoPub : undefined,
106
- type: testSet.keyType,
107
- }),
108
- coin: coins.get('btc'),
109
- userKeychain: createKeychain({
110
- commonKeychain: testSet.keyType === 'tss' ? userPub : undefined,
111
- commonPub: testSet.keyType === 'blsdkg' ? userPub : undefined,
112
- pub: testSet.keyType === 'independent' ? userPub : undefined,
113
- type: testSet.keyType,
114
- }),
115
- userMasterKey,
116
- });
117
-
118
- qrData.user.title.should.equal('A: Provided User Key');
119
- qrData.user.description.should.equal('This is the public key you provided for your wallet.');
120
- qrData.user.data.should.equal(userPub);
121
- should.equal(qrData.user.publicMasterKey, userMasterKey);
122
-
123
- assert(qrData.backup);
124
- qrData.backup.title.should.equal('B: Provided Backup Key');
125
- qrData.backup.description.should.equal('This is the public key you provided for your wallet.');
126
- qrData.backup.data.should.equal(backupPub);
127
- should.equal(qrData.backup?.publicMasterKey, backupMasterKey);
128
-
129
- assert(qrData.bitgo);
130
- qrData.bitgo.data.should.equal(bitgoPub);
131
-
132
- should.not.exist(qrData.passcode);
133
- });
134
- }
135
- });
136
-
137
- it('backup key from provider', function () {
138
- const coin = coins.get('btc');
139
- const userEncryptedPrv = 'prv123encrypted';
140
- const backupPub = 'pub673backup';
141
- const provider = '3rd Party Provider';
142
- const bitgoPub = 'pub789bitgo';
143
- const qrData = generateQrData({
144
- backupKeychain: createKeychain({
145
- pub: backupPub,
146
- provider,
147
- }),
148
- backupKeyProvider: provider,
149
- bitgoKeychain: createKeychain({
150
- pub: bitgoPub,
151
- }),
152
- coin,
153
- userKeychain: createKeychain({
154
- encryptedPrv: userEncryptedPrv,
155
- }),
156
- });
157
-
158
- qrData.user.data.should.equal(userEncryptedPrv);
159
-
160
- assert(qrData.backup);
161
- qrData.backup.title.should.equal('B: Backup Key');
162
- qrData.backup.description.should.equal('This is the public key held at ' +
163
- provider +
164
- ', an ' +
165
- coin.name +
166
- ' recovery service. If you lose\r\nyour key, ' +
167
- provider +
168
- ' will be able to sign transactions to recover funds.');
169
- qrData.backup.data.should.equal(backupPub);
170
-
171
- assert(qrData.bitgo);
172
- qrData.bitgo.data.should.equal(bitgoPub);
173
- });
174
-
175
- it('tss backup key held at BitGo Trust', function () {
176
- const coin = coins.get('btc');
177
- const userEncryptedPrv = 'prv123encrypted';
178
- const provider = 'BitGoTrustAsKRS';
179
- const backupKeyProvider = 'BitGo Trust';
180
- const userToBackupKeyShare: ApiKeyShare = { from: 'user', to: 'backup', publicShare: 'userToBackupPublic', privateShare: 'userToBackupPrivate' };
181
- const bitgoToBackupKeyShare: ApiKeyShare = { from: 'bitgo', to: 'backup', publicShare: 'bitgoToBackupPublic', privateShare: 'bitgoToBackupPrivate' };
182
- const qrData = generateQrData({
183
- backupKeychain: createKeychain({
184
- provider,
185
- keyShares: [userToBackupKeyShare, bitgoToBackupKeyShare],
186
- type: 'tss',
187
- }),
188
- backupKeyProvider,
189
- bitgoKeychain: createKeychain({
190
- type: 'tss',
191
- }),
192
- coin,
193
- userKeychain: createKeychain({
194
- encryptedPrv: userEncryptedPrv,
195
- type: 'tss',
196
- }),
197
- });
198
-
199
- qrData.user.data.should.equal(userEncryptedPrv);
200
-
201
- assert(qrData.backup);
202
- qrData.backup.title.should.equal('B: User To Backup Key Share');
203
- 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.`);
204
- qrData.backup.data.should.equal(JSON.stringify(userToBackupKeyShare));
205
-
206
- assert(qrData.bitgo);
207
- qrData.bitgo.title.should.equal('C: BitGo To Backup Key Share');
208
- 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.`);
209
- qrData.bitgo.data.should.equal(JSON.stringify(bitgoToBackupKeyShare));
210
- });
211
- });
@@ -1,30 +0,0 @@
1
- import 'should';
2
- import { splitKeys } from '../../src';
3
-
4
- describe('getSplitKeys', function () {
5
- it('only returns one item when input shorter than limit', function () {
6
- const key = 'hello world';
7
- const limit = 20;
8
- const keys = splitKeys(key, limit);
9
- keys.length.should.equal(1);
10
- keys[0].should.equal(key);
11
- });
12
-
13
- it('splits key up into multiple items when exceeding the limit', function () {
14
- const key = 'hello world this is a short message';
15
- const limit = 5;
16
- const keys = splitKeys(key, limit);
17
- keys.length.should.equal(7);
18
- for (const splitKey of keys.slice(0, keys.length - 1)) {
19
- splitKey.length.should.equal(limit);
20
- }
21
- keys[keys.length - 1].length.should.be.lessThanOrEqual(limit);
22
- keys[0].should.equal('hello');
23
- keys[1].should.equal(' worl');
24
- keys[2].should.equal('d thi');
25
- keys[3].should.equal('s is ');
26
- keys[4].should.equal('a sho');
27
- keys[5].should.equal('rt me');
28
- keys[6].should.equal('ssage');
29
- });
30
- });
package/tsconfig.json DELETED
@@ -1,20 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "./dist",
5
- "rootDir": "./"
6
- },
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
- ]
20
- }