-
Notifications
You must be signed in to change notification settings - Fork 302
Expand file tree
/
Copy pathreplayProtection.ts
More file actions
62 lines (55 loc) · 2.31 KB
/
replayProtection.ts
File metadata and controls
62 lines (55 loc) · 2.31 KB
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
import assert from 'node:assert/strict';
import * as utxolib from '@bitgo/utxo-lib';
import {
getReplayProtectionPubkeys,
getReplayProtectionAddresses,
} from '../../../../src/transaction/fixedScript/replayProtection';
describe('replayProtection', function () {
for (const network of utxolib.getNetworkList()) {
const networkName = utxolib.getNetworkName(network);
assert(networkName, 'network name is required');
describe(`${networkName}`, function () {
if (
utxolib.getMainnet(network) === utxolib.networks.bitcoincash ||
utxolib.getMainnet(network) === utxolib.networks.bitcoinsv
) {
it('should have keys that correspond to addresses via p2shP2pk', function () {
const actualAddressesDefault = getReplayProtectionAddresses(network, 'default');
switch (network) {
case utxolib.networks.bitcoincash:
case utxolib.networks.bitcoinsv:
assert.deepStrictEqual(actualAddressesDefault, ['33p1q7mTGyeM5UnZERGiMcVUkY12SCsatA']);
break;
case utxolib.networks.bitcoincashTestnet:
case utxolib.networks.bitcoinsvTestnet:
assert.deepStrictEqual(actualAddressesDefault, ['2MuMnPoSDgWEpNWH28X2nLtYMXQJCyT61eY']);
break;
default:
throw new Error(`illegal state`);
}
if (utxolib.getMainnet(network) !== utxolib.networks.bitcoincash) {
return;
}
const actualAddressesCashaddr = getReplayProtectionAddresses(network, 'cashaddr');
switch (network) {
case utxolib.networks.bitcoincash:
assert.deepStrictEqual(actualAddressesCashaddr, [
'bitcoincash:pqt5x9w0m6z0f3znjkkx79wl3l7ywrszesemp8xgpf',
]);
break;
case utxolib.networks.bitcoincashTestnet:
assert.deepStrictEqual(actualAddressesCashaddr, ['bchtest:pqtjmnzwqffkrk2349g3cecfwwjwxusvnq87n07cal']);
break;
default:
throw new Error(`illegal state`);
}
});
} else {
it('should have no replay protection', function () {
assert.deepEqual(getReplayProtectionPubkeys(network), []);
assert.deepEqual(getReplayProtectionAddresses(network), []);
});
}
});
}
});