How to use the tweetnacl.sign.keyPair function in tweetnacl

To help you get started, we’ve selected a few tweetnacl 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 rchain / rchain-api / signing.js View on Github external
function keyPair(seed) {
  const key = sign.keyPair.fromSeed(seed);

  // TODO const toString = () => ``;
  const signBytes = bytes => sign.detached(bytes, key.secretKey);

  return def({
    // TODO toString,
    signBytes,
    signBytesHex: bytes => b2h(signBytes(bytes)),
    signText: text => signBytes(t2b(text)),
    signTextHex: text => b2h(signBytes(t2b(text))),
    publicKey: () => b2h(key.publicKey),
    // TODO label: () => state.label,
    // TODO [inspect.custom]: toString
  });
}
github rchain-community / rchain-dbr / o2r / gateway / server / keyPair.js View on Github external
function init(label) {
	    const key = sign.keyPair.fromSeed(randomBytes(32));

	    state = context.state;
	    state.label = label;
	    state.publicKey = b2h(key.publicKey);
	    state.secretKey = b2h(key.secretKey);
	}
github rchain-community / rchain-dbr / o2r / gateway / server / keyPair.js View on Github external
function privateKey() {
	    return sign.keyPair.fromSecretKey(h2b(state.secretKey)).secretKey;
	}
    }
github ArcBlock / forge-js / packages / mcrypto / lib / signer / ed25519.js View on Github external
getPublicKey(sk, encoding = 'hex') {
    const skBytes = toUint8Array(sk);
    const pk = ed25519.keyPair.fromSecretKey(skBytes).publicKey;
    return encode(pk, encoding);
  }
github fidm / x509 / src / pki.ts View on Github external
throw new Error('Cannot read X.509 private key: ' + err.message)
    }

    this.version = ASN1.parseIntegerNum(captures.privateKeyVersion.bytes) + 1
    this.oid = ASN1.parseOID(captures.privateKeyOID.bytes)
    this.algo = getOIDName(this.oid)
    this._pkcs8 = obj
    this._keyRaw = captures.privateKey.bytes
    this._publicKeyRaw = null
    this._finalKey = this._keyRaw
    this._finalPEM = ''

    if (EdDSAPrivateKeyOIDs.includes(this.oid)) {
      this._finalKey = this._keyRaw = ASN1.parseDER(this._keyRaw, Class.UNIVERSAL, Tag.OCTETSTRING).bytes
      if (this.oid === '1.3.101.112') {
        const keypair = ed25519.keyPair.fromSeed(this._keyRaw)
        this._publicKeyRaw = Buffer.from(keypair.publicKey)
        this._finalKey = Buffer.from(keypair.secretKey)
      } else if (this.version === 2) {
        for (const val of obj.mustCompound()) {
          if (val.class === Class.CONTEXT_SPECIFIC && val.tag === 1) {
            this._publicKeyRaw = ASN1.parseBitString(val.bytes).buf
            this._finalKey = Buffer.concat([this._keyRaw, this._publicKeyRaw as Buffer])
          }
        }
      }
    }
  }