@@ -2,7 +2,7 @@ import { createEncoder, VariableSizeEncoder } from '@solana/codecs-core';
22import { getBase58Encoder } from '@solana/codecs-strings' ;
33
44import { createPrivateKeyFromBytes } from '../private-key' ;
5- import { SignatureBytes , signBytes , verifySignature } from '../signatures' ;
5+ import { assertIsSignatureBytes , SignatureBytes , signBytes , verifySignature } from '../signatures' ;
66
77jest . mock ( '@solana/codecs-strings' , ( ) => ( {
88 ...jest . requireActual ( '@solana/codecs-strings' ) ,
@@ -14,7 +14,7 @@ const MOCK_DATA_SIGNATURE = new Uint8Array([
1414 66 , 111 , 184 , 228 , 239 , 189 , 127 , 46 , 23 , 168 , 117 , 69 , 58 , 143 , 132 , 164 , 112 , 189 , 203 , 228 , 183 , 151 , 0 , 23 , 179 ,
1515 181 , 52 , 75 , 112 , 225 , 150 , 128 , 184 , 164 , 36 , 21 , 101 , 205 , 115 , 28 , 127 , 221 , 24 , 135 , 229 , 8 , 69 , 232 , 16 , 225 ,
1616 44 , 229 , 17 , 236 , 206 , 174 , 102 , 207 , 79 , 253 , 96 , 7 , 174 , 10 ,
17- ] ) as SignatureBytes ;
17+ ] ) ;
1818const MOCK_PRIVATE_KEY_BYTES = new Uint8Array ( [
1919 0xeb , 0xfa , 0x65 , 0xeb , 0x93 , 0xdc , 0x79 , 0x15 , 0x7a , 0xba , 0xde , 0xa2 , 0xf7 , 0x94 , 0x37 , 0x9d , 0xfc , 0x07 , 0x1d ,
2020 0x68 , 0x86 , 0x87 , 0x37 , 0x6d , 0xc5 , 0xd5 , 0xa0 , 0x54 , 0x12 , 0x1d , 0x34 , 0x4a ,
@@ -143,6 +143,33 @@ describe('assertIsSignature()', () => {
143143 } ) ;
144144} ) ;
145145
146+ describe ( 'assertIsSignatureBytes()' , ( ) => {
147+ it ( 'throws when supplied an empty byte array' , ( ) => {
148+ expect ( ( ) => {
149+ assertIsSignatureBytes ( new Uint8Array ( 0 ) ) ;
150+ } ) . toThrow ( ) ;
151+ } ) ;
152+ it . each ( [ 63 , 65 ] ) ( 'throws when the byte array has a length of %s' , length => {
153+ expect ( ( ) => {
154+ assertIsSignatureBytes ( new Uint8Array ( length ) ) ;
155+ } ) . toThrow ( ) ;
156+ } ) ;
157+ it ( 'does not throw when supplied a zeroed 64-byte bytearray' , ( ) => {
158+ expect ( ( ) => {
159+ assertIsSignatureBytes ( new Uint8Array ( 64 ) ) ;
160+ } ) . not . toThrow ( ) ;
161+ } ) ;
162+ it ( 'does not throw when supplied a 64-byte signature as a bytearray' , ( ) => {
163+ expect ( ( ) => {
164+ assertIsSignatureBytes ( MOCK_DATA_SIGNATURE ) ;
165+ } ) . not . toThrow ( ) ;
166+ } ) ;
167+ it ( 'returns undefined when supplied a 64-byte byte array' , ( ) => {
168+ // 64 bytes [0, ..., 0]
169+ expect ( assertIsSignatureBytes ( new Uint8Array ( 64 ) ) ) . toBeUndefined ( ) ;
170+ } ) ;
171+ } ) ;
172+
146173describe ( 'sign' , ( ) => {
147174 it ( 'produces the expected signature given a private key' , async ( ) => {
148175 expect . assertions ( 1 ) ;
@@ -171,7 +198,7 @@ describe('verify', () => {
171198 } ) ;
172199 it ( 'returns `true` when the correct signature is supplied for a given payload' , async ( ) => {
173200 expect . assertions ( 1 ) ;
174- const result = await verifySignature ( mockPublicKey , MOCK_DATA_SIGNATURE , MOCK_DATA ) ;
201+ const result = await verifySignature ( mockPublicKey , MOCK_DATA_SIGNATURE as SignatureBytes , MOCK_DATA ) ;
175202 expect ( result ) . toBe ( true ) ;
176203 } ) ;
177204 it ( 'returns `false` when a bad signature is supplied for a given payload' , async ( ) => {
0 commit comments