opnet
Version:
The perfect library for building Bitcoin-based applications.
28 lines (27 loc) • 910 B
JavaScript
import { fromBase64, fromHex } from '@btc-vision/bitcoin';
import { BufferHelper } from '@btc-vision/transaction';
export class StoredValue {
pointer;
value;
height;
proofs;
constructor(iStoredValue) {
this.pointer =
typeof iStoredValue.pointer === 'string'
? this.base64ToBigInt(iStoredValue.pointer)
: iStoredValue.pointer;
if (typeof iStoredValue.value !== 'string') {
this.value = iStoredValue.value;
}
else {
this.value = iStoredValue.value.startsWith('0x')
? fromHex(iStoredValue.value.slice(2))
: fromBase64(iStoredValue.value);
}
this.height = BigInt(iStoredValue.height);
this.proofs = iStoredValue.proofs || [];
}
base64ToBigInt(base64) {
return BufferHelper.uint8ArrayToPointer(fromBase64(base64));
}
}