• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript typeforce.default函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中typeforce.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了default函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: fromPrivateKey

function fromPrivateKey(buffer: Buffer, options?: ECPairOptions): ECPair {
  typeforce(types.Buffer256bit, buffer);
  if (!ecc.isPrivate(buffer))
    throw new TypeError('Private key not in range [1, n)');
  typeforce(isOptions, options);

  return new ECPair(buffer, undefined, options as ECPairOptions);
}
开发者ID:bitcoinjs,项目名称:bitcoinjs-lib,代码行数:8,代码来源:ecpair.ts


示例2: makeRandom

function makeRandom(options?: ECPairOptions): ECPair {
  typeforce(isOptions, options);
  if (options === undefined) options = {};
  const rng = options.rng || randomBytes;

  let d;
  do {
    d = rng(32);
    typeforce(types.Buffer256bit, d);
  } while (!ecc.isPrivate(d));

  return fromPrivateKey(d, options);
}
开发者ID:bitcoinjs,项目名称:bitcoinjs-lib,代码行数:13,代码来源:ecpair.ts


示例3: check

export function check(chunks: Buffer[], allowIncomplete?: boolean): boolean {
  typeforce(typeforce.Array, chunks);
  if (chunks.length < 1) return false;

  const witnessScript = chunks[chunks.length - 1];
  if (!Buffer.isBuffer(witnessScript)) return false;

  const witnessScriptChunks = bscript.decompile(witnessScript);

  // is witnessScript a valid script?
  if (!witnessScriptChunks || witnessScriptChunks.length === 0) return false;

  const witnessRawScriptSig = bscript.compile(chunks.slice(0, -1));

  // match types
  if (
    p2pkh.input.check(witnessRawScriptSig) &&
    p2pkh.output.check(witnessScriptChunks)
  )
    return true;

  if (
    p2ms.input.check(witnessRawScriptSig, allowIncomplete) &&
    p2ms.output.check(witnessScriptChunks)
  )
    return true;

  if (
    p2pk.input.check(witnessRawScriptSig) &&
    p2pk.output.check(witnessScriptChunks)
  )
    return true;

  return false;
}
开发者ID:bitcoinjs,项目名称:bitcoinjs-lib,代码行数:35,代码来源:input.ts


示例4: typeforce

    asm.split(' ').map(chunkStr => {
      // opcode?
      if (OPS[chunkStr] !== undefined) return OPS[chunkStr];
      typeforce(types.Hex, chunkStr);

      // data!
      return Buffer.from(chunkStr, 'hex');
    }),
开发者ID:bitcoinjs,项目名称:bitcoinjs-lib,代码行数:8,代码来源:script.ts


示例5: typeforce

export function toBase58Check(hash: Buffer, version: number, bs58check: Base58Check = bs58checkWithsha256): string {
  typeforce(types.tuple(types.Hash160bit, types.UInt8), arguments);

  const payload = Buffer.allocUnsafe(21);
  payload.writeUInt8(version, 0);
  hash.copy(payload, 1);

  return bs58check.encode(payload);
}
开发者ID:sbwdlihao,项目名称:bitcoinjs-lib,代码行数:9,代码来源:address.ts


示例6: encode

export function encode(commitment: Buffer): Buffer {
  typeforce(types.Hash256bit, commitment);

  const buffer = Buffer.allocUnsafe(36);
  HEADER.copy(buffer, 0);
  commitment.copy(buffer, 4);

  return bscript.compile([OPS.OP_RETURN, buffer]);
}
开发者ID:bitcoinjs,项目名称:bitcoinjs-lib,代码行数:9,代码来源:output.ts


示例7: toStack

export function toStack(chunks: Buffer | Array<number | Buffer>): Buffer[] {
  chunks = decompile(chunks) as Stack;
  typeforce(isPushOnly, chunks);

  return chunks.map(op => {
    if (singleChunkIsBuffer(op)) return op;
    if (op === OPS.OP_0) return Buffer.allocUnsafe(0);

    return scriptNumber.encode(op - OP_INT_BASE);
  });
}
开发者ID:bitcoinjs,项目名称:bitcoinjs-lib,代码行数:11,代码来源:script.ts


示例8: fromASM

export function fromASM(asm: string): Buffer {
  typeforce(types.String, asm);

  return compile(
    asm.split(' ').map(chunkStr => {
      // opcode?
      if (OPS[chunkStr] !== undefined) return OPS[chunkStr];
      typeforce(types.Hex, chunkStr);

      // data!
      return Buffer.from(chunkStr, 'hex');
    }),
  );
}
开发者ID:bitcoinjs,项目名称:bitcoinjs-lib,代码行数:14,代码来源:script.ts


示例9: compile

export function compile(chunks: Buffer | Stack): Buffer {
  // TODO: remove me
  if (chunksIsBuffer(chunks)) return chunks;

  typeforce(types.Array, chunks);

  const bufferSize = chunks.reduce((accum: number, chunk) => {
    // data chunk
    if (singleChunkIsBuffer(chunk)) {
      // adhere to BIP62.3, minimal push policy
      if (chunk.length === 1 && asMinimalOP(chunk) !== undefined) {
        return accum + 1;
      }

      return accum + pushdata.encodingLength(chunk.length) + chunk.length;
    }

    // opcode
    return accum + 1;
  }, 0.0);

  const buffer = Buffer.allocUnsafe(bufferSize);
  let offset = 0;

  chunks.forEach(chunk => {
    // data chunk
    if (singleChunkIsBuffer(chunk)) {
      // adhere to BIP62.3, minimal push policy
      const opcode = asMinimalOP(chunk);
      if (opcode !== undefined) {
        buffer.writeUInt8(opcode, offset);
        offset += 1;
        return;
      }

      offset += pushdata.encode(buffer, chunk.length, offset);
      chunk.copy(buffer, offset);
      offset += chunk.length;

      // opcode
    } else {
      buffer.writeUInt8(chunk, offset);
      offset += 1;
    }
  });

  if (offset !== buffer.length) throw new Error('Could not decode chunks');
  return buffer;
}
开发者ID:bitcoinjs,项目名称:bitcoinjs-lib,代码行数:49,代码来源:script.ts


示例10: decompile

export function decompile(
  buffer: Buffer | Array<number | Buffer>,
): Array<number | Buffer> | null {
  // TODO: remove me
  if (chunksIsArray(buffer)) return buffer;

  typeforce(types.Buffer, buffer);

  const chunks: Array<number | Buffer> = [];
  let i = 0;

  while (i < buffer.length) {
    const opcode = buffer[i];

    // data chunk
    if (opcode > OPS.OP_0 && opcode <= OPS.OP_PUSHDATA4) {
      const d = pushdata.decode(buffer, i);

      // did reading a pushDataInt fail?
      if (d === null) return null;
      i += d.size;

      // attempt to read too much data?
      if (i + d.number > buffer.length) return null;

      const data = buffer.slice(i, i + d.number);
      i += d.number;

      // decompile minimally
      const op = asMinimalOP(data);
      if (op !== undefined) {
        chunks.push(op);
      } else {
        chunks.push(data);
      }

      // opcode
    } else {
      chunks.push(opcode);

      i += 1;
    }
  }

  return chunks;
}
开发者ID:bitcoinjs,项目名称:bitcoinjs-lib,代码行数:46,代码来源:script.ts



注:本文中的typeforce.default函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript typeforce.maybe函数代码示例发布时间:2022-05-25
下一篇:
TypeScript typeforce.arrayOf函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap