@@ -16,12 +16,14 @@ export default class GenericApp {
16
16
readonly INS : INSGeneric ;
17
17
readonly P1_VALUES : P1_VALUESGeneric ;
18
18
readonly acceptedPathLengths ?: number [ ] ;
19
+ readonly CHUNK_SIZE : number ;
19
20
20
21
constructor ( transport : Transport , params : ConstructorParams ) {
21
22
this . transport = transport ;
22
23
this . CLA = params . cla ;
23
24
this . INS = params . ins ;
24
25
this . P1_VALUES = params . p1Values ;
26
+ this . CHUNK_SIZE = params . chunkSize ;
25
27
this . acceptedPathLengths = params . acceptedPathLengths ;
26
28
}
27
29
@@ -56,6 +58,27 @@ export default class GenericApp {
56
58
return buf ;
57
59
}
58
60
61
+ prepareChunks ( path : string , message : Buffer ) : Buffer [ ] {
62
+ const chunks = [ ] ;
63
+ const serializedPathBuffer = this . serializePath ( path ) ;
64
+
65
+ // First chunk (only path)
66
+ chunks . push ( serializedPathBuffer ) ;
67
+
68
+ const messageBuffer = Buffer . from ( message ) ;
69
+
70
+ const buffer = Buffer . concat ( [ messageBuffer ] ) ;
71
+ for ( let i = 0 ; i < buffer . length ; i += this . CHUNK_SIZE ) {
72
+ let end = i + this . CHUNK_SIZE ;
73
+ if ( i > buffer . length ) {
74
+ end = buffer . length ;
75
+ }
76
+ chunks . push ( buffer . subarray ( i , end ) ) ;
77
+ }
78
+
79
+ return chunks ;
80
+ }
81
+
59
82
async getVersion ( ) : Promise < ResponseVersion > {
60
83
const versionResponse : ResponseVersion = await this . transport
61
84
. send ( this . CLA , this . INS . GET_VERSION , 0 , 0 )
0 commit comments