How to use the @taquito/utils.prefix.sig function in @taquito/utils

To help you get started, we’ve selected a few @taquito/utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ecadlabs / taquito / packages / taquito-tezbridge-signer / src / taquito-tezbridge-signer.ts View on Github external
async sign(bytes: string, _watermark?: Uint8Array) {
    const prefixSig = await tezbridge.request({
      method: 'raw_sign',
      bytes, // Any operation bytes as string
    });

    const decoded = b58cdecode(prefixSig, prefix[prefixSig.substr(0, 5)]);

    return {
      bytes,
      sig: b58cencode(decoded, prefix.sig),
      prefixSig,
      sbytes: bytes + buf2hex(toBuffer(decoded)),
    };
  }
}
github ecadlabs / taquito / packages / taquito-signer / src / ec-key.ts View on Github external
async sign(bytes: string, bytesHash: Uint8Array) {
    const key = new elliptic.ec(this.curve).keyFromPrivate(this._key);
    const sig = key.sign(bytesHash, { canonical: true });
    const signature = new Uint8Array(sig.r.toArray().concat(sig.s.toArray()));
    const signatureBuffer = toBuffer(signature);
    const sbytes = bytes + buf2hex(signatureBuffer);

    return {
      bytes,
      sig: b58cencode(signature, prefix.sig),
      prefixSig: b58cencode(signature, pref[this.curve].sig),
      sbytes,
    };
  }
github ecadlabs / taquito / packages / taquito-signer / src / ed-key.ts View on Github external
async sign(bytes: string, bytesHash: Uint8Array) {
    await this.isInit;
    const signature = sodium.crypto_sign_detached(
      new Uint8Array(bytesHash),
      new Uint8Array(this._key)
    );
    const signatureBuffer = toBuffer(signature);
    const sbytes = bytes + buf2hex(signatureBuffer);

    return {
      bytes,
      sig: b58cencode(signature, prefix.sig),
      prefixSig: b58cencode(signature, prefix.edsig),
      sbytes,
    };
  }
github ecadlabs / taquito / packages / taquito-remote-signer / src / taquito-remote-signer.ts View on Github external
try {
      let bb = hex2buf(bytes);
      if (typeof watermark !== 'undefined') {
        bb = mergebuf(watermark, bb);
      }
      const { signature } = await this.http.createRequest(
        { url: this.createURL(`/keys/${this.pkh}`), method: 'POST' },
        buf2hex(toBuffer(bb))
      );
      let pref = signature.startsWith('sig') ? signature.substr(0, 3) : signature.substr(0, 5);

      const decoded = b58cdecode(signature, prefix[pref]);

      return {
        bytes,
        sig: b58cencode(decoded, prefix.sig),
        prefixSig: signature,
        sbytes: bytes + buf2hex(toBuffer(decoded)),
      };
    } catch (ex) {
      if (ex instanceof HttpResponseError) {
        if (ex.status === STATUS_CODE.NOT_FOUND) {
          throw new KeyNotFoundError(`Key not found: ${this.pkh}`, ex);
        } else if (ex.status === STATUS_CODE.FORBIDDEN) {
          throw new OperationNotAuthorizedError('Signing Operation not authorized', ex);
        } else if (ex.status === STATUS_CODE.BAD_REQUEST) {
          throw new BadSigningDataError('Invalid data', ex, {
            bytes,
            watermark,
          });
        }
      }