Files
psf-memo/psf-memo-client/test/support/script-encoding.js
T
Chris Troutner fac01730c4 Review multi-push encoding: fix browser Buffer and harden coverage
Import the browser-safe buffer module in the multi-push adapter so the
CRA production bundle no longer reads the Node global Buffer, add
regression tests for the falsy-wallet and idempotent-attach paths, share
the script-encoding test helper, and de-duplicate the UTF-8 push
acceptance assertions. Refresh the language mutation manifests and the
soft acceptance-mutation manifest.

By architect.
2026-09-16 21:31:23 -07:00

21 lines
579 B
JavaScript

/*
Test helper: encode a script the way Bitcoin does.
An opcode number is one byte; a Buffer/string becomes a length-prefixed push.
Enough to observe that the multi-push adapter produced the expected pushes.
Shared by the memo-multipush unit and property tests.
*/
'use strict'
function encodeScript (script) {
const parts = script.map((el) => {
if (typeof el === 'number') return Buffer.from([el])
const buf = Buffer.from(el)
return Buffer.concat([Buffer.from([buf.length]), buf])
})
return Buffer.concat(parts)
}
module.exports = { encodeScript }