Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@transmute/did-key-bls12381

Package Overview
Dependencies
Maintainers
3
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@transmute/did-key-bls12381 - npm Package Compare versions

Comparing version 0.2.1-unstable.20 to 0.2.1-unstable.21

src/__fixtures__/README.md

8

CHANGELOG.md

@@ -6,2 +6,10 @@ # Change Log

## 0.2.1-unstable.21 (2020-09-28)
**Note:** Version bump only for package @transmute/did-key-bls12381
## 0.2.1-unstable.20 (2020-09-15)

@@ -8,0 +16,0 @@

20

dist/Bls12381G2KeyPair.d.ts

@@ -1,5 +0,17 @@

import * as mattr from '@mattrglobal/bls12381-key-pair';
export declare class Bls12381G2KeyPair extends mattr.Bls12381G2KeyPair {
static generate(options?: any): Promise<mattr.Bls12381G2KeyPair>;
static toKeyPair(key: any): any;
/// <reference types="node" />
export declare class Bls12381G2KeyPair {
id: string;
type: string;
controller: string;
publicKeyBuffer: Buffer;
privateKeyBuffer?: Buffer;
static generate(): Promise<Bls12381G2KeyPair>;
static fromFingerprint({ fingerprint }: any): Promise<Bls12381G2KeyPair>;
static from(options: any): Promise<Bls12381G2KeyPair>;
constructor(options: any);
fingerprint(): string;
toKeyPair(exportPrivateKey?: boolean): any;
toJsonWebKeyPair(exportPrivateKey?: boolean): any;
verifier(): import("@mattrglobal/bls12381-key-pair/lib/types").KeyPairVerifier;
signer(): import("@mattrglobal/bls12381-key-pair/lib/types").KeyPairSigner;
}

253

dist/did-key-bls12381.cjs.development.js

@@ -5,59 +5,7 @@ 'use strict';

function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var didKeyCommon = require('@transmute/did-key-common');
var mattr = require('@mattrglobal/bls12381-key-pair');
var bbsSignatures = require('@mattrglobal/bbs-signatures');
var bs58 = require('bs58');
var bs58__default = _interopDefault(bs58);
var bbsSignatures = require('@mattrglobal/bbs-signatures');
var keyToDidDoc = function keyToDidDoc(bls12381Key) {
var did = "did:key:" + bls12381Key.fingerprint();
var keyId = "#" + bls12381Key.fingerprint();
return {
'@context': ['https://www.w3.org/ns/did/v1', {
'@base': did
}],
id: did,
publicKey: [{
id: keyId,
type: bls12381Key.type,
controller: did,
publicKeyBase58: bs58__default.encode(bls12381Key.publicKeyBuffer)
}],
authentication: [keyId],
assertionMethod: [keyId],
capabilityDelegation: [keyId],
capabilityInvocation: [keyId]
};
};
var get = function get(_temp) {
var _ref = _temp === void 0 ? {} : _temp,
did = _ref.did,
url = _ref.url;
try {
did = did || url;
if (!did) {
throw new TypeError('"did" must be a string.');
}
var fingerprint = did.split('#')[0].split('did:key:').pop();
return Promise.resolve(mattr.Bls12381G2KeyPair.fromFingerprint({
fingerprint: fingerprint
})).then(function (publicKey) {
var didDoc = keyToDidDoc(publicKey);
return didDoc;
});
} catch (e) {
return Promise.reject(e);
}
};
var driver = {
__proto__: null,
keyToDidDoc: keyToDidDoc,
get: get
};
function _extends() {

@@ -81,21 +29,43 @@ _extends = Object.assign || function (target) {

function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
subClass.__proto__ = superClass;
}
var Bls12381G2KeyPair = /*#__PURE__*/function () {
function Bls12381G2KeyPair(options) {
this.type = 'Bls12381G2Key2020';
this.id = options.id;
this.type = options.type || 'Bls12381G2Key2020';
this.controller = options.controller;
var Bls12381G2KeyPair = /*#__PURE__*/function (_mattr$Bls12381G2KeyP) {
_inheritsLoose(Bls12381G2KeyPair, _mattr$Bls12381G2KeyP);
if (options.publicKeyBase58) {
this.publicKeyBuffer = bs58.decode(options.publicKeyBase58);
} else if (options.publicKeyJwk) {
this.publicKeyBuffer = Buffer.from('a');
} else {
throw new Error('Bls12381G2KeyPair requires publicKeyBase58 or publicKeyJwk, recieved neither.');
}
function Bls12381G2KeyPair() {
return _mattr$Bls12381G2KeyP.apply(this, arguments) || this;
if (options.privateKeyBase58) {
this.privateKeyBuffer = bs58.decode(options.privateKeyBase58);
}
if (!this.id) {
this.id = '#' + this.fingerprint();
}
if (!this.controller) {
this.controller = "did:key:" + this.fingerprint();
}
}
Bls12381G2KeyPair.generate = function generate(options) {
Bls12381G2KeyPair.generate = function generate() {
try {
var keyPair = bbsSignatures.generateBls12381KeyPair();
return Promise.resolve(Bls12381G2KeyPair.from(_extends({}, options, {
var options = {
privateKeyBase58: bs58.encode(keyPair.secretKey),
publicKeyBase58: bs58.encode(keyPair.publicKey)
};
var fingerprint = mattr.Bls12381G2KeyPair.fingerprintFromPublicKey({
publicKeyBase58: options.publicKeyBase58
});
return Promise.resolve(new Bls12381G2KeyPair(_extends({}, options, {
id: '#' + fingerprint,
controller: "did:key:" + fingerprint
})));

@@ -107,15 +77,107 @@ } catch (e) {

Bls12381G2KeyPair.toKeyPair = function toKeyPair(key) {
var fingerprint = Bls12381G2KeyPair.fingerprintFromPublicKey({
publicKeyBase58: bs58.encode(key.publicKeyBuffer)
Bls12381G2KeyPair.fromFingerprint = function fromFingerprint(_ref) {
var fingerprint = _ref.fingerprint;
try {
var keypair = mattr.Bls12381G2KeyPair.fromFingerprint({
fingerprint: fingerprint
});
var options = {
publicKeyBase58: bs58.encode(keypair.publicKeyBuffer)
};
return Promise.resolve(new Bls12381G2KeyPair(options));
} catch (e) {
return Promise.reject(e);
}
};
Bls12381G2KeyPair.from = function from(options) {
try {
var _temp9 = function _temp9() {
function _temp6() {
function _temp4() {
function _temp2() {
var _options = {
publicKeyBase58: bs58.encode(keypair.publicKeyBuffer)
};
if (keypair.privateKeyBuffer) {
_options.privateKeyBase58 = bs58.encode(keypair.privateKeyBuffer);
}
return new Bls12381G2KeyPair(_options);
}
var _temp = function () {
if (options.privateKeyBase58) {
return Promise.resolve(mattr.Bls12381G2KeyPair.from(options)).then(function (_mattr$Bls12381G2KeyP4) {
keypair = _mattr$Bls12381G2KeyP4;
});
}
}();
return _temp && _temp.then ? _temp.then(_temp2) : _temp2(_temp);
}
var _temp3 = function () {
if (options.publicKeyBase58) {
return Promise.resolve(mattr.Bls12381G2KeyPair.from(options)).then(function (_mattr$Bls12381G2KeyP3) {
keypair = _mattr$Bls12381G2KeyP3;
});
}
}();
return _temp3 && _temp3.then ? _temp3.then(_temp4) : _temp4(_temp3);
}
var _temp5 = function () {
if (options.privateKeyJwk) {
return Promise.resolve(mattr.Bls12381G2KeyPair.fromJwk(options)).then(function (_mattr$Bls12381G2KeyP2) {
keypair = _mattr$Bls12381G2KeyP2;
});
}
}();
return _temp5 && _temp5.then ? _temp5.then(_temp6) : _temp6(_temp5);
};
var keypair;
var _temp10 = function () {
if (options.publicKeyJwk) {
return Promise.resolve(mattr.Bls12381G2KeyPair.fromJwk(options)).then(function (_mattr$Bls12381G2KeyP) {
keypair = _mattr$Bls12381G2KeyP;
});
}
}();
return Promise.resolve(_temp10 && _temp10.then ? _temp10.then(_temp9) : _temp9(_temp10));
} catch (e) {
return Promise.reject(e);
}
};
var _proto = Bls12381G2KeyPair.prototype;
_proto.fingerprint = function fingerprint() {
var fingerprint = mattr.Bls12381G2KeyPair.fingerprintFromPublicKey({
publicKeyBase58: bs58.encode(this.publicKeyBuffer)
});
return fingerprint;
};
_proto.toKeyPair = function toKeyPair(exportPrivateKey) {
if (exportPrivateKey === void 0) {
exportPrivateKey = false;
}
var kp = {
id: '#' + fingerprint,
type: 'Bls12381G2Key2020',
controller: "did:key:" + fingerprint,
publicKeyBase58: bs58.encode(key.publicKeyBuffer)
id: this.id,
type: this.type,
controller: this.controller,
publicKeyBase58: bs58.encode(this.publicKeyBuffer)
};
if (key.privateKeyBuffer) {
kp.privateKeyBase58 = bs58.encode(key.privateKeyBuffer);
if (exportPrivateKey) {
kp.privateKeyBase58 = bs58.encode(this.privateKeyBuffer);
}

@@ -126,7 +188,48 @@

_proto.toJsonWebKeyPair = function toJsonWebKeyPair(exportPrivateKey) {
if (exportPrivateKey === void 0) {
exportPrivateKey = false;
}
var mattrKey = new mattr.Bls12381G2KeyPair(this.toKeyPair(exportPrivateKey));
var kp = {
id: this.id,
type: 'JsonWebKey2020',
controller: this.controller,
publicKeyJwk: mattrKey.publicKeyJwk
};
delete kp.publicKeyJwk.kid;
if (exportPrivateKey) {
kp.privateKeyJwk = mattrKey.privateKeyJwk;
delete kp.privateKeyJwk.kid;
}
return kp;
};
_proto.verifier = function verifier() {
var mattrKey = new mattr.Bls12381G2KeyPair(this.toKeyPair(false));
return mattrKey.verifier();
};
_proto.signer = function signer() {
var mattrKey = new mattr.Bls12381G2KeyPair(this.toKeyPair(true));
return mattrKey.signer();
};
return Bls12381G2KeyPair;
}(mattr.Bls12381G2KeyPair);
}();
var resolve = /*#__PURE__*/didKeyCommon.getResolve(Bls12381G2KeyPair);
var get = /*#__PURE__*/didKeyCommon.getGet(resolve);
var driver = {
__proto__: null,
resolve: resolve,
get: get
};
exports.Bls12381G2KeyPair = Bls12381G2KeyPair;
exports.driver = driver;
//# sourceMappingURL=did-key-bls12381.cjs.development.js.map

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,r=require("@mattrglobal/bls12381-key-pair"),t=require("bs58"),i=(e=t)&&"object"==typeof e&&"default"in e?e.default:e,n=require("@mattrglobal/bbs-signatures"),o=function(e){var r="did:key:"+e.fingerprint(),t="#"+e.fingerprint();return{"@context":["https://www.w3.org/ns/did/v1",{"@base":r}],id:r,publicKey:[{id:t,type:e.type,controller:r,publicKeyBase58:i.encode(e.publicKeyBuffer)}],authentication:[t],assertionMethod:[t],capabilityDelegation:[t],capabilityInvocation:[t]}},a={__proto__:null,keyToDidDoc:o,get:function(e){var t=void 0===e?{}:e,i=t.did,n=t.url;try{if(!(i=i||n))throw new TypeError('"did" must be a string.');var a=i.split("#")[0].split("did:key:").pop();return Promise.resolve(r.Bls12381G2KeyPair.fromFingerprint({fingerprint:a})).then((function(e){return o(e)}))}catch(e){return Promise.reject(e)}}};function c(){return(c=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e}).apply(this,arguments)}exports.Bls12381G2KeyPair=function(e){var r,i;function o(){return e.apply(this,arguments)||this}return i=e,(r=o).prototype=Object.create(i.prototype),r.prototype.constructor=r,r.__proto__=i,o.generate=function(e){try{var r=n.generateBls12381KeyPair();return Promise.resolve(o.from(c({},e,{privateKeyBase58:t.encode(r.secretKey),publicKeyBase58:t.encode(r.publicKey)})))}catch(e){return Promise.reject(e)}},o.toKeyPair=function(e){var r=o.fingerprintFromPublicKey({publicKeyBase58:t.encode(e.publicKeyBuffer)}),i={id:"#"+r,type:"Bls12381G2Key2020",controller:"did:key:"+r,publicKeyBase58:t.encode(e.publicKeyBuffer)};return e.privateKeyBuffer&&(i.privateKeyBase58=t.encode(e.privateKeyBuffer)),i},o}(r.Bls12381G2KeyPair),exports.driver=a;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@transmute/did-key-common"),r=require("@mattrglobal/bls12381-key-pair"),i=require("@mattrglobal/bbs-signatures"),t=require("bs58");function n(){return(n=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var i=arguments[r];for(var t in i)Object.prototype.hasOwnProperty.call(i,t)&&(e[t]=i[t])}return e}).apply(this,arguments)}var o=function(){function e(e){if(this.type="Bls12381G2Key2020",this.id=e.id,this.type=e.type||"Bls12381G2Key2020",this.controller=e.controller,e.publicKeyBase58)this.publicKeyBuffer=t.decode(e.publicKeyBase58);else{if(!e.publicKeyJwk)throw new Error("Bls12381G2KeyPair requires publicKeyBase58 or publicKeyJwk, recieved neither.");this.publicKeyBuffer=Buffer.from("a")}e.privateKeyBase58&&(this.privateKeyBuffer=t.decode(e.privateKeyBase58)),this.id||(this.id="#"+this.fingerprint()),this.controller||(this.controller="did:key:"+this.fingerprint())}e.generate=function(){try{var o=i.generateBls12381KeyPair(),s={privateKeyBase58:t.encode(o.secretKey),publicKeyBase58:t.encode(o.publicKey)},u=r.Bls12381G2KeyPair.fingerprintFromPublicKey({publicKeyBase58:s.publicKeyBase58});return Promise.resolve(new e(n({},s,{id:"#"+u,controller:"did:key:"+u})))}catch(e){return Promise.reject(e)}},e.fromFingerprint=function(i){var n=i.fingerprint;try{var o=r.Bls12381G2KeyPair.fromFingerprint({fingerprint:n}),s={publicKeyBase58:t.encode(o.publicKeyBuffer)};return Promise.resolve(new e(s))}catch(e){return Promise.reject(e)}},e.from=function(i){try{var n,o=function(){function o(){function o(){function o(){var r={publicKeyBase58:t.encode(n.publicKeyBuffer)};return n.privateKeyBuffer&&(r.privateKeyBase58=t.encode(n.privateKeyBuffer)),new e(r)}var s=function(){if(i.privateKeyBase58)return Promise.resolve(r.Bls12381G2KeyPair.from(i)).then((function(e){n=e}))}();return s&&s.then?s.then(o):o()}var s=function(){if(i.publicKeyBase58)return Promise.resolve(r.Bls12381G2KeyPair.from(i)).then((function(e){n=e}))}();return s&&s.then?s.then(o):o()}var s=function(){if(i.privateKeyJwk)return Promise.resolve(r.Bls12381G2KeyPair.fromJwk(i)).then((function(e){n=e}))}();return s&&s.then?s.then(o):o()},s=function(){if(i.publicKeyJwk)return Promise.resolve(r.Bls12381G2KeyPair.fromJwk(i)).then((function(e){n=e}))}();return Promise.resolve(s&&s.then?s.then(o):o())}catch(e){return Promise.reject(e)}};var o=e.prototype;return o.fingerprint=function(){return r.Bls12381G2KeyPair.fingerprintFromPublicKey({publicKeyBase58:t.encode(this.publicKeyBuffer)})},o.toKeyPair=function(e){void 0===e&&(e=!1);var r={id:this.id,type:this.type,controller:this.controller,publicKeyBase58:t.encode(this.publicKeyBuffer)};return e&&(r.privateKeyBase58=t.encode(this.privateKeyBuffer)),r},o.toJsonWebKeyPair=function(e){void 0===e&&(e=!1);var i=new r.Bls12381G2KeyPair(this.toKeyPair(e)),t={id:this.id,type:"JsonWebKey2020",controller:this.controller,publicKeyJwk:i.publicKeyJwk};return delete t.publicKeyJwk.kid,e&&(t.privateKeyJwk=i.privateKeyJwk,delete t.privateKeyJwk.kid),t},o.verifier=function(){return new r.Bls12381G2KeyPair(this.toKeyPair(!1)).verifier()},o.signer=function(){return new r.Bls12381G2KeyPair(this.toKeyPair(!0)).signer()},e}(),s=e.getResolve(o),u={__proto__:null,resolve:s,get:e.getGet(s)};exports.Bls12381G2KeyPair=o,exports.driver=u;
//# sourceMappingURL=did-key-bls12381.cjs.production.min.js.map

@@ -0,55 +1,6 @@

import { getResolve, getGet } from '@transmute/did-key-common';
import { Bls12381G2KeyPair as Bls12381G2KeyPair$1 } from '@mattrglobal/bls12381-key-pair';
import bs58__default, { encode } from 'bs58';
import { generateBls12381KeyPair } from '@mattrglobal/bbs-signatures';
import { encode, decode } from 'bs58';
var keyToDidDoc = function keyToDidDoc(bls12381Key) {
var did = "did:key:" + bls12381Key.fingerprint();
var keyId = "#" + bls12381Key.fingerprint();
return {
'@context': ['https://www.w3.org/ns/did/v1', {
'@base': did
}],
id: did,
publicKey: [{
id: keyId,
type: bls12381Key.type,
controller: did,
publicKeyBase58: bs58__default.encode(bls12381Key.publicKeyBuffer)
}],
authentication: [keyId],
assertionMethod: [keyId],
capabilityDelegation: [keyId],
capabilityInvocation: [keyId]
};
};
var get = function get(_temp) {
var _ref = _temp === void 0 ? {} : _temp,
did = _ref.did,
url = _ref.url;
try {
did = did || url;
if (!did) {
throw new TypeError('"did" must be a string.');
}
var fingerprint = did.split('#')[0].split('did:key:').pop();
return Promise.resolve(Bls12381G2KeyPair$1.fromFingerprint({
fingerprint: fingerprint
})).then(function (publicKey) {
var didDoc = keyToDidDoc(publicKey);
return didDoc;
});
} catch (e) {
return Promise.reject(e);
}
};
var driver = {
__proto__: null,
keyToDidDoc: keyToDidDoc,
get: get
};
function _extends() {

@@ -73,21 +24,43 @@ _extends = Object.assign || function (target) {

function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
subClass.__proto__ = superClass;
}
var Bls12381G2KeyPair = /*#__PURE__*/function () {
function Bls12381G2KeyPair(options) {
this.type = 'Bls12381G2Key2020';
this.id = options.id;
this.type = options.type || 'Bls12381G2Key2020';
this.controller = options.controller;
var Bls12381G2KeyPair = /*#__PURE__*/function (_mattr$Bls12381G2KeyP) {
_inheritsLoose(Bls12381G2KeyPair, _mattr$Bls12381G2KeyP);
if (options.publicKeyBase58) {
this.publicKeyBuffer = decode(options.publicKeyBase58);
} else if (options.publicKeyJwk) {
this.publicKeyBuffer = Buffer.from('a');
} else {
throw new Error('Bls12381G2KeyPair requires publicKeyBase58 or publicKeyJwk, recieved neither.');
}
function Bls12381G2KeyPair() {
return _mattr$Bls12381G2KeyP.apply(this, arguments) || this;
if (options.privateKeyBase58) {
this.privateKeyBuffer = decode(options.privateKeyBase58);
}
if (!this.id) {
this.id = '#' + this.fingerprint();
}
if (!this.controller) {
this.controller = "did:key:" + this.fingerprint();
}
}
Bls12381G2KeyPair.generate = function generate(options) {
Bls12381G2KeyPair.generate = function generate() {
try {
var keyPair = generateBls12381KeyPair();
return Promise.resolve(Bls12381G2KeyPair.from(_extends({}, options, {
var options = {
privateKeyBase58: encode(keyPair.secretKey),
publicKeyBase58: encode(keyPair.publicKey)
};
var fingerprint = Bls12381G2KeyPair$1.fingerprintFromPublicKey({
publicKeyBase58: options.publicKeyBase58
});
return Promise.resolve(new Bls12381G2KeyPair(_extends({}, options, {
id: '#' + fingerprint,
controller: "did:key:" + fingerprint
})));

@@ -99,15 +72,107 @@ } catch (e) {

Bls12381G2KeyPair.toKeyPair = function toKeyPair(key) {
var fingerprint = Bls12381G2KeyPair.fingerprintFromPublicKey({
publicKeyBase58: encode(key.publicKeyBuffer)
Bls12381G2KeyPair.fromFingerprint = function fromFingerprint(_ref) {
var fingerprint = _ref.fingerprint;
try {
var keypair = Bls12381G2KeyPair$1.fromFingerprint({
fingerprint: fingerprint
});
var options = {
publicKeyBase58: encode(keypair.publicKeyBuffer)
};
return Promise.resolve(new Bls12381G2KeyPair(options));
} catch (e) {
return Promise.reject(e);
}
};
Bls12381G2KeyPair.from = function from(options) {
try {
var _temp9 = function _temp9() {
function _temp6() {
function _temp4() {
function _temp2() {
var _options = {
publicKeyBase58: encode(keypair.publicKeyBuffer)
};
if (keypair.privateKeyBuffer) {
_options.privateKeyBase58 = encode(keypair.privateKeyBuffer);
}
return new Bls12381G2KeyPair(_options);
}
var _temp = function () {
if (options.privateKeyBase58) {
return Promise.resolve(Bls12381G2KeyPair$1.from(options)).then(function (_mattr$Bls12381G2KeyP4) {
keypair = _mattr$Bls12381G2KeyP4;
});
}
}();
return _temp && _temp.then ? _temp.then(_temp2) : _temp2(_temp);
}
var _temp3 = function () {
if (options.publicKeyBase58) {
return Promise.resolve(Bls12381G2KeyPair$1.from(options)).then(function (_mattr$Bls12381G2KeyP3) {
keypair = _mattr$Bls12381G2KeyP3;
});
}
}();
return _temp3 && _temp3.then ? _temp3.then(_temp4) : _temp4(_temp3);
}
var _temp5 = function () {
if (options.privateKeyJwk) {
return Promise.resolve(Bls12381G2KeyPair$1.fromJwk(options)).then(function (_mattr$Bls12381G2KeyP2) {
keypair = _mattr$Bls12381G2KeyP2;
});
}
}();
return _temp5 && _temp5.then ? _temp5.then(_temp6) : _temp6(_temp5);
};
var keypair;
var _temp10 = function () {
if (options.publicKeyJwk) {
return Promise.resolve(Bls12381G2KeyPair$1.fromJwk(options)).then(function (_mattr$Bls12381G2KeyP) {
keypair = _mattr$Bls12381G2KeyP;
});
}
}();
return Promise.resolve(_temp10 && _temp10.then ? _temp10.then(_temp9) : _temp9(_temp10));
} catch (e) {
return Promise.reject(e);
}
};
var _proto = Bls12381G2KeyPair.prototype;
_proto.fingerprint = function fingerprint() {
var fingerprint = Bls12381G2KeyPair$1.fingerprintFromPublicKey({
publicKeyBase58: encode(this.publicKeyBuffer)
});
return fingerprint;
};
_proto.toKeyPair = function toKeyPair(exportPrivateKey) {
if (exportPrivateKey === void 0) {
exportPrivateKey = false;
}
var kp = {
id: '#' + fingerprint,
type: 'Bls12381G2Key2020',
controller: "did:key:" + fingerprint,
publicKeyBase58: encode(key.publicKeyBuffer)
id: this.id,
type: this.type,
controller: this.controller,
publicKeyBase58: encode(this.publicKeyBuffer)
};
if (key.privateKeyBuffer) {
kp.privateKeyBase58 = encode(key.privateKeyBuffer);
if (exportPrivateKey) {
kp.privateKeyBase58 = encode(this.privateKeyBuffer);
}

@@ -118,6 +183,47 @@

_proto.toJsonWebKeyPair = function toJsonWebKeyPair(exportPrivateKey) {
if (exportPrivateKey === void 0) {
exportPrivateKey = false;
}
var mattrKey = new Bls12381G2KeyPair$1(this.toKeyPair(exportPrivateKey));
var kp = {
id: this.id,
type: 'JsonWebKey2020',
controller: this.controller,
publicKeyJwk: mattrKey.publicKeyJwk
};
delete kp.publicKeyJwk.kid;
if (exportPrivateKey) {
kp.privateKeyJwk = mattrKey.privateKeyJwk;
delete kp.privateKeyJwk.kid;
}
return kp;
};
_proto.verifier = function verifier() {
var mattrKey = new Bls12381G2KeyPair$1(this.toKeyPair(false));
return mattrKey.verifier();
};
_proto.signer = function signer() {
var mattrKey = new Bls12381G2KeyPair$1(this.toKeyPair(true));
return mattrKey.signer();
};
return Bls12381G2KeyPair;
}(Bls12381G2KeyPair$1);
}();
var resolve = /*#__PURE__*/getResolve(Bls12381G2KeyPair);
var get = /*#__PURE__*/getGet(resolve);
var driver = {
__proto__: null,
resolve: resolve,
get: get
};
export { Bls12381G2KeyPair, driver };
//# sourceMappingURL=did-key-bls12381.esm.js.map

@@ -1,32 +0,8 @@

export declare const keyToDidDoc: (bls12381Key: any) => {
'@context': (string | {
'@base': string;
})[];
id: string;
publicKey: {
id: string;
type: any;
controller: string;
publicKeyBase58: any;
}[];
authentication: string[];
assertionMethod: string[];
capabilityDelegation: string[];
capabilityInvocation: string[];
};
export declare const get: ({ did, url }?: any) => Promise<{
'@context': (string | {
'@base': string;
})[];
id: string;
publicKey: {
id: string;
type: any;
controller: string;
publicKeyBase58: any;
}[];
authentication: string[];
assertionMethod: string[];
capabilityDelegation: string[];
capabilityInvocation: string[];
export declare const resolve: (didUri: string, resolutionMetaData?: any) => Promise<{
didDocument: any;
didDocumentMetaData: {
'content-type': any;
};
didResolutionMetaData: {};
}>;
export declare const get: ({ did, url }?: any) => Promise<any>;

@@ -5,3 +5,3 @@ {

"module": "dist/bls12381.esm.js",
"version": "0.2.1-unstable.20",
"version": "0.2.1-unstable.21",
"license": "Apache-2.0",

@@ -34,2 +34,3 @@ "main": "dist/index.js",

"devDependencies": {
"@transmute/did-key-test-vectors": "^0.2.1-unstable.21",
"tsdx": "^0.13.2",

@@ -41,6 +42,7 @@ "tslib": "^2.0.0",

"@mattrglobal/bbs-signatures": "^0.3.0",
"@mattrglobal/bls12381-key-pair": "^0.3.1-unstable.046a371",
"@mattrglobal/bls12381-key-pair": "v0.4.1-unstable.aeea218",
"@transmute/did-key-common": "^0.2.1-unstable.21",
"bs58": "^4.0.1"
},
"gitHead": "29d870c1ec1449ed726e0d9b5818a03e7abfc71c"
"gitHead": "28e7977d60b1074bfa8154cf83d9f6f97895e441"
}

@@ -5,4 +5,8 @@ import { Bls12381G2KeyPair } from '@mattrglobal/bls12381-key-pair';

import * as fixtures from '../__fixtures__';
import { didCoreConformance } from '@transmute/did-key-test-vectors';
const [example] = didCoreConformance.bls12381_g2.key;
const message = 'hello world';
describe('bls12381.sanity', () => {

@@ -18,3 +22,5 @@ it('generate', async () => {

it('from', async () => {
const key = await Bls12381G2KeyPair.from(fixtures.bls12381_base58btc);
const key = await Bls12381G2KeyPair.from(
example.keypair['application/did+ld+json']
);
expect(key.publicKeyBuffer).toBeDefined();

@@ -26,5 +32,9 @@ expect(key.privateKeyBuffer).toBeDefined();

const key = await Bls12381G2KeyPair.fromFingerprint({
fingerprint: fixtures.bls12381_base58btc.id.split('#').pop(),
fingerprint: example.keypair['application/did+ld+json'].id
.split('#')
.pop(),
});
expect('#' + key.fingerprint()).toBe(fixtures.bls12381_base58btc.id);
expect('#' + key.fingerprint()).toBe(
example.keypair['application/did+ld+json'].id
);
});

@@ -34,5 +44,8 @@

const fingerprint = await Bls12381G2KeyPair.fingerprintFromPublicKey({
publicKeyBase58: fixtures.bls12381_base58btc.publicKeyBase58,
publicKeyBase58:
example.keypair['application/did+ld+json'].publicKeyBase58,
});
expect('#' + fingerprint).toBe(fixtures.bls12381_base58btc.id);
expect('#' + fingerprint).toBe(
example.keypair['application/did+ld+json'].id
);
});

@@ -44,7 +57,7 @@

const signature = await signer.sign({
data: new Uint8Array(Buffer.from(fixtures.message)),
data: new Uint8Array(Buffer.from(message)),
});
const verifier = key.verifier();
const verified = await verifier.verify({
data: new Uint8Array(Buffer.from(fixtures.message)),
data: new Uint8Array(Buffer.from(message)),
signature,

@@ -51,0 +64,0 @@ });

import fs from 'fs';
import path from 'path';
// import crypto from 'crypto';
import * as bls12381 from '../index';
import { Bls12381G2KeyPair } from '../Bls12381G2KeyPair';
import { resolve } from '../driver';
const count = 5;
const WRITE_FIXTURE_TO_DISK = false;
it('generate random fixtures', async () => {
let fixture: any = {};
let fixtures: any = [];
it('generate did-core fixtures', async () => {
for (let i = 0; i < count; i++) {
const key = await bls12381.Bls12381G2KeyPair.generate();
const didDocument = await bls12381.driver.keyToDidDoc(key);
fixture = {
...fixture,
[didDocument.id]: {
verificationKeyPair: bls12381.Bls12381G2KeyPair.toKeyPair(key),
didDocument,
const key = await Bls12381G2KeyPair.generate();
fixtures.push({
seed: i,
keypair: {
'application/did+json': await key.toJsonWebKeyPair(true),
'application/did+ld+json': key.toKeyPair(true),
},
};
resolution: {
'application/did+json': await resolve(key.controller, {
accept: 'application/did+json',
}),
'application/did+ld+json': await resolve(key.controller, {
accept: 'application/did+ld+json',
}),
},
});
}
// uncomment to debug
// console.log(JSON.stringify(fixture, null, 2));
// console.log(JSON.stringify(fixtures, null, 2));
if (WRITE_FIXTURE_TO_DISK) {
fs.writeFileSync(
path.resolve(__dirname, '../__fixtures__/did.json'),
JSON.stringify(fixture, null, 2)
path.resolve(__dirname, '../__fixtures__/bls12381_g2.json'),
JSON.stringify(fixtures, null, 2)
);
}
});

@@ -6,28 +6,133 @@ import * as mattr from '@mattrglobal/bls12381-key-pair';

export class Bls12381G2KeyPair extends mattr.Bls12381G2KeyPair {
static async generate(options?: any) {
export class Bls12381G2KeyPair {
public id: string;
public type: string = 'Bls12381G2Key2020';
public controller: string;
public publicKeyBuffer: Buffer;
public privateKeyBuffer?: Buffer;
static async generate() {
const keyPair = generateBls12381KeyPair();
return Bls12381G2KeyPair.from({
...options,
let options = {
privateKeyBase58: bs58.encode(keyPair.secretKey as Uint8Array),
publicKeyBase58: bs58.encode(keyPair.publicKey),
};
const fingerprint = mattr.Bls12381G2KeyPair.fingerprintFromPublicKey({
publicKeyBase58: options.publicKeyBase58,
});
return new Bls12381G2KeyPair({
...options,
id: '#' + fingerprint,
controller: `did:key:${fingerprint}`,
});
}
static toKeyPair(key: any) {
const fingerprint = Bls12381G2KeyPair.fingerprintFromPublicKey({
publicKeyBase58: bs58.encode(key.publicKeyBuffer),
static async fromFingerprint({ fingerprint }: any) {
const keypair = mattr.Bls12381G2KeyPair.fromFingerprint({
fingerprint,
});
let kp: any = {
id: '#' + fingerprint,
type: 'Bls12381G2Key2020',
controller: `did:key:${fingerprint}`,
publicKeyBase58: bs58.encode(key.publicKeyBuffer),
const options = {
publicKeyBase58: bs58.encode(keypair.publicKeyBuffer),
};
return new Bls12381G2KeyPair(options);
}
if (key.privateKeyBuffer) {
kp.privateKeyBase58 = bs58.encode(key.privateKeyBuffer);
static async from(options: any) {
let keypair;
if (options.publicKeyJwk) {
keypair = await mattr.Bls12381G2KeyPair.fromJwk(options);
}
if (options.privateKeyJwk) {
keypair = await mattr.Bls12381G2KeyPair.fromJwk(options);
}
if (options.publicKeyBase58) {
keypair = await mattr.Bls12381G2KeyPair.from(options);
}
if (options.privateKeyBase58) {
keypair = await mattr.Bls12381G2KeyPair.from(options);
}
let _options: any = {
publicKeyBase58: bs58.encode((keypair as any).publicKeyBuffer),
};
if ((keypair as any).privateKeyBuffer) {
_options.privateKeyBase58 = bs58.encode(
(keypair as any).privateKeyBuffer
);
}
return new Bls12381G2KeyPair(_options);
}
constructor(options: any) {
this.id = options.id;
this.type = options.type || 'Bls12381G2Key2020';
this.controller = options.controller;
if (options.publicKeyBase58) {
this.publicKeyBuffer = bs58.decode(options.publicKeyBase58);
} else if (options.publicKeyJwk) {
this.publicKeyBuffer = Buffer.from('a');
} else {
throw new Error(
'Bls12381G2KeyPair requires publicKeyBase58 or publicKeyJwk, recieved neither.'
);
}
if (options.privateKeyBase58) {
this.privateKeyBuffer = bs58.decode(options.privateKeyBase58);
}
if (!this.id) {
this.id = '#' + this.fingerprint();
}
if (!this.controller) {
this.controller = `did:key:${this.fingerprint()}`;
}
}
fingerprint() {
const fingerprint = mattr.Bls12381G2KeyPair.fingerprintFromPublicKey({
publicKeyBase58: bs58.encode(this.publicKeyBuffer),
});
return fingerprint;
}
toKeyPair(exportPrivateKey: boolean = false) {
const kp: any = {
id: this.id,
type: this.type,
controller: this.controller,
publicKeyBase58: bs58.encode(this.publicKeyBuffer),
};
if (exportPrivateKey) {
kp.privateKeyBase58 = bs58.encode(this.privateKeyBuffer);
}
return kp;
}
toJsonWebKeyPair(exportPrivateKey = false) {
const mattrKey = new mattr.Bls12381G2KeyPair(
this.toKeyPair(exportPrivateKey)
);
const kp: any = {
id: this.id,
type: 'JsonWebKey2020',
controller: this.controller,
publicKeyJwk: mattrKey.publicKeyJwk,
};
delete kp.publicKeyJwk.kid;
if (exportPrivateKey) {
kp.privateKeyJwk = mattrKey.privateKeyJwk;
delete kp.privateKeyJwk.kid;
}
return kp;
}
verifier() {
const mattrKey = new mattr.Bls12381G2KeyPair(this.toKeyPair(false));
return mattrKey.verifier();
}
signer() {
const mattrKey = new mattr.Bls12381G2KeyPair(this.toKeyPair(true));
return mattrKey.signer();
}
}

@@ -1,10 +0,34 @@

import * as fixtures from './__fixtures__';
import { didCoreConformance } from '@transmute/did-key-test-vectors';
import { get } from './driver';
import { get, resolve } from './driver';
it('resolve a key from id', async () => {
const [example] = didCoreConformance.bls12381_g2.key;
it('get interface defaults to application/did+ld+json', async () => {
let _didDocument: any = await get({
did: fixtures.didDocument.id,
did: example.resolution['application/did+ld+json'].didDocument.id,
});
expect(_didDocument).toEqual(fixtures.didDocument);
expect(_didDocument).toEqual(
example.resolution['application/did+ld+json'].didDocument
);
});
let representations = [
{
keyType: 'JsonWebKey2020',
contentType: 'application/did+json',
},
{
keyType: 'Bls12381G2Key2020',
contentType: 'application/did+ld+json',
},
];
representations.forEach(rep => {
let { id } = example.resolution[rep.contentType].didDocument;
it(`resolve supports ${rep.contentType}`, async () => {
let resolutionResponse: any = await resolve(id, {
accept: rep.contentType,
});
expect(resolutionResponse).toEqual(example.resolution[rep.contentType]);
});
});

@@ -1,42 +0,6 @@

import { Bls12381G2KeyPair } from '@mattrglobal/bls12381-key-pair';
import bs58 from 'bs58';
export const keyToDidDoc = (bls12381Key: any) => {
const did = `did:key:${bls12381Key.fingerprint()}`;
const keyId = `#${bls12381Key.fingerprint()}`;
return {
'@context': [
'https://www.w3.org/ns/did/v1',
{
'@base': did,
},
],
id: did,
publicKey: [
{
id: keyId,
type: bls12381Key.type,
controller: did,
publicKeyBase58: bs58.encode(bls12381Key.publicKeyBuffer),
},
],
authentication: [keyId],
assertionMethod: [keyId],
capabilityDelegation: [keyId],
capabilityInvocation: [keyId],
};
};
import { getResolve, getGet } from '@transmute/did-key-common';
export const get = async ({ did, url }: any = {}) => {
did = did || url;
if (!did) {
throw new TypeError('"did" must be a string.');
}
const fingerprint = did
.split('#')[0]
.split('did:key:')
.pop();
import { Bls12381G2KeyPair } from './Bls12381G2KeyPair';
const publicKey = await Bls12381G2KeyPair.fromFingerprint({ fingerprint });
const didDoc = keyToDidDoc(publicKey);
return didDoc;
};
export const resolve = getResolve(Bls12381G2KeyPair);
export const get = getGet(resolve);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc