本文整理汇总了TypeScript中bitcoinjs-lib.address类的典型用法代码示例。如果您正苦于以下问题:TypeScript address类的具体用法?TypeScript address怎么用?TypeScript address使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了address类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: makeNameImportSkeleton
export function makeNameImportSkeleton(name: string, recipientAddr: string, zonefileHash: string) {
/*
Format:
0 2 3 39
|----|--|-----------------------------|
magic op name.ns_id (37 bytes)
Output 0: the OP_RETURN
Output 1: the recipient
Output 2: the zonefile hash
*/
if (zonefileHash.length !== 40) {
throw new Error('Invalid zonefile hash: must be 20 bytes hex-encoded')
}
const network = config.network
const opReturnBuffer = Buffer.alloc(3 + name.length)
opReturnBuffer.write(opEncode(';'), 0, 3, 'ascii')
opReturnBuffer.write(name, 3, name.length, 'ascii')
const nullOutput = bitcoin.payments.embed({ data: [opReturnBuffer] }).output
const tx = makeTXbuilder()
const zonefileHashB58 = bitcoin.address.toBase58Check(
Buffer.from(zonefileHash, 'hex'), network.layer1.pubKeyHash
)
tx.addOutput(nullOutput, 0)
tx.addOutput(recipientAddr, DUST_MINIMUM)
tx.addOutput(zonefileHashB58, DUST_MINIMUM)
return tx.buildIncomplete()
}
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:34,代码来源:skeletons.ts
示例2: checkTransaction
checkTransaction(transaction: string, address: string, amount: BitcoinUnit) : any {
let buffer = new Buffer(transaction, 'hex');
let t = bitcoin.Transaction.fromBuffer(buffer);
for (let out of t.outs) {
if (address === bitcoin.address.fromOutputScript(out.script) && amount.to('satoshis') <= out.value) {
return t.getId();
}
}
return false;
}
开发者ID:Roli21,项目名称:bitpocket-mobile-app,代码行数:12,代码来源:electrum.ts
示例3: publicKeyToAddress
export function publicKeyToAddress(publicKey: string) {
const publicKeyBuffer = Buffer.from(publicKey, 'hex')
const publicKeyHash160 = bcrypto.hash160(publicKeyBuffer)
const address = baddress.toBase58Check(publicKeyHash160, 0x00)
return address
}
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:6,代码来源:keys.ts
示例4: makeNamespacePreorderSkeleton
export function makeNamespacePreorderSkeleton(
namespaceID: string, consensusHash: string, preorderAddress: string,
registerAddress: string, burn: AmountType
) {
// Returns a namespace preorder tx skeleton.
// Returns an unsigned serialized transaction.
/*
Formats:
Without STACKS:
0 2 3 23 39
|-----|---|--------------------------------------|----------------|
magic op hash(ns_id,script_pubkey,reveal_addr) consensus hash
with STACKs:
0 2 3 23 39 47
|-----|---|--------------------------------------|----------------|--------------------------|
magic op hash(ns_id,script_pubkey,reveal_addr) consensus hash token fee (big-endian)
output 0: namespace preorder code
output 1: change address
otuput 2: burn address
*/
const burnAmount = asAmountV2(burn)
if (burnAmount.units !== 'BTC' && burnAmount.units !== 'STACKS') {
throw new Error(`Invalid burnUnits ${burnAmount.units}`)
}
const network = config.network
const burnAddress = network.getDefaultBurnAddress()
const namespaceIDBuff = Buffer.from(decodeB40(namespaceID), 'hex') // base40
const scriptPublicKey = bitcoin.address.toOutputScript(preorderAddress, network.layer1)
const registerBuff = Buffer.from(registerAddress, 'ascii')
const dataBuffers = [namespaceIDBuff, scriptPublicKey, registerBuff]
const dataBuff = Buffer.concat(dataBuffers)
const hashed = hash160(dataBuff)
let btcBurnAmount = DUST_MINIMUM
let opReturnBufferLen = 39
if (burnAmount.units === 'STACKS') {
opReturnBufferLen = 47
} else {
btcBurnAmount = burnAmount.amount.toNumber()
}
const opReturnBuffer = Buffer.alloc(opReturnBufferLen)
opReturnBuffer.write(opEncode('*'), 0, 3, 'ascii')
hashed.copy(opReturnBuffer, 3)
opReturnBuffer.write(consensusHash, 23, 16, 'hex')
if (burnAmount.units === 'STACKS') {
const burnHex = burnAmount.amount.toString(16, 2)
const paddedBurnHex = `0000000000000000${burnHex}`.slice(-16)
opReturnBuffer.write(paddedBurnHex, 39, 8, 'hex')
}
const nullOutput = bitcoin.payments.embed({ data: [opReturnBuffer] }).output
const tx = makeTXbuilder()
tx.addOutput(nullOutput, 0)
tx.addOutput(preorderAddress, DUST_MINIMUM)
tx.addOutput(burnAddress, btcBurnAmount)
return tx.buildIncomplete()
}
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:71,代码来源:skeletons.ts
示例5: makePreorderSkeleton
export function makePreorderSkeleton(
fullyQualifiedName: string, consensusHash: string, preorderAddress: string,
burnAddress: string, burn: AmountType,
registerAddress: string = null
) {
// Returns a preorder tx skeleton.
// with 3 outputs : 1. the Blockstack Preorder OP_RETURN data
// 2. the Preorder's change address (5500 satoshi minimum)
// 3. the BURN
//
// 0 2 3 23 39 47 66
// |-----|--|--------------------------------------|--------------|-----------|-------------|
// magic op hash160(fqn,scriptPubkey,registerAddr) consensus hash token burn token type
// (optional) (optional)
//
// output 0: name preorder code
// output 1: preorder address
// output 2: burn address
//
// Returns an unsigned serialized transaction.
const burnAmount = asAmountV2(burn)
const network = config.network
const nameBuff = Buffer.from(decodeB40(fullyQualifiedName), 'hex') // base40
const scriptPublicKey = bitcoin.address.toOutputScript(preorderAddress, network.layer1)
const dataBuffers = [nameBuff, scriptPublicKey]
if (!!registerAddress) {
const registerBuff = Buffer.from(registerAddress, 'ascii')
dataBuffers.push(registerBuff)
}
const dataBuff = Buffer.concat(dataBuffers)
const hashed = hash160(dataBuff)
const opReturnBufferLen = burnAmount.units === 'BTC' ? 39 : 66
const opReturnBuffer = Buffer.alloc(opReturnBufferLen)
opReturnBuffer.write(opEncode('?'), 0, 3, 'ascii')
hashed.copy(opReturnBuffer, 3)
opReturnBuffer.write(consensusHash, 23, 16, 'hex')
if (burnAmount.units !== 'BTC') {
const burnHex = burnAmount.amount.toString(16, 2)
if (burnHex.length > 16) {
// exceeds 2**64; can't fit
throw new Error(`Cannot preorder '${fullyQualifiedName}': cannot fit price into 8 bytes`)
}
const paddedBurnHex = `0000000000000000${burnHex}`.slice(-16)
opReturnBuffer.write(paddedBurnHex, 39, 8, 'hex')
opReturnBuffer.write(burnAmount.units, 47, burnAmount.units.length, 'ascii')
}
const nullOutput = bitcoin.payments.embed({ data: [opReturnBuffer] }).output
const tx = makeTXbuilder()
tx.addOutput(nullOutput, 0)
tx.addOutput(preorderAddress, DUST_MINIMUM)
if (burnAmount.units === 'BTC') {
const btcBurnAmount = burnAmount.amount.toNumber()
tx.addOutput(burnAddress, btcBurnAmount)
} else {
tx.addOutput(burnAddress, DUST_MINIMUM)
}
return tx.buildIncomplete()
}
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:69,代码来源:skeletons.ts
示例6: ecPairToAddress
export function ecPairToAddress(keyPair: ECPair) {
return address.toBase58Check(crypto.hash160(keyPair.publicKey), keyPair.network.pubKeyHash)
}
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:3,代码来源:utils.ts
注:本文中的bitcoinjs-lib.address类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论