-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First checks if the input is already a buffer that starts with the magic PSBT byte sequence. If not, it checks if the input is a base64- or hex-encoded string that starts with the PSBT header. This function is useful when reading a file or request that could be in any of the above formats. Issue: BTC-1351
- Loading branch information
1 parent
93e467c
commit dcc4d93
Showing
3 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import * as assert from 'assert'; | ||
|
||
import { toPsbtBuffer } from '../../../src/bitgo'; | ||
|
||
describe('bufferUtil', function () { | ||
function variants(data: Buffer | string): (Buffer | string)[] { | ||
return [ | ||
data, | ||
data.toString('hex'), | ||
Buffer.from(data.toString('hex')), | ||
data.toString('base64'), | ||
Buffer.from(data.toString('base64')), | ||
]; | ||
} | ||
|
||
it('should convert a buffer to a string', function () { | ||
const psbt = Buffer.from('psbt\xff', 'ascii'); | ||
for (const v of variants(psbt)) { | ||
assert.ok(toPsbtBuffer(v).equals(psbt)); | ||
} | ||
|
||
const nonPsbt = Buffer.from('hello world', 'ascii'); | ||
for (const v of variants(nonPsbt)) { | ||
assert.throws(() => toPsbtBuffer(v)); | ||
} | ||
}); | ||
}); |