diff --git a/modules/sdk-coin-avaxp/src/lib/permissionlessValidatorTxBuilder.ts b/modules/sdk-coin-avaxp/src/lib/permissionlessValidatorTxBuilder.ts index 4022b1afb5..91a902df80 100644 --- a/modules/sdk-coin-avaxp/src/lib/permissionlessValidatorTxBuilder.ts +++ b/modules/sdk-coin-avaxp/src/lib/permissionlessValidatorTxBuilder.ts @@ -329,8 +329,7 @@ export class PermissionlessValidatorTxBuilder extends TransactionBuilder { // delegating and validating have no fees const totalTarget = this._stakeAmount.valueOf(); - const credentials: Credential[] = []; - + const credentials: Credential[] = this.transaction.credentials ?? []; // Convert fromAddresses to string // The order of fromAddresses is determined by the source of the data // When building from params, the order is [user, bitgo, backup] @@ -407,24 +406,51 @@ export class PermissionlessValidatorTxBuilder extends TransactionBuilder { utxos.push(new Utxo(utxoId, assetId, transferInputs)); inputs.push(input); - if (buildOutputs) { - // For the bitgo signature we create an empty signature - // For the user/backup signature we store the address that matches the key - credentials.push( - new Credential([ - utils.createNewSig(BufferAvax.from(this.transaction._fromAddresses[userOrBackupIndex]).toString('hex')), - utils.createNewSig(BufferAvax.from('').toString('hex')), - ]) - ); - } else { - // TODO(CR-1073): verify this else case for OVC - credentials.push( - new Credential( - addressesIndex.map((i) => - utils.createNewSig(BufferAvax.from(this.transaction._fromAddresses[i]).toString('hex')) + if (!this.transaction.credentials || this.transaction.credentials.length == 0) { + if (buildOutputs) { + // For the bitgo signature we create an empty signature + // For the user/backup signature we store the address that matches the key + // if bitgo address comes before < user/backup address + + // TODO(CR-1073): remove log + console.log(`bitgo index on chain: ${utxo.addressesIndex[bitgoIndex]}`); + console.log(`user Or Backup Index: ${utxo.addressesIndex[userOrBackupIndex]}`); + if (utxo.addressesIndex[bitgoIndex] < utxo.addressesIndex[userOrBackupIndex]) { + // TODO(CR-1073): remove log + console.log(`user or backup credentials after bitgo`); + credentials.push( + new Credential([ + utils.createNewSig(BufferAvax.from('').toString('hex')), + utils.createNewSig( + BufferAvax.from(this.transaction._fromAddresses[userOrBackupIndex]).toString('hex') + ), + ]) + ); + } else { + // TODO(CR-1073): remove log + console.log(`user or backup credentials before bitgo`); + credentials.push( + new Credential([ + utils.createNewSig( + BufferAvax.from(this.transaction._fromAddresses[userOrBackupIndex]).toString('hex') + ), + utils.createNewSig(BufferAvax.from('').toString('hex')), + ]) + ); + } + } else { + // TODO(CR-1073): verify this else case for OVC + credentials.push( + new Credential( + addressesIndex.map((i) => + utils.createNewSig(BufferAvax.from(this.transaction._fromAddresses[i]).toString('hex')) + ) ) - ) - ); + ); + } + } else { + // TODO(CR-1073): remove log + console.log(`reusing credentials from transaction`); } } }); @@ -468,9 +494,8 @@ export class PermissionlessValidatorTxBuilder extends TransactionBuilder { } } } - const finalCredentials = this.transaction.credentials ?? credentials; inputs.sort((a, b) => avaxUtils.bytesCompare(a.utxoID.txID.toBytes(), b.utxoID.txID.toBytes())); - return { inputs, stakeOutputs, changeOutputs, utxos, credentials: finalCredentials }; + return { inputs, stakeOutputs, changeOutputs, utxos, credentials }; } /** diff --git a/modules/sdk-coin-avaxp/test/resources/avaxp.ts b/modules/sdk-coin-avaxp/test/resources/avaxp.ts index 72f1a608df..51d567eb49 100644 --- a/modules/sdk-coin-avaxp/test/resources/avaxp.ts +++ b/modules/sdk-coin-avaxp/test/resources/avaxp.ts @@ -571,9 +571,9 @@ export const BUILD_AND_SIGN_ADD_PERMISSIONLESS_SAMPLE = { halfSignedRawTxNonRecovery: '0x00000000000c000000050000000000000000000000000000000000000000000000000000000000000000000000013d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa00000007000000000baeb9000000000000000000000000020000000342e19ad9a617fb95dcf8843ade66e06e578f549a8be54f016ab748127ab1a184626cba44c748a1eeac03c0ca71a1dde84702d272fbdd086001867012000000024f194d8e066b11dfe92f593cfa5c2fa1ae450927ecd5b093952e61834f4d8aa4000000013d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa000000050000000023a4c1800000000200000000000000024f194d8e066b11dfe92f593cfa5c2fa1ae450927ecd5b093952e61834f4d8aa4000000013d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa000000050000000023a4c1800000000200000000000000020000000094a8b8179f0b6e7e7ce55b4d6ec5ad56dae1de9f0000000062bb03e60000000062e32556000000003b9aca00000000013d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa00000007000000003b9aca000000000000000000000000020000000342e19ad9a617fb95dcf8843ade66e06e578f549a8be54f016ab748127ab1a184626cba44c748a1eeac03c0ca71a1dde84702d272fbdd0860018670120000000b0000000000000000000000020000000342e19ad9a617fb95dcf8843ade66e06e578f549a8be54f016ab748127ab1a184626cba44c748a1eeac03c0ca71a1dde84702d272fbdd086001867012000186a000000002000000090000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007cd1d8802e15894ee973ebba974d3965b3cc42d4963470d0b7fc7460d14aa5d97f567e4fe9ec2d1f80c9802ef0e37cbe216b09c6613991fe299954fe03702c5000000000090000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007cd1d8802e15894ee973ebba974d3965b3cc42d4963470d0b7fc7460d14aa5d97f567e4fe9ec2d1f80c9802ef0e37cbe216b09c6613991fe299954fe03702c5000f8dfbe9f', unsignedRawtxRecovery: - '0x000000000019000000050000000000000000000000000000000000000000000000000000000000000000000000013d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa00000007000000000baeb9000000000000000000000000020000000342e19ad9a617fb95dcf8843ade66e06e578f549a8be54f016ab748127ab1a184626cba44c748a1eeac03c0ca71a1dde84702d272fbdd086001867012000000024f194d8e066b11dfe92f593cfa5c2fa1ae450927ecd5b093952e61834f4d8aa4000000013d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa000000050000000023a4c1800000000200000000000000014f194d8e066b11dfe92f593cfa5c2fa1ae450927ecd5b093952e61834f4d8aa4000000013d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa000000050000000023a4c1800000000200000000000000010000000094a8b8179f0b6e7e7ce55b4d6ec5ad56dae1de9f0000000062bb03e60000000062e32556000000003b9aca0000000000000000000000000000000000000000000000000000000000000000000000001c8f95423f7142d00a48e1014a3de8d28907d420dc33b3052a6dee03a3f2941a393c2351e354704ca66a3fc29870282e1586a3ab4c45cfe31cae34c1d06f212434ac71b1be6cfe046c80c162e057614a94a5bc9f1ded1a7029deb0ba4ca7c9b71411e293438691be79c2dbf19d1ca7c3eadb9c756246fc5de5b7b89511c7d7302ae051d9e03d7991138299b5ed6a570a98000000013d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa00000007000000003b9aca000000000000000000000000020000000342e19ad9a617fb95dcf8843ade66e06e578f549a8be54f016ab748127ab1a184626cba44c748a1eeac03c0ca71a1dde84702d272fbdd0860018670120000000b0000000000000000000000020000000342e19ad9a617fb95dcf8843ade66e06e578f549a8be54f016ab748127ab1a184626cba44c748a1eeac03c0ca71a1dde84702d272fbdd0860018670120000000b0000000000000000000000020000000342e19ad9a617fb95dcf8843ade66e06e578f549a8be54f016ab748127ab1a184626cba44c748a1eeac03c0ca71a1dde84702d272fbdd08600186701200030d400000000200000009000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008be54f016ab748127ab1a184626cba44c748a1ee000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008be54f016ab748127ab1a184626cba44c748a1ee000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003bbb49e', + '0x000000000019000000050000000000000000000000000000000000000000000000000000000000000000000000013d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa00000007000000000baeb9000000000000000000000000020000000342e19ad9a617fb95dcf8843ade66e06e578f549a8be54f016ab748127ab1a184626cba44c748a1eeac03c0ca71a1dde84702d272fbdd086001867012000000024f194d8e066b11dfe92f593cfa5c2fa1ae450927ecd5b093952e61834f4d8aa4000000013d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa000000050000000023a4c1800000000200000000000000014f194d8e066b11dfe92f593cfa5c2fa1ae450927ecd5b093952e61834f4d8aa4000000013d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa000000050000000023a4c1800000000200000000000000010000000094a8b8179f0b6e7e7ce55b4d6ec5ad56dae1de9f0000000062bb03e60000000062e32556000000003b9aca0000000000000000000000000000000000000000000000000000000000000000000000001c8f95423f7142d00a48e1014a3de8d28907d420dc33b3052a6dee03a3f2941a393c2351e354704ca66a3fc29870282e1586a3ab4c45cfe31cae34c1d06f212434ac71b1be6cfe046c80c162e057614a94a5bc9f1ded1a7029deb0ba4ca7c9b71411e293438691be79c2dbf19d1ca7c3eadb9c756246fc5de5b7b89511c7d7302ae051d9e03d7991138299b5ed6a570a98000000013d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa00000007000000003b9aca000000000000000000000000020000000342e19ad9a617fb95dcf8843ade66e06e578f549a8be54f016ab748127ab1a184626cba44c748a1eeac03c0ca71a1dde84702d272fbdd0860018670120000000b0000000000000000000000020000000342e19ad9a617fb95dcf8843ade66e06e578f549a8be54f016ab748127ab1a184626cba44c748a1eeac03c0ca71a1dde84702d272fbdd0860018670120000000b0000000000000000000000020000000342e19ad9a617fb95dcf8843ade66e06e578f549a8be54f016ab748127ab1a184626cba44c748a1eeac03c0ca71a1dde84702d272fbdd08600186701200030d4000000002000000090000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008be54f016ab748127ab1a184626cba44c748a1ee000000090000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008be54f016ab748127ab1a184626cba44c748a1ee2145400a', halfSignedRawTxRecovery: - '0x000000000019000000050000000000000000000000000000000000000000000000000000000000000000000000013d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa00000007000000000baeb9000000000000000000000000020000000342e19ad9a617fb95dcf8843ade66e06e578f549a8be54f016ab748127ab1a184626cba44c748a1eeac03c0ca71a1dde84702d272fbdd086001867012000000024f194d8e066b11dfe92f593cfa5c2fa1ae450927ecd5b093952e61834f4d8aa4000000013d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa000000050000000023a4c1800000000200000000000000014f194d8e066b11dfe92f593cfa5c2fa1ae450927ecd5b093952e61834f4d8aa4000000013d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa000000050000000023a4c1800000000200000000000000010000000094a8b8179f0b6e7e7ce55b4d6ec5ad56dae1de9f0000000062bb03e60000000062e32556000000003b9aca0000000000000000000000000000000000000000000000000000000000000000000000001c8f95423f7142d00a48e1014a3de8d28907d420dc33b3052a6dee03a3f2941a393c2351e354704ca66a3fc29870282e1586a3ab4c45cfe31cae34c1d06f212434ac71b1be6cfe046c80c162e057614a94a5bc9f1ded1a7029deb0ba4ca7c9b71411e293438691be79c2dbf19d1ca7c3eadb9c756246fc5de5b7b89511c7d7302ae051d9e03d7991138299b5ed6a570a98000000013d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa00000007000000003b9aca000000000000000000000000020000000342e19ad9a617fb95dcf8843ade66e06e578f549a8be54f016ab748127ab1a184626cba44c748a1eeac03c0ca71a1dde84702d272fbdd0860018670120000000b0000000000000000000000020000000342e19ad9a617fb95dcf8843ade66e06e578f549a8be54f016ab748127ab1a184626cba44c748a1eeac03c0ca71a1dde84702d272fbdd0860018670120000000b0000000000000000000000020000000342e19ad9a617fb95dcf8843ade66e06e578f549a8be54f016ab748127ab1a184626cba44c748a1eeac03c0ca71a1dde84702d272fbdd08600186701200030d400000000200000009000000028cfd7500ceacfcbae29e3f5e103ad932121a1e7f30f0c499faab1b721dc687424274ae4676e12edc7f90b2ba2d4722acfb8e13468e99fff2e3e4566fc9490edb01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009000000028cfd7500ceacfcbae29e3f5e103ad932121a1e7f30f0c499faab1b721dc687424274ae4676e12edc7f90b2ba2d4722acfb8e13468e99fff2e3e4566fc9490edb010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000fba08673', + '0x000000000019000000050000000000000000000000000000000000000000000000000000000000000000000000013d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa00000007000000000baeb9000000000000000000000000020000000342e19ad9a617fb95dcf8843ade66e06e578f549a8be54f016ab748127ab1a184626cba44c748a1eeac03c0ca71a1dde84702d272fbdd086001867012000000024f194d8e066b11dfe92f593cfa5c2fa1ae450927ecd5b093952e61834f4d8aa4000000013d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa000000050000000023a4c1800000000200000000000000014f194d8e066b11dfe92f593cfa5c2fa1ae450927ecd5b093952e61834f4d8aa4000000013d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa000000050000000023a4c1800000000200000000000000010000000094a8b8179f0b6e7e7ce55b4d6ec5ad56dae1de9f0000000062bb03e60000000062e32556000000003b9aca0000000000000000000000000000000000000000000000000000000000000000000000001c8f95423f7142d00a48e1014a3de8d28907d420dc33b3052a6dee03a3f2941a393c2351e354704ca66a3fc29870282e1586a3ab4c45cfe31cae34c1d06f212434ac71b1be6cfe046c80c162e057614a94a5bc9f1ded1a7029deb0ba4ca7c9b71411e293438691be79c2dbf19d1ca7c3eadb9c756246fc5de5b7b89511c7d7302ae051d9e03d7991138299b5ed6a570a98000000013d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa00000007000000003b9aca000000000000000000000000020000000342e19ad9a617fb95dcf8843ade66e06e578f549a8be54f016ab748127ab1a184626cba44c748a1eeac03c0ca71a1dde84702d272fbdd0860018670120000000b0000000000000000000000020000000342e19ad9a617fb95dcf8843ade66e06e578f549a8be54f016ab748127ab1a184626cba44c748a1eeac03c0ca71a1dde84702d272fbdd0860018670120000000b0000000000000000000000020000000342e19ad9a617fb95dcf8843ade66e06e578f549a8be54f016ab748127ab1a184626cba44c748a1eeac03c0ca71a1dde84702d272fbdd08600186701200030d4000000002000000090000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008cfd7500ceacfcbae29e3f5e103ad932121a1e7f30f0c499faab1b721dc687424274ae4676e12edc7f90b2ba2d4722acfb8e13468e99fff2e3e4566fc9490edb01000000090000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008cfd7500ceacfcbae29e3f5e103ad932121a1e7f30f0c499faab1b721dc687424274ae4676e12edc7f90b2ba2d4722acfb8e13468e99fff2e3e4566fc9490edb01e3b1dcd9', userPrivateKey: 'xprv9xhdWP2xkT2o3vMjkWv1oxPUHvVLvSuGJYLA72MpuM5dBykYsBdzRB8uxcYiiLWvP8Z6Vjiq2wc4HfGtgedgNPSv85mebXPKHp7ov9eRzRK', backupPrivateKey: