1
1
const prepareTransfers = require ( '@iota/core' ) . createPrepareTransfers ( )
2
2
3
3
const converter = require ( '@iota/converter' )
4
- const add = require ( '@iota/signing/out/signing/src/add ' ) . default
4
+ const add = require ( '@iota/signing' ) . add
5
5
const Kerl = require ( '@iota/kerl' ) . default
6
6
const { intToTrytes, trytesToInt, concat, padTritsMultipleOf, padTrytesMultipleOf, alphabet} = require ( './helpers' )
7
7
const { encrypt, decrypt} = require ( "./encrypt" )
@@ -12,7 +12,8 @@ const SECURITY_TRYTES = 1
12
12
const HEIGHT_TRYTES = 1
13
13
const PREFIX_LENGTH = INDEX_TRYTES + MESSAGE_LENGTH_TRYTES + SECURITY_TRYTES + HEIGHT_TRYTES
14
14
15
- const MESSAGE_FRAGMENT_TRYTES = 2187
15
+ const MESSAGE_FRAGMENT_TRYTES = 2187 ;
16
+ const SIGNATURE_TRYTES_PER_SECURITY = 2187 ;
16
17
17
18
const Errors = {
18
19
INVALID_LENGTH : `The message cannot be longer than ${ Math . pow ( 27 , MESSAGE_LENGTH_TRYTES ) } trytes.` ,
@@ -113,7 +114,7 @@ async function sendMessage(iota, merkleRoot, message, sig, index, verifyingKey,
113
114
async function sendTransfers ( iota , transfers , { message, depth = 3 , mwm = 14 } = { } ) {
114
115
const trytes = await prepareTransfers ( "9" . repeat ( 81 ) , transfers )
115
116
const bundle = await iota . sendTrytes ( trytes , depth , mwm )
116
- return { bundle, message}
117
+ return { bundle, message}
117
118
}
118
119
119
120
function getKey ( merkleRoot , channelPassword , indexTrits , messagePassword ) {
@@ -253,10 +254,13 @@ function processBundle(index, txs, key, {height, security} = {}) {
253
254
result . nextRoot = converter . trits ( decrypted . slice ( endHashes , endHashes + nextRootLength ) )
254
255
255
256
// extract signature
256
- result . signature = new Int8Array ( result . security * MESSAGE_FRAGMENT_TRYTES * 3 )
257
+ result . signature = new Int8Array ( result . security * SIGNATURE_TRYTES_PER_SECURITY * 3 )
258
+ let remaining = result . signature . length
257
259
for ( let i = payloadTransactions ; i < txs . length ; i ++ ) {
258
- result . signature . set ( converter . trits ( txs [ i ] . signatureMessageFragment ) ,
260
+ const frag = converter . trits ( txs [ i ] . signatureMessageFragment )
261
+ result . signature . set ( remaining >= MESSAGE_FRAGMENT_TRYTES * 3 ? frag : frag . slice ( 0 , remaining ) ,
259
262
( txs [ i ] . currentIndex - payloadTransactions ) * MESSAGE_FRAGMENT_TRYTES * 3 )
263
+ remaining -= MESSAGE_FRAGMENT_TRYTES * 3
260
264
}
261
265
262
266
return result
0 commit comments