|
1 | 1 | import * as assert from 'assert'; |
2 | | -import { BuildParams } from '../../../../src/bitgo/wallet/BuildParams'; |
| 2 | +import { BuildParams, buildParamKeys, AttestationPayload } from '../../../../src/bitgo/wallet/BuildParams'; |
3 | 3 |
|
4 | 4 | describe('BuildParams', function () { |
5 | 5 | it('enforces codec', function () { |
@@ -74,4 +74,36 @@ describe('BuildParams', function () { |
74 | 74 | } |
75 | 75 | ); |
76 | 76 | }); |
| 77 | + |
| 78 | + it('should whitelist attestation (WCN-539) while stripping unrelated unknown params', function () { |
| 79 | + const attestation = { |
| 80 | + signature: 'sig', |
| 81 | + credentialId: 'cred-id', |
| 82 | + clientDataJSON: 'client-data', |
| 83 | + authenticatorData: 'auth-data', |
| 84 | + }; |
| 85 | + assert.deepStrictEqual( |
| 86 | + BuildParams.encode({ |
| 87 | + recipients: [{ amount: '10000', address: '2N9Ego9KidiZR8tMP82g6RaggQtcbR9zNzH' }], |
| 88 | + attestation, |
| 89 | + unknownField: 'should be stripped', |
| 90 | + } as any), |
| 91 | + { |
| 92 | + recipients: [{ amount: '10000', address: '2N9Ego9KidiZR8tMP82g6RaggQtcbR9zNzH' }], |
| 93 | + attestation, |
| 94 | + } |
| 95 | + ); |
| 96 | + assert.ok(buildParamKeys.includes('attestation'), 'buildParamKeys must include attestation'); |
| 97 | + }); |
| 98 | + |
| 99 | + it('AttestationPayload codec requires all four fields', function () { |
| 100 | + const valid = { |
| 101 | + signature: 'sig', |
| 102 | + credentialId: 'cred-id', |
| 103 | + clientDataJSON: 'client-data', |
| 104 | + authenticatorData: 'auth-data', |
| 105 | + }; |
| 106 | + assert.strictEqual(AttestationPayload.is(valid), true); |
| 107 | + assert.strictEqual(AttestationPayload.is({ ...valid, signature: undefined }), false); |
| 108 | + }); |
77 | 109 | }); |
0 commit comments