@bitgo-beta/key-card 0.1.2-alpha.9 → 0.1.2-alpha.91

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/src/index.ts DELETED
@@ -1,22 +0,0 @@
1
- import { generateQrData, GenerateQrDataParams } from './generateQrData';
2
- import { generateFaq } from './faq';
3
- import { drawKeycard } from './drawKeycard';
4
-
5
- export * from './drawKeycard';
6
- export * from './faq';
7
- export * from './generateQrData';
8
- export * from './utils';
9
-
10
- export interface GenerateKeycardParams extends GenerateQrDataParams {
11
- activationCode?: string;
12
- keyCardImage?: HTMLImageElement;
13
- walletLabel: string;
14
- }
15
-
16
- export async function generateKeycard(params: GenerateKeycardParams): Promise<void> {
17
- const questions = generateFaq(params.coin.fullName);
18
- const qrData = generateQrData(params);
19
- const keycard = await drawKeycard({ ...params, questions, qrData });
20
- // Save the PDF on the user's browser
21
- keycard.save(`BitGo Keycard for ${params.walletLabel}.pdf`);
22
- }
package/src/utils.ts DELETED
@@ -1,15 +0,0 @@
1
- export function splitKeys(key: string, limit: number): string[] {
2
- if (key.length <= limit) {
3
- return [key];
4
- }
5
-
6
- const keys: string[] = [];
7
-
8
- let rightIndex = limit;
9
- for (let i = 0; i < key.length; i += limit) {
10
- keys.push(key.substring(i, rightIndex));
11
- rightIndex = Math.min(rightIndex + limit, key.length);
12
- }
13
-
14
- return keys;
15
- }
package/test/unit/faq.ts DELETED
@@ -1,14 +0,0 @@
1
- import { generateFaq } from '../../src/faq';
2
-
3
- describe('generateFaq', function () {
4
- it('generates faq with filled in coin name', function () {
5
- const coinName = 'fooCoin';
6
- const questions = generateFaq(coinName);
7
-
8
- questions.length.should.equal(7);
9
- questions[0].answer[0].should.match(new RegExp(coinName));
10
- questions[2].answer[0].should.match(new RegExp(coinName));
11
- questions[5].answer[1].should.match(new RegExp(coinName));
12
- questions[6].answer[2].should.match(new RegExp(coinName));
13
- });
14
- });
@@ -1,213 +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 BitGo.');
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 bitgoCommonKeychain = 'commonCommonBitGo';
183
- const qrData = generateQrData({
184
- backupKeychain: createKeychain({
185
- provider,
186
- keyShares: [userToBackupKeyShare, bitgoToBackupKeyShare],
187
- type: 'tss',
188
- }),
189
- backupKeyProvider,
190
- bitgoKeychain: createKeychain({
191
- type: 'tss',
192
- commonKeychain: bitgoCommonKeychain,
193
- }),
194
- coin,
195
- userKeychain: createKeychain({
196
- encryptedPrv: userEncryptedPrv,
197
- type: 'tss',
198
- }),
199
- });
200
-
201
- qrData.user.data.should.equal(userEncryptedPrv);
202
-
203
- assert(qrData.backup);
204
- qrData.backup.title.should.equal('B: Backup Key Shares');
205
- qrData.backup.description.should.equal(`These are the key shares for ${backupKeyProvider}. If BitGo Inc. goes out of business,\r\ncontact ${backupKeyProvider} and they will help you recover your funds.`);
206
- qrData.backup.data.should.equal(JSON.stringify([userToBackupKeyShare, bitgoToBackupKeyShare]));
207
-
208
- assert(qrData.bitgo);
209
- qrData.bitgo.title.should.equal('C: BitGo Public Key');
210
- qrData.bitgo.description.should.equal('This is the public part of the key that BitGo will use to co-sign transactions\r\nwith you on your wallet.');
211
- qrData.bitgo.data.should.equal(bitgoCommonKeychain);
212
- });
213
- });
@@ -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
- }