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

@dfinity/identity

Package Overview
Dependencies
Maintainers
12
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dfinity/identity - npm Package Compare versions

Comparing version 0.9.0 to 0.9.1-beta-1

lib/cjs/identity/der.d.ts

1

lib/cjs/identity/ed25519.d.ts

@@ -8,3 +8,2 @@ import { KeyPair, PublicKey, SignIdentity } from '@dfinity/agent';

private static RAW_KEY_LENGTH;
private static DER_PREFIX;
private static derEncode;

@@ -11,0 +10,0 @@ private static derDecode;

@@ -27,2 +27,3 @@ "use strict";

const tweetnacl = __importStar(require("tweetnacl"));
const der_1 = require("./der");
class Ed25519PublicKey {

@@ -44,25 +45,10 @@ // `fromRaw` and `fromDer` should be used for instantiation, not this constructor.

static derEncode(publicKey) {
if (publicKey.byteLength !== Ed25519PublicKey.RAW_KEY_LENGTH) {
const bl = publicKey.byteLength;
throw new TypeError(`ed25519 public key must be ${Ed25519PublicKey.RAW_KEY_LENGTH} bytes long (is ${bl})`);
}
// https://github.com/dfinity/agent-js/issues/42#issuecomment-716356288
const derPublicKey = Uint8Array.from([
...Ed25519PublicKey.DER_PREFIX,
...new Uint8Array(publicKey),
]);
return candid_1.derBlobFromBlob(candid_1.blobFromUint8Array(derPublicKey));
return candid_1.derBlobFromBlob(candid_1.blobFromUint8Array(der_1.wrapDER(publicKey, der_1.ED25519_OID)));
}
static derDecode(key) {
const expectedLength = Ed25519PublicKey.DER_PREFIX.length + Ed25519PublicKey.RAW_KEY_LENGTH;
if (key.byteLength !== expectedLength) {
const bl = key.byteLength;
throw new TypeError(`Ed25519 DER-encoded public key must be ${expectedLength} bytes long (is ${bl})`);
const unwrapped = der_1.unwrapDER(key, der_1.ED25519_OID);
if (unwrapped.length !== this.RAW_KEY_LENGTH) {
throw new Error('An Ed25519 public key must be exactly 32bytes long');
}
const rawKey = candid_1.blobFromUint8Array(key.subarray(Ed25519PublicKey.DER_PREFIX.length));
if (!this.derEncode(rawKey).equals(key)) {
throw new TypeError('Ed25519 DER-encoded public key is invalid. A valid Ed25519 DER-encoded public key ' +
`must have the following prefix: ${Ed25519PublicKey.DER_PREFIX}`);
}
return rawKey;
return candid_1.blobFromUint8Array(unwrapped);
}

@@ -79,13 +65,2 @@ toDer() {

Ed25519PublicKey.RAW_KEY_LENGTH = 32;
// Adding this prefix to a raw public key is sufficient to DER-encode it.
// See https://github.com/dfinity/agent-js/issues/42#issuecomment-716356288
Ed25519PublicKey.DER_PREFIX = Uint8Array.from([
...[48, 42],
...[48, 5],
...[6, 3],
...[43, 101, 112],
...[3],
...[Ed25519PublicKey.RAW_KEY_LENGTH + 1],
...[0], // 'no padding'
]);
class Ed25519KeyIdentity extends agent_1.SignIdentity {

@@ -92,0 +67,0 @@ // `fromRaw` and `fromDer` should be used for instantiation, not this constructor.

@@ -30,18 +30,5 @@ "use strict";

const tweetnacl = __importStar(require("tweetnacl"));
const der_1 = require("./der");
function _coseToDerEncodedBlob(cose) {
const c = new Uint8Array(cose);
if (c.byteLength > 230) {
// 'Tis true, 'tis too much.
throw new Error('Cannot encode byte length of more than 230.');
}
// prettier-ignore
const der = new Uint8Array([
0x30, 0x10 + c.byteLength + 1,
0x30, 0x0C,
// OID 1.3.6.1.4.1.56387.1.1
0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0xB8, 0x43, 0x01, 0x01,
0x03, 1 + c.byteLength, 0x00,
...c,
]);
return candid_1.derBlobFromBlob(candid_1.blobFromUint8Array(der));
return candid_1.derBlobFromBlob(candid_1.blobFromUint8Array(der_1.wrapDER(cose, der_1.DER_COSE_OID)));
}

@@ -48,0 +35,0 @@ /**

export { Ed25519KeyIdentity, Ed25519PublicKey } from './identity/ed25519';
export { Delegation, DelegationIdentity, DelegationChain, SignedDelegation, } from './identity/delegation';
export { WebAuthnIdentity } from './identity/webauthn';
export { wrapDER, unwrapDER, DER_COSE_OID, ED25519_OID } from './identity/der';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WebAuthnIdentity = exports.DelegationChain = exports.DelegationIdentity = exports.Delegation = exports.Ed25519PublicKey = exports.Ed25519KeyIdentity = void 0;
exports.ED25519_OID = exports.DER_COSE_OID = exports.unwrapDER = exports.wrapDER = exports.WebAuthnIdentity = exports.DelegationChain = exports.DelegationIdentity = exports.Delegation = exports.Ed25519PublicKey = exports.Ed25519KeyIdentity = void 0;
var ed25519_1 = require("./identity/ed25519");

@@ -13,2 +13,7 @@ Object.defineProperty(exports, "Ed25519KeyIdentity", { enumerable: true, get: function () { return ed25519_1.Ed25519KeyIdentity; } });

Object.defineProperty(exports, "WebAuthnIdentity", { enumerable: true, get: function () { return webauthn_1.WebAuthnIdentity; } });
var der_1 = require("./identity/der");
Object.defineProperty(exports, "wrapDER", { enumerable: true, get: function () { return der_1.wrapDER; } });
Object.defineProperty(exports, "unwrapDER", { enumerable: true, get: function () { return der_1.unwrapDER; } });
Object.defineProperty(exports, "DER_COSE_OID", { enumerable: true, get: function () { return der_1.DER_COSE_OID; } });
Object.defineProperty(exports, "ED25519_OID", { enumerable: true, get: function () { return der_1.ED25519_OID; } });
//# sourceMappingURL=index.js.map

@@ -8,3 +8,2 @@ import { KeyPair, PublicKey, SignIdentity } from '@dfinity/agent';

private static RAW_KEY_LENGTH;
private static DER_PREFIX;
private static derEncode;

@@ -11,0 +10,0 @@ private static derDecode;

@@ -5,2 +5,3 @@ import { SignIdentity } from '@dfinity/agent';

import * as tweetnacl from 'tweetnacl';
import { ED25519_OID, unwrapDER, wrapDER } from './der';
export class Ed25519PublicKey {

@@ -22,25 +23,10 @@ // `fromRaw` and `fromDer` should be used for instantiation, not this constructor.

static derEncode(publicKey) {
if (publicKey.byteLength !== Ed25519PublicKey.RAW_KEY_LENGTH) {
const bl = publicKey.byteLength;
throw new TypeError(`ed25519 public key must be ${Ed25519PublicKey.RAW_KEY_LENGTH} bytes long (is ${bl})`);
}
// https://github.com/dfinity/agent-js/issues/42#issuecomment-716356288
const derPublicKey = Uint8Array.from([
...Ed25519PublicKey.DER_PREFIX,
...new Uint8Array(publicKey),
]);
return derBlobFromBlob(blobFromUint8Array(derPublicKey));
return derBlobFromBlob(blobFromUint8Array(wrapDER(publicKey, ED25519_OID)));
}
static derDecode(key) {
const expectedLength = Ed25519PublicKey.DER_PREFIX.length + Ed25519PublicKey.RAW_KEY_LENGTH;
if (key.byteLength !== expectedLength) {
const bl = key.byteLength;
throw new TypeError(`Ed25519 DER-encoded public key must be ${expectedLength} bytes long (is ${bl})`);
const unwrapped = unwrapDER(key, ED25519_OID);
if (unwrapped.length !== this.RAW_KEY_LENGTH) {
throw new Error('An Ed25519 public key must be exactly 32bytes long');
}
const rawKey = blobFromUint8Array(key.subarray(Ed25519PublicKey.DER_PREFIX.length));
if (!this.derEncode(rawKey).equals(key)) {
throw new TypeError('Ed25519 DER-encoded public key is invalid. A valid Ed25519 DER-encoded public key ' +
`must have the following prefix: ${Ed25519PublicKey.DER_PREFIX}`);
}
return rawKey;
return blobFromUint8Array(unwrapped);
}

@@ -56,13 +42,2 @@ toDer() {

Ed25519PublicKey.RAW_KEY_LENGTH = 32;
// Adding this prefix to a raw public key is sufficient to DER-encode it.
// See https://github.com/dfinity/agent-js/issues/42#issuecomment-716356288
Ed25519PublicKey.DER_PREFIX = Uint8Array.from([
...[48, 42],
...[48, 5],
...[6, 3],
...[43, 101, 112],
...[3],
...[Ed25519PublicKey.RAW_KEY_LENGTH + 1],
...[0], // 'no padding'
]);
export class Ed25519KeyIdentity extends SignIdentity {

@@ -69,0 +44,0 @@ // `fromRaw` and `fromDer` should be used for instantiation, not this constructor.

@@ -5,18 +5,5 @@ import { SignIdentity } from '@dfinity/agent';

import * as tweetnacl from 'tweetnacl';
import { DER_COSE_OID, wrapDER } from './der';
function _coseToDerEncodedBlob(cose) {
const c = new Uint8Array(cose);
if (c.byteLength > 230) {
// 'Tis true, 'tis too much.
throw new Error('Cannot encode byte length of more than 230.');
}
// prettier-ignore
const der = new Uint8Array([
0x30, 0x10 + c.byteLength + 1,
0x30, 0x0C,
// OID 1.3.6.1.4.1.56387.1.1
0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0xB8, 0x43, 0x01, 0x01,
0x03, 1 + c.byteLength, 0x00,
...c,
]);
return derBlobFromBlob(blobFromUint8Array(der));
return derBlobFromBlob(blobFromUint8Array(wrapDER(cose, DER_COSE_OID)));
}

@@ -23,0 +10,0 @@ /**

export { Ed25519KeyIdentity, Ed25519PublicKey } from './identity/ed25519';
export { Delegation, DelegationIdentity, DelegationChain, SignedDelegation, } from './identity/delegation';
export { WebAuthnIdentity } from './identity/webauthn';
export { wrapDER, unwrapDER, DER_COSE_OID, ED25519_OID } from './identity/der';
export { Ed25519KeyIdentity, Ed25519PublicKey } from './identity/ed25519';
export { Delegation, DelegationIdentity, DelegationChain, } from './identity/delegation';
export { WebAuthnIdentity } from './identity/webauthn';
export { wrapDER, unwrapDER, DER_COSE_OID, ED25519_OID } from './identity/der';
//# sourceMappingURL=index.js.map
{
"name": "@dfinity/identity",
"version": "0.9.0",
"version": "0.9.1-beta-1",
"author": "DFINITY Stiftung <sdk@dfinity.org>",

@@ -34,3 +34,3 @@ "license": "Apache-2.0",

"lint:fix": "npm run lint -- --fix",
"make:docs/reference": "typedoc src/index.ts --out docs/reference",
"make:docs/reference": "typedoc src/index.ts --out ../../docs/generated/identity",
"release": "npm publish",

@@ -41,4 +41,4 @@ "test": "jest",

"peerDependencies": {
"@dfinity/agent": "^0.9.0",
"@dfinity/principal": "^0.9.0"
"@dfinity/agent": "^0.9.1-beta-1",
"@dfinity/principal": "^0.9.1-beta-1"
},

@@ -45,0 +45,0 @@ "dependencies": {

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

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

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