From 410f454ee13146260c780c2d74713809f6969750 Mon Sep 17 00:00:00 2001 From: Natanael Date: Mon, 15 Nov 2021 14:00:38 -0600 Subject: [PATCH 1/4] feature(message): Add a new function to construct and sign a stacks' message --- js/src/index.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/js/src/index.ts b/js/src/index.ts index 1b58893b..36fcb9bc 100644 --- a/js/src/index.ts +++ b/js/src/index.ts @@ -239,4 +239,29 @@ export default class BlockstackApp { }, processErrorResponse); }, processErrorResponse); } + + async sign_msg(path: string, message: string) { + const len = message.length + const stacks_message = "\x19Stacks Signed Message:\n" + `${len}` + message + const blob = Buffer.from(stacks_message) + return this.signGetChunks(path, blob).then(chunks => { + return this.signSendChunk(1, chunks.length, chunks[0]).then(async response => { + let result = { + returnCode: response.returnCode, + errorMessage: response.errorMessage, + postSignHash: null as null | Buffer, + signatureCompact: null as null | Buffer, + signatureDER: null as null | Buffer, + }; + for (let i = 1; i < chunks.length; i += 1) { + // eslint-disable-next-line no-await-in-loop + result = await this.signSendChunk(1 + i, chunks.length, chunks[i]); + if (result.returnCode !== LedgerError.NoErrors) { + break; + } + } + return result; + }, processErrorResponse); + }, processErrorResponse); + } } From e1ed387a6552665530d1c34315193450fdb359f9 Mon Sep 17 00:00:00 2001 From: Natanael Date: Mon, 15 Nov 2021 14:01:28 -0600 Subject: [PATCH 2/4] feature(message): Update sign_message test and some clean-ups in the string-args test --- tests_zemu/tests/standard.test.ts | 44 +++++-------------------------- 1 file changed, 6 insertions(+), 38 deletions(-) diff --git a/tests_zemu/tests/standard.test.ts b/tests_zemu/tests/standard.test.ts index 3a92abd8..63a1fa09 100644 --- a/tests_zemu/tests/standard.test.ts +++ b/tests_zemu/tests/standard.test.ts @@ -477,19 +477,9 @@ describe('Standard', function () { expect(testPublicKey).toEqual('02' + expectedPublicKey.slice(2, 2 + 32 * 2)) const msg = "Hello World" - const len = msg.length - const signedTx = "\x19Stacks Signed Message:\n" + `${len}` + msg - console.log(signedTx) - - const unsignedTx = signedTx - - // tx_hash: bdb9f5112cf2333e6b8e6fca88764083332a41923dadab84cd5065a7a483a3f6 - // digest: dd46e325d5a631c99e84f3018a839c229453ab7fd8d16a6dadd7f7cf51e604c3 - - const blob = Buffer.from(unsignedTx) // Check the signature - const signatureRequest = app.sign(path, blob) + const signatureRequest = app.sign_msg(path, msg) // Wait until we are not in the main men await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot()) @@ -497,39 +487,17 @@ describe('Standard', function () { await sim.compareSnapshotsAndAccept('.', `${m.prefix.toLowerCase()}-sign_message`, m.name === 'nanos' ? 1 : 2) const signature = await signatureRequest - // TODO: Complete message signing - // current error: - // errorMessage: 'Sign/verify error : zxerr_no_data' + console.log(signature) expect(signature.returnCode).toEqual(0x9000) expect(signature.errorMessage).toEqual('No errors') - // @ts-ignore - //const js_signature = signedTx.auth.spendingCondition?.signature.signature - - //console.log('js_signature ', js_signature) - //console.log('ledger-postSignHash: ', signature.postSignHash.toString('hex')) - //console.log('ledger-compact: ', signature.signatureCompact.toString('hex')) - //console.log('ledger-vrs', signature.signatureVRS.toString('hex')) - //console.log('ledger-DER: ', signature.signatureDER.toString('hex')) - - // @ts-ignore - //unsignedTx.auth.spendingCondition.signature = createMessageSignature(signature.signatureVRS.toString('hex')) - //unsignedTx.auth.spendingCondition.signature.signature = signature.signatureVRS.toString('hex'); - - console.log('unsignedTx serialized ', unsignedTx.toString('hex')) - // - // const broadcast = await broadcastTransaction(unsignedTx, network); - // console.log(broadcast); - // - // expect(broadcast.reason).not.toBe("SignatureValidation"); - // - // expect(signature.returnCode).toEqual(0x9000); - // - //Verify signature const ec = new EC("secp256k1"); - const msgHash = sha512_256(unsignedTx); + const len = msg.length + const data = "\x19Stacks Signed Message:\n" + `${len}` + msg + console.log(data) + const msgHash = sha512_256(data); const sig = signature.signatureVRS.toString('hex') const signature_obj = { r: sig.substr(2, 64), From e6c47a41ebdf206503b687d1653d3101c8f6ed7c Mon Sep 17 00:00:00 2001 From: Natanael Date: Mon, 15 Nov 2021 14:02:59 -0600 Subject: [PATCH 3/4] bump app version and update snapshots --- tests_zemu/snapshots/s-mainmenu/00004.png | Bin 415 -> 414 bytes tests_zemu/snapshots/s-mainmenu/00011.png | Bin 415 -> 414 bytes tests_zemu/snapshots/x-mainmenu/00004.png | Bin 363 -> 360 bytes tests_zemu/snapshots/x-mainmenu/00011.png | Bin 363 -> 360 bytes 4 files changed, 0 insertions(+), 0 deletions(-) diff --git a/tests_zemu/snapshots/s-mainmenu/00004.png b/tests_zemu/snapshots/s-mainmenu/00004.png index 53c7cea80ef0bd1201a05b7d0852716f304e6e45..eaf743f67badd871cdfe55d18134658c81862f00 100644 GIT binary patch delta 387 zcmV-}0et?S1D*qrB!6W|L_t(|ob8$24uc>Jh0$#9|G-|j3zvpa+ER2#=lS9lfs!2P zk0m7l002*A8MoEGW!t__8R=d=AFo0CaN+(=%05ONKmmCJ9fRZ_`uH(&iErJ+s1QUN zkwB6MaAl?QP^QIU9kfrOJ7?d%Up~@kGq(_pwh$!wdyaV-DSyuFTSYt5zCs?sxbeC1 zdw?XaLf^$yY*s^mDBX#+93Vw-X;6yn%KU0@=L>n#RuXswoClEP!XvT@H`1GgNn&Vy zJppTpso{ER3R9s1E<`S`mvUa7{mkNB0&$6R=*g<&wVXll$^@LDrhXdQ4Xx5rI~6~7 z=8{nL*r--S6?{@w`3Eir%_S{1XTsBpIFPz&%Dt=3Y`L4$%Xgk$4=DP{I{9UEbuM{> zflNj2faW+4!0gZbnrIQm#B%^rRjRarfQ3H*b`Qvmf&@Al>sQZ@xI{N!wf! hstg4H0001ZCLhV5&EoBg>AFF{{#1;yKo^!1i>~|w)3S|#$s}m zA2B5W0095WHgBo(D3*O+GBW)8db}pB!-e}fDaV+#0Ttv8v<;Gf=;L|h7TDSytKM?<@=eT6cDapP;_ z_W(&;g|UOF*ldRWP`VSg93Vw-X;6yn%KT<<=RfkKtt9XWI5!~4g-2u+9%M8Llf=;a zegf7KOT+cl6sA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Q@6@ i9N>`v00000%ku%_s=x_l>YAD>WZ)Ye}5D`nXs?a zBHlURj0RiCYeu7+QMOY~+f+oGC#ar|<+6V{vEF|EOuNK*z$GGXV!g6Za`JfmkGaL+pOdU^7_2-B2H^2-EF zU-G;0>KJlGX0`b6`jwunn7Vbf&DNJmTT*`)ehMj!UQ|~2af3W_q*TMZa9fW_Kv#x)ay!lU~}*Dvh4E>SyZ8^H)zDt!ZOIc>IG# Yy!pbnPeQl#>;VaSy85}Sb4q9e098wkvH$=8 delta 336 zcmaFC^qOgcO1+V%i(^Q|oVPclg_;$390G5>^tH1ntMH`C7^`-B9p$Seup@m@E~ z>&S$~EMHh%J>9mx{(g;hYO+Jm#SNWT3ytI@R?XeLCy?*fDF(YsP8EMep7okG`+R9% z*)r<|zZ;*g7v_9ikOxK5X5&e^wuTs6eYe(r`#r?() z*LK^8Kh$k&r d5PoN{xGKJe;pYFK>GMoMqMojPF6*2UngCA{nG^s3 diff --git a/tests_zemu/snapshots/x-mainmenu/00011.png b/tests_zemu/snapshots/x-mainmenu/00011.png index d5725180f0da9ec7726fa56eba415d2fc739ae03..0562744c5c8f30aea2484d184660cb8c0e211948 100644 GIT binary patch delta 333 zcmaFO^nz)EO1-|Pi(^Q|oVPb)`I;33+yZZxsK2ZCe6y5)8H=QZmX`4=TmRmA#rqr_ zbJZ9SprC7dDRYrx%a7`L&u#f%?yFtWU&YAD>WZ)Ye}5D`nXs?a zBHlURj0RiCYeu7+QMOY~+f+oGC#ar|<+6V{vEF|EOuNK*z$GGXV!g6Za`JfmkGaL+pOdU^7_2-B2H^2-EF zU-G;0>KJlGX0`b6`jwunn7Vbf&DNJmTT*`)ehMj!UQ|~2af3W_q*TMZa9fW_Kv#x)ay!lU~}*Dvh4E>SyZ8^H)zDt!ZOIc>IG# Yy!pbnPeQl#>;VaSy85}Sb4q9e098wkvH$=8 delta 336 zcmaFC^qOgcO1+V%i(^Q|oVPclg_;$390G5>^tH1ntMH`C7^`-B9p$Seup@m@E~ z>&S$~EMHh%J>9mx{(g;hYO+Jm#SNWT3ytI@R?XeLCy?*fDF(YsP8EMep7okG`+R9% z*)r<|zZ;*g7v_9ikOxK5X5&e^wuTs6eYe(r`#r?() z*LK^8Kh$k&r d5PoN{xGKJe;pYFK>GMoMqMojPF6*2UngCA{nG^s3 From 53d10bb279414f6398a2de6076cfae0bd703f4aa Mon Sep 17 00:00:00 2001 From: Natanael Date: Mon, 15 Nov 2021 14:50:10 -0600 Subject: [PATCH 4/4] Update snapshots --- tests_zemu/snapshots/s-mainmenu/00004.png | Bin 414 -> 415 bytes tests_zemu/snapshots/s-mainmenu/00011.png | Bin 414 -> 415 bytes tests_zemu/snapshots/x-mainmenu/00004.png | Bin 360 -> 363 bytes tests_zemu/snapshots/x-mainmenu/00011.png | Bin 360 -> 363 bytes 4 files changed, 0 insertions(+), 0 deletions(-) diff --git a/tests_zemu/snapshots/s-mainmenu/00004.png b/tests_zemu/snapshots/s-mainmenu/00004.png index eaf743f67badd871cdfe55d18134658c81862f00..53c7cea80ef0bd1201a05b7d0852716f304e6e45 100644 GIT binary patch delta 388 zcmV-~0ek+Q1D^wsB!6Z}L_t(|ob8$24#OY_g>AFF{{#1;yKo^!1i>~|w)3S|#$s}m zA2B5W0095WHgBo(D3*O+GBW)8db}pB!-e}fDaV+#0Ttv8v<;Gf=;L|h7TDSytKM?<@=eT6cDapP;_ z_W(&;g|UOF*ldRWP`VSg93Vw-X;6yn%KT<<=RfkKtt9XWI5!~4g-2u+9%M8Llf=;a zegf7KOT+cl6sAH2+=yIWZ}q$~`*n+V3B)B%){|Aqdp(2Tl?k{)OZ_yp8`{KDJ1N&R zW4*gDvsw{NNPSu54$Ku-?pzjwi{WWSWTbAIa`c)rEypv0f)^R}fU2LYQ=Ugx=Q3=A z!H#nSy8W3sMD9OVcs4+)N|hE6=;04RmQ=}cy_|SE`!QbvGPWdK-4Bd2EoMvYjQ@6@ i9N>`v00000%ku%_s=x_l>Jh0$#9|G-|j3zvpa+ER2#=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ClEP!XvT@H`1GgNn&Vy zJppTpso{ER3R9s1E<`S`mvUa7{mkNB0&$6R=*g<&wVXll$^@LDrhXdQ4Xx5rI~6~7 z=8{nL*r--S6?{@w`3Eir%_S{1XTsBpIFPz&%Dt=3Y`L4$%Xgk$4=DP{I{9UEbuM{> zflNj2faW+4!0gZbnrIQm#B%^rRjRarfQ3H*b`Qvmf&@Al>sQZ@xI{N!wf! hstg4H0001ZCLhV5&EoBg>^tH1ntMH`C7^`-B9p$Seup@m@E~ z>&S$~EMHh%J>9mx{(g;hYO+Jm#SNWT3ytI@R?XeLCy?*fDF(YsP8EMep7okG`+R9% z*)r<|zZ;*g7v_9ikOxK5X5&e^wuTs6eYe(r`#r?() z*LK^8Kh$k&r d5PoN{xGKJe;pYFK>GMoMqMojPF6*2UngCA{nG^s3 delta 333 zcmaFO^nz)EO1-|Pi(^Q|oVPb)`I;33+yZZxsK2ZCe6y5)8H=QZmX`4=TmRmA#rqr_ zbJZ9SprC7dDRYrx%a7`L&u#f%?yFtWU&YAD>WZ)Ye}5D`nXs?a zBHlURj0RiCYeu7+QMOY~+f+oGC#ar|<+6V{vEF|EOuNK*z$GGXV!g6Za`JfmkGaL+pOdU^7_2-B2H^2-EF zU-G;0>KJlGX0`b6`jwunn7Vbf&DNJmTT*`)ehMj!UQ|~2af3W_q*TMZa9fW_Kv#x)ay!lU~}*Dvh4E>SyZ8^H)zDt!ZOIc>IG# Yy!pbnPeQl#>;VaSy85}Sb4q9e098wkvH$=8 diff --git a/tests_zemu/snapshots/x-mainmenu/00011.png b/tests_zemu/snapshots/x-mainmenu/00011.png index 0562744c5c8f30aea2484d184660cb8c0e211948..d5725180f0da9ec7726fa56eba415d2fc739ae03 100644 GIT binary patch delta 336 zcmaFC^qOgcO1+V%i(^Q|oVPclg_;$390G5>^tH1ntMH`C7^`-B9p$Seup@m@E~ z>&S$~EMHh%J>9mx{(g;hYO+Jm#SNWT3ytI@R?XeLCy?*fDF(YsP8EMep7okG`+R9% z*)r<|zZ;*g7v_9ikOxK5X5&e^wuTs6eYe(r`#r?() z*LK^8Kh$k&r d5PoN{xGKJe;pYFK>GMoMqMojPF6*2UngCA{nG^s3 delta 333 zcmaFO^nz)EO1-|Pi(^Q|oVPb)`I;33+yZZxsK2ZCe6y5)8H=QZmX`4=TmRmA#rqr_ zbJZ9SprC7dDRYrx%a7`L&u#f%?yFtWU&YAD>WZ)Ye}5D`nXs?a zBHlURj0RiCYeu7+QMOY~+f+oGC#ar|<+6V{vEF|EOuNK*z$GGXV!g6Za`JfmkGaL+pOdU^7_2-B2H^2-EF zU-G;0>KJlGX0`b6`jwunn7Vbf&DNJmTT*`)ehMj!UQ|~2af3W_q*TMZa9fW_Kv#x)ay!lU~}*Dvh4E>SyZ8^H)zDt!ZOIc>IG# Yy!pbnPeQl#>;VaSy85}Sb4q9e098wkvH$=8