@bitgo-beta/key-card 0.0.1-beta.7 → 0.0.1-beta.9
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 +5 -5
- package/src/generateQrData.ts +35 -2
- package/test/unit/generateQrData.ts +51 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bitgo-beta/key-card",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.9",
|
|
4
4
|
"description": "key card generator for BitGo wallets",
|
|
5
5
|
"main": "./dist/src/index.js",
|
|
6
6
|
"types": "./dist/src/index.d.ts",
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
]
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@bitgo-beta/sdk-api": "1.1.1-beta.
|
|
37
|
-
"@bitgo-beta/sdk-core": "1.1.1-beta.
|
|
38
|
-
"@bitgo-beta/statics": "7.0.1-beta.
|
|
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
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "2a8f20b3ca0aa4498def41930539fce61847f764"
|
|
41
41
|
}
|
package/src/generateQrData.ts
CHANGED
|
@@ -93,6 +93,18 @@ function generateBackupQrData(coin: Readonly<BaseCoin>, backupKeychain: Keychain
|
|
|
93
93
|
};
|
|
94
94
|
}
|
|
95
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
|
+
|
|
96
108
|
const pub = getPubFromKey(backupKeychain);
|
|
97
109
|
assert(pub);
|
|
98
110
|
|
|
@@ -115,7 +127,25 @@ function generateBackupQrData(coin: Readonly<BaseCoin>, backupKeychain: Keychain
|
|
|
115
127
|
};
|
|
116
128
|
}
|
|
117
129
|
|
|
118
|
-
function generateBitGoQrData(bitgoKeychain: Keychain
|
|
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
|
+
|
|
119
149
|
const bitgoData = getPubFromKey(bitgoKeychain);
|
|
120
150
|
assert(bitgoData);
|
|
121
151
|
|
|
@@ -146,7 +176,10 @@ export function generateQrData({
|
|
|
146
176
|
backupKeyProvider,
|
|
147
177
|
backupMasterKey,
|
|
148
178
|
}),
|
|
149
|
-
bitgo: generateBitGoQrData(bitgoKeychain
|
|
179
|
+
bitgo: generateBitGoQrData(bitgoKeychain, {
|
|
180
|
+
backupKeychain,
|
|
181
|
+
backupKeyProvider,
|
|
182
|
+
}),
|
|
150
183
|
};
|
|
151
184
|
|
|
152
185
|
if (passphrase && passcodeEncryptionCode) {
|
|
@@ -2,19 +2,23 @@ import * as assert from 'assert';
|
|
|
2
2
|
import * as should from 'should';
|
|
3
3
|
import { generateQrData } from '../../src/generateQrData';
|
|
4
4
|
import { decrypt } from '@bitgo-beta/sdk-api';
|
|
5
|
-
import { Keychain, KeyType } from '@bitgo-beta/sdk-core';
|
|
5
|
+
import { ApiKeyShare, Keychain, KeyType } from '@bitgo-beta/sdk-core';
|
|
6
6
|
import { coins } from '@bitgo-beta/statics';
|
|
7
7
|
|
|
8
8
|
function createKeychain({
|
|
9
9
|
commonKeychain,
|
|
10
10
|
commonPub,
|
|
11
11
|
encryptedPrv,
|
|
12
|
+
keyShares,
|
|
13
|
+
provider,
|
|
12
14
|
pub,
|
|
13
15
|
type,
|
|
14
16
|
}: {
|
|
15
17
|
commonKeychain?: string;
|
|
16
18
|
commonPub?: string;
|
|
17
19
|
encryptedPrv?: string;
|
|
20
|
+
keyShares?: ApiKeyShare[];
|
|
21
|
+
provider?: string;
|
|
18
22
|
pub?: string;
|
|
19
23
|
type?: KeyType;
|
|
20
24
|
}): Keychain {
|
|
@@ -23,6 +27,8 @@ function createKeychain({
|
|
|
23
27
|
commonPub,
|
|
24
28
|
encryptedPrv,
|
|
25
29
|
id: 'id',
|
|
30
|
+
keyShares,
|
|
31
|
+
provider,
|
|
26
32
|
pub: pub ?? 'pub',
|
|
27
33
|
type: type ?? 'independent',
|
|
28
34
|
};
|
|
@@ -138,13 +144,14 @@ describe('generateQrData', function () {
|
|
|
138
144
|
const coin = coins.get('btc');
|
|
139
145
|
const userEncryptedPrv = 'prv123encrypted';
|
|
140
146
|
const backupPub = 'pub673backup';
|
|
141
|
-
const
|
|
147
|
+
const provider = '3rd Party Provider';
|
|
142
148
|
const bitgoPub = 'pub789bitgo';
|
|
143
149
|
const qrData = generateQrData({
|
|
144
150
|
backupKeychain: createKeychain({
|
|
145
151
|
pub: backupPub,
|
|
152
|
+
provider,
|
|
146
153
|
}),
|
|
147
|
-
backupKeyProvider,
|
|
154
|
+
backupKeyProvider: provider,
|
|
148
155
|
bitgoKeychain: createKeychain({
|
|
149
156
|
pub: bitgoPub,
|
|
150
157
|
}),
|
|
@@ -160,15 +167,54 @@ describe('generateQrData', function () {
|
|
|
160
167
|
qrData.backup.title.should.equal('B: Backup Key');
|
|
161
168
|
qrData.backup.image.should.equal('.qrPublicBackupKey');
|
|
162
169
|
qrData.backup.description.should.equal('This is the public key held at ' +
|
|
163
|
-
|
|
170
|
+
provider +
|
|
164
171
|
', an ' +
|
|
165
172
|
coin.name +
|
|
166
173
|
' recovery service. If you lose\r\nyour key, ' +
|
|
167
|
-
|
|
174
|
+
provider +
|
|
168
175
|
' will be able to sign transactions to recover funds.');
|
|
169
176
|
qrData.backup.data.should.equal(backupPub);
|
|
170
177
|
|
|
171
178
|
assert(qrData.bitgo);
|
|
172
179
|
qrData.bitgo.data.should.equal(bitgoPub);
|
|
173
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
|
+
});
|
|
174
220
|
});
|