@mattrglobal/bls12381-key-pair
Advanced tools
Comparing version 0.3.1-unstable.c709887 to 0.3.1-unstable.dc79d57
@@ -1,6 +0,6 @@ | ||
## 0.3.1-unstable.c709887 (2020-05-25) | ||
## 0.3.1-unstable.dc79d57 (2020-06-22) | ||
## 0.3.1 (2020-05-25) | ||
## 0.3.1 (2020-06-22) | ||
@@ -7,0 +7,0 @@ |
@@ -45,2 +45,12 @@ import { KeyPairOptions, KeyPairSigner, KeyPairVerifier, GenerateKeyPairOptions } from "./types"; | ||
/** | ||
* Constructs a BLS 12-381 key pair from a public key fingerprint | ||
* @param fingerprint [Optional] public key fingerprint | ||
* | ||
* TODO this interface needs to be refactored, there should be no | ||
* hard coded notion of DIDs at this layer | ||
* | ||
* @returns A BLS 12-381 key pair | ||
*/ | ||
static fromFingerprint({ id, controller, fingerprint }: any): Bls12381G2KeyPair; | ||
/** | ||
* Returns a signer object for use with jsonld-signatures. | ||
@@ -47,0 +57,0 @@ * |
@@ -157,2 +157,46 @@ "use strict"; | ||
/** | ||
* Constructs a BLS 12-381 key pair from a public key fingerprint | ||
* @param fingerprint [Optional] public key fingerprint | ||
* | ||
* TODO this interface needs to be refactored, there should be no | ||
* hard coded notion of DIDs at this layer | ||
* | ||
* @returns A BLS 12-381 key pair | ||
*/ | ||
static fromFingerprint({ id, controller, fingerprint }) { | ||
if (fingerprint.substr(0, 1) != MULTIBASE_ENCODED_BASE58_IDENTIFIER) { | ||
throw new Error(`Unsupported fingerprint type: expected first character to be \`z\` indicating base58 encoding, received \`${fingerprint.substr(0, 1)}\``); | ||
} | ||
// parse of the multi-format public key removing the `z` that indicates base58 encoding | ||
const buffer = bs58_1.default.decode(fingerprint.substr(1)); | ||
if (buffer.length !== node_bbs_signatures_1.DEFAULT_BLS12381_PUBLIC_KEY_LENGTH + 2) { | ||
throw new Error(`Unsupported public key length: expected \`${node_bbs_signatures_1.DEFAULT_BLS12381_PUBLIC_KEY_LENGTH}\` received \`${buffer.length - | ||
2}\``); | ||
} | ||
if (buffer[0] !== BLS12381G2_MULTICODEC_IDENTIFIER) { | ||
throw new Error(`Unsupported public key identifier: expected second character to be \`${BLS12381G2_MULTICODEC_IDENTIFIER}\` indicating BLS12381G2 key pair, received \`${buffer[0]}\``); | ||
} | ||
if (buffer[1] !== VARIABLE_INTEGER_TRAILING_BYTE) { | ||
throw new Error(`Missing variable integer trailing byte: expected third character to be \`${VARIABLE_INTEGER_TRAILING_BYTE}\` indicating trailing integer, received \`${buffer[1]}\``); | ||
} | ||
const publicKeyBase58 = bs58_1.default.encode(buffer.slice(2)); | ||
//Defaults the controller to a DID key based controller | ||
if (!controller) { | ||
controller = `did:key:${Bls12381G2KeyPair.fingerprintFromPublicKey({ | ||
publicKeyBase58 | ||
})}`; | ||
} | ||
//Defaults the id to the did key based fragment | ||
if (!id) { | ||
id = `#${Bls12381G2KeyPair.fingerprintFromPublicKey({ | ||
publicKeyBase58 | ||
})}`; | ||
} | ||
return new Bls12381G2KeyPair({ | ||
id, | ||
controller, | ||
publicKeyBase58 | ||
}); | ||
} | ||
/** | ||
* Returns a signer object for use with jsonld-signatures. | ||
@@ -238,3 +282,4 @@ * | ||
// that it's multi-base encoded | ||
if (!(typeof fingerprint === "string" && fingerprint[0] === "z")) { | ||
if (!(typeof fingerprint === "string" && | ||
fingerprint[0] === MULTIBASE_ENCODED_BASE58_IDENTIFIER)) { | ||
return { | ||
@@ -241,0 +286,0 @@ error: new Error("`fingerprint` must be a multibase encoded string."), |
{ | ||
"name": "@mattrglobal/bls12381-key-pair", | ||
"version": "0.3.1-unstable.c709887", | ||
"version": "0.3.1-unstable.dc79d57", | ||
"description": "A library for using BLS 12-381 key pairs with BBS+ signatures", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/mattrglobal/bls12381-key-pair", |
@@ -5,2 +5,4 @@ ![Mattr logo](./docs/assets/mattr-black.svg) | ||
![npm-version](https://badgen.net/npm/v/@mattrglobal/bls12381-key-pair) | ||
![npm-unstable-version](https://badgen.net/npm/v/@mattrglobal/bls12381-key-pair/unstable) | ||
![push-master](https://github.com/mattrglobal/bls12381-key-pair/workflows/push-master/badge.svg) | ||
@@ -11,3 +13,3 @@ ![push-release](https://github.com/mattrglobal/bls12381-key-pair/workflows/push-release/badge.svg) | ||
This library supports generating [BLS12-381](https://tools.ietf.org/html/draft-irtf-cfrg-pairing-friendly-curves-02#section-2.4) key pairs and supports the | ||
signing and verification of BBS+ signatures. | ||
signing and verification of [BBS+ signatures](https://github.com/mattrglobal/bbs-signatures-spec). | ||
@@ -14,0 +16,0 @@ ## Getting started |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43880
3059
578
63