Skip to content

Commit

Permalink
Add new preimage length byte to search string for replacing the preimage
Browse files Browse the repository at this point in the history
  • Loading branch information
sisou committed Nov 22, 2024
1 parent 9a46fd2 commit 71d3752
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/NimiqAssetAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,19 @@ export class NimiqAssetAdapter implements AssetAdapter<SwapAsset.NIM> {
secret: string,
hash: string,
): Promise<TransactionDetails> {
// HTLC proofs in Albatross include a preimage length byte
const preImageLength = (secret.length / 2).toString(16).padStart(2, '0');
const dummyPreImage = ''.padEnd(secret.length, '0');
serializedTx = serializedTx
.replace(
`${hash}0000000000000000000000000000000000000000000000000000000000000000`,
`${hash}${secret}`,
`${hash}${preImageLength}${dummyPreImage}`,
`${hash}${preImageLength}${secret}`,
)
// Also handle "valid" transactions, where the hashRoot is the hash of the dummy secret
.replace(
'66687aadf862bd776c8fc18b8e9f8e20089714856ee233b3902a591d0d5f2925' // SHA256 hash of dummy secret
+ '0000000000000000000000000000000000000000000000000000000000000000', // Dummy secret
`${hash}${secret}`,
// SHA256 hash of 32-byte dummy secret
`66687aadf862bd776c8fc18b8e9f8e20089714856ee233b3902a591d0d5f2925${preImageLength}${dummyPreImage}`,
`${hash}${preImageLength}${secret}`,
);
return this.sendTransaction(serializedTx);
}
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// "incremental": true, /* Enable incremental compilation */
"target": "ES2017", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "es2015", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
"lib": ["ES6", "DOM"], /* Specify library files to be included in the compilation. */
"lib": ["ES2017", "DOM"], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
Expand Down

0 comments on commit 71d3752

Please sign in to comment.