Socket
Socket
Sign inDemoInstall

@dfinity/identity

Package Overview
Dependencies
Maintainers
10
Versions
76
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.20.2 to 0.21.1

lib/cjs/buffer.d.ts

5

lib/cjs/identity/delegation.d.ts

@@ -64,2 +64,3 @@ import { DerEncodedPublicKey, HttpAgentRequest, PublicKey, Signature, SignIdentity } from '@dfinity/agent';

* passing the previous delegation chain into the options argument. For example:
*
* @example

@@ -79,2 +80,3 @@ * const rootKey = createKey();

* const identity = DelegationIdentity.fromDelegation(bottomKey, middleToBottom);
*
* @param from The identity that will delegate.

@@ -95,2 +97,3 @@ * @param to The identity that gets delegated. It can now sign messages as if it was the

* Creates a DelegationChain object from a JSON string.
*
* @param json The JSON string to parse.

@@ -101,2 +104,3 @@ */

* Creates a DelegationChain object from a list of delegations and a DER-encoded public key.
*
* @param delegations The list of delegations.

@@ -120,2 +124,3 @@ * @param publicKey The DER-encoded public key of the key-pair signing the first delegation.

* Create a delegation without having access to delegateKey.
*
* @param key The key used to sign the reqyests.

@@ -122,0 +127,0 @@ * @param delegation A delegation object created using `createDelegation`.

38

lib/cjs/identity/delegation.js

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

const cbor = __importStar(require("simple-cbor"));
const buffer_1 = require("../buffer");
const domainSeparator = new TextEncoder().encode('\x1Aic-request-auth-delegation');

@@ -48,3 +49,3 @@ const requestDomainSeparator = new TextEncoder().encode('\x0Aic-request');

}
return (0, agent_1.fromHex)(value);
return (0, buffer_1.fromHexString)(value);
}

@@ -73,3 +74,3 @@ /**

// with an OID). After de-hex, if it's not obvious what it is, it's an ArrayBuffer.
return Object.assign({ expiration: this.expiration.toString(16), pubkey: (0, agent_1.toHex)(this.pubkey) }, (this.targets && { targets: this.targets.map(p => p.toHex()) }));
return Object.assign({ expiration: this.expiration.toString(16), pubkey: (0, buffer_1.toHexString)(this.pubkey) }, (this.targets && { targets: this.targets.map(p => p.toHex()) }));
}

@@ -80,2 +81,3 @@ }

* Sign a single delegation object for a period of time.
*
* @param from The identity that lends its delegation.

@@ -110,6 +112,2 @@ * @param to The identity that receives the delegation.

class DelegationChain {
constructor(delegations, publicKey) {
this.delegations = delegations;
this.publicKey = publicKey;
}
/**

@@ -121,2 +119,3 @@ * Create a delegation chain between two (or more) keys. By default, the expiration time

* passing the previous delegation chain into the options argument. For example:
*
* @example

@@ -136,2 +135,3 @@ * const rootKey = createKey();

* const identity = DelegationIdentity.fromDelegation(bottomKey, middleToBottom);
*
* @param from The identity that will delegate.

@@ -153,2 +153,3 @@ * @param to The identity that gets delegated. It can now sign messages as if it was the

* Creates a DelegationChain object from a JSON string.
*
* @param json The JSON string to parse.

@@ -168,3 +169,3 @@ */

return {
delegation: new Delegation(_parseBlob(pubkey), BigInt('0x' + expiration), // expiration in JSON is an hexa string (See toJSON() below).
delegation: new Delegation(_parseBlob(pubkey), BigInt(`0x${expiration}`), // expiration in JSON is an hexa string (See toJSON() below).
targets &&

@@ -184,2 +185,3 @@ targets.map((t) => {

* Creates a DelegationChain object from a list of delegations and a DER-encoded public key.
*
* @param delegations The list of delegations.

@@ -191,2 +193,6 @@ * @param publicKey The DER-encoded public key of the key-pair signing the first delegation.

}
constructor(delegations, publicKey) {
this.delegations = delegations;
this.publicKey = publicKey;
}
toJSON() {

@@ -198,9 +204,9 @@ return {

return {
delegation: Object.assign({ expiration: delegation.expiration.toString(16), pubkey: (0, agent_1.toHex)(delegation.pubkey) }, (targets && {
delegation: Object.assign({ expiration: delegation.expiration.toString(16), pubkey: (0, buffer_1.toHexString)(delegation.pubkey) }, (targets && {
targets: targets.map(t => t.toHex()),
})),
signature: (0, agent_1.toHex)(signature),
signature: (0, buffer_1.toHexString)(signature),
};
}),
publicKey: (0, agent_1.toHex)(this.publicKey),
publicKey: (0, buffer_1.toHexString)(this.publicKey),
};

@@ -217,9 +223,5 @@ }

class DelegationIdentity extends agent_1.SignIdentity {
constructor(_inner, _delegation) {
super();
this._inner = _inner;
this._delegation = _delegation;
}
/**
* Create a delegation without having access to delegateKey.
*
* @param key The key used to sign the reqyests.

@@ -231,2 +233,7 @@ * @param delegation A delegation object created using `createDelegation`.

}
constructor(_inner, _delegation) {
super();
this._inner = _inner;
this._delegation = _delegation;
}
getDelegation() {

@@ -237,3 +244,2 @@ return this._delegation;

return {
derKey: this._delegation.publicKey,
toDer: () => this._delegation.publicKey,

@@ -240,0 +246,0 @@ };

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

*/
export declare type CryptoKeyOptions = {
export type CryptoKeyOptions = {
extractable?: boolean;

@@ -8,0 +8,0 @@ keyUsages?: KeyUsage[];

@@ -19,5 +19,2 @@ "use strict";

function _getEffectiveCrypto(subtleCrypto) {
if (typeof global !== 'undefined' && global['crypto'] && global['crypto']['subtle']) {
return global['crypto']['subtle'];
}
if (subtleCrypto) {

@@ -37,9 +34,2 @@ return subtleCrypto;

class ECDSAKeyIdentity extends agent_1.SignIdentity {
// `fromKeyPair` and `generate` should be used for instantiation, not this constructor.
constructor(keyPair, derKey, subtleCrypto) {
super();
this._keyPair = keyPair;
this._derKey = derKey;
this._subtleCrypto = subtleCrypto;
}
/**

@@ -75,2 +65,9 @@ * Generates a randomly generated identity for use in calls to the Internet Computer.

}
// `fromKeyPair` and `generate` should be used for instantiation, not this constructor.
constructor(keyPair, derKey, subtleCrypto) {
super();
this._keyPair = keyPair;
this._derKey = derKey;
this._subtleCrypto = subtleCrypto;
}
/**

@@ -77,0 +74,0 @@ * Return the internally-used key pair.

import { DerEncodedPublicKey, KeyPair, PublicKey, Signature, SignIdentity } from '@dfinity/agent';
export declare class Ed25519PublicKey implements PublicKey {
#private;
static from(key: PublicKey): Ed25519PublicKey;

@@ -10,4 +9,4 @@ static fromRaw(rawKey: ArrayBuffer): Ed25519PublicKey;

private static derDecode;
get rawKey(): ArrayBuffer;
get derKey(): DerEncodedPublicKey;
private readonly rawKey;
private readonly derKey;
private constructor();

@@ -18,3 +17,3 @@ toDer(): DerEncodedPublicKey;

export declare class Ed25519KeyIdentity extends SignIdentity {
#private;
protected _privateKey: ArrayBuffer;
static generate(seed?: Uint8Array): Ed25519KeyIdentity;

@@ -25,3 +24,4 @@ static fromParsedJson(obj: JsonnableEd25519KeyIdentity): Ed25519KeyIdentity;

static fromSecretKey(secretKey: ArrayBuffer): Ed25519KeyIdentity;
protected constructor(publicKey: PublicKey, privateKey: ArrayBuffer);
protected _publicKey: Ed25519PublicKey;
protected constructor(publicKey: PublicKey, _privateKey: ArrayBuffer);
/**

@@ -38,3 +38,3 @@ * Serialize this key to JSON.

*/
getPublicKey(): Required<PublicKey>;
getPublicKey(): PublicKey;
/**

@@ -45,14 +45,6 @@ * Signs a blob of data, with this identity's private key.

sign(challenge: ArrayBuffer): Promise<Signature>;
/**
* Verify
* @param sig - signature to verify
* @param msg - message to verify
* @param pk - public key
* @returns - true if the signature is valid, false otherwise
*/
static verify(sig: ArrayBuffer | Uint8Array | string, msg: ArrayBuffer | Uint8Array | string, pk: ArrayBuffer | Uint8Array | string): boolean;
}
declare type PublicKeyHex = string;
declare type SecretKeyHex = string;
export declare type JsonnableEd25519KeyIdentity = [PublicKeyHex, SecretKeyHex];
type PublicKeyHex = string;
type SecretKeyHex = string;
export type JsonnableEd25519KeyIdentity = [PublicKeyHex, SecretKeyHex];
export {};
"use strict";
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _Ed25519PublicKey_rawKey, _Ed25519PublicKey_derKey, _Ed25519KeyIdentity_publicKey, _Ed25519KeyIdentity_privateKey;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Ed25519KeyIdentity = exports.Ed25519PublicKey = void 0;
const agent_1 = require("@dfinity/agent");
const ed25519_1 = require("@noble/curves/ed25519");
const tweetnacl = __importStar(require("tweetnacl"));
const buffer_1 = require("../buffer");
const der_1 = require("./der");
class Ed25519PublicKey {
// `fromRaw` and `fromDer` should be used for instantiation, not this constructor.
constructor(key) {
_Ed25519PublicKey_rawKey.set(this, void 0);
_Ed25519PublicKey_derKey.set(this, void 0);
if (key.byteLength !== Ed25519PublicKey.RAW_KEY_LENGTH) {
throw new Error('An Ed25519 public key must be exactly 32bytes long');
}
__classPrivateFieldSet(this, _Ed25519PublicKey_rawKey, key, "f");
__classPrivateFieldSet(this, _Ed25519PublicKey_derKey, Ed25519PublicKey.derEncode(key), "f");
}
static from(key) {

@@ -39,6 +42,6 @@ return this.fromDer(key.toDer());

static derEncode(publicKey) {
return (0, agent_1.wrapDER)(publicKey, agent_1.ED25519_OID).buffer;
return (0, der_1.wrapDER)(publicKey, der_1.ED25519_OID).buffer;
}
static derDecode(key) {
const unwrapped = (0, agent_1.unwrapDER)(key, agent_1.ED25519_OID);
const unwrapped = (0, der_1.unwrapDER)(key, der_1.ED25519_OID);
if (unwrapped.length !== this.RAW_KEY_LENGTH) {

@@ -49,8 +52,7 @@ throw new Error('An Ed25519 public key must be exactly 32bytes long');

}
get rawKey() {
return __classPrivateFieldGet(this, _Ed25519PublicKey_rawKey, "f");
// `fromRaw` and `fromDer` should be used for instantiation, not this constructor.
constructor(key) {
this.rawKey = key;
this.derKey = Ed25519PublicKey.derEncode(key);
}
get derKey() {
return __classPrivateFieldGet(this, _Ed25519PublicKey_derKey, "f");
}
toDer() {

@@ -64,29 +66,15 @@ return this.derKey;

exports.Ed25519PublicKey = Ed25519PublicKey;
_Ed25519PublicKey_rawKey = new WeakMap(), _Ed25519PublicKey_derKey = new WeakMap();
// The length of Ed25519 public keys is always 32 bytes.
Ed25519PublicKey.RAW_KEY_LENGTH = 32;
class Ed25519KeyIdentity extends agent_1.SignIdentity {
// `fromRaw` and `fromDer` should be used for instantiation, not this constructor.
constructor(publicKey, privateKey) {
super();
_Ed25519KeyIdentity_publicKey.set(this, void 0);
_Ed25519KeyIdentity_privateKey.set(this, void 0);
__classPrivateFieldSet(this, _Ed25519KeyIdentity_publicKey, Ed25519PublicKey.from(publicKey), "f");
__classPrivateFieldSet(this, _Ed25519KeyIdentity_privateKey, new Uint8Array(privateKey), "f");
}
static generate(seed = new Uint8Array(32)) {
static generate(seed) {
if (seed && seed.length !== 32) {
throw new Error('Ed25519 Seed needs to be 32 bytes long.');
}
if (!seed)
seed = ed25519_1.ed25519.utils.randomPrivateKey();
const sk = new Uint8Array(32);
for (let i = 0; i < 32; i++)
sk[i] = new Uint8Array(seed)[i];
const pk = ed25519_1.ed25519.getPublicKey(sk);
return Ed25519KeyIdentity.fromKeyPair(pk, sk);
const { publicKey, secretKey } = seed === undefined ? tweetnacl.sign.keyPair() : tweetnacl.sign.keyPair.fromSeed(seed);
return new this(Ed25519PublicKey.fromRaw(publicKey), secretKey);
}
static fromParsedJson(obj) {
const [publicKeyDer, privateKeyRaw] = obj;
return new Ed25519KeyIdentity(Ed25519PublicKey.fromDer((0, agent_1.fromHex)(publicKeyDer)), (0, agent_1.fromHex)(privateKeyRaw));
return new Ed25519KeyIdentity(Ed25519PublicKey.fromDer((0, buffer_1.fromHexString)(publicKeyDer)), (0, buffer_1.fromHexString)(privateKeyRaw));
}

@@ -109,5 +97,11 @@ static fromJSON(json) {

static fromSecretKey(secretKey) {
const publicKey = ed25519_1.ed25519.getPublicKey(new Uint8Array(secretKey));
return Ed25519KeyIdentity.fromKeyPair(publicKey, secretKey);
const keyPair = tweetnacl.sign.keyPair.fromSecretKey(new Uint8Array(secretKey));
return Ed25519KeyIdentity.fromKeyPair(keyPair.publicKey, keyPair.secretKey);
}
// `fromRaw` and `fromDer` should be used for instantiation, not this constructor.
constructor(publicKey, _privateKey) {
super();
this._privateKey = _privateKey;
this._publicKey = Ed25519PublicKey.from(publicKey);
}
/**

@@ -117,3 +111,3 @@ * Serialize this key to JSON.

toJSON() {
return [(0, agent_1.toHex)(__classPrivateFieldGet(this, _Ed25519KeyIdentity_publicKey, "f").toDer()), (0, agent_1.toHex)(__classPrivateFieldGet(this, _Ed25519KeyIdentity_privateKey, "f"))];
return [(0, buffer_1.toHexString)(this._publicKey.toDer()), (0, buffer_1.toHexString)(this._privateKey)];
}

@@ -125,4 +119,4 @@ /**

return {
secretKey: __classPrivateFieldGet(this, _Ed25519KeyIdentity_privateKey, "f"),
publicKey: __classPrivateFieldGet(this, _Ed25519KeyIdentity_publicKey, "f"),
secretKey: this._privateKey,
publicKey: this._publicKey,
};

@@ -134,3 +128,3 @@ }

getPublicKey() {
return __classPrivateFieldGet(this, _Ed25519KeyIdentity_publicKey, "f");
return this._publicKey;
}

@@ -143,33 +137,7 @@ /**

const blob = new Uint8Array(challenge);
// Some implementations of Ed25519 private keys append a public key to the end of the private key. We only want the private key.
const signature = (0, agent_1.uint8ToBuf)(ed25519_1.ed25519.sign(blob, __classPrivateFieldGet(this, _Ed25519KeyIdentity_privateKey, "f").slice(0, 32)));
// add { __signature__: void; } to the signature to make it compatible with the agent
Object.defineProperty(signature, '__signature__', {
enumerable: false,
value: undefined,
});
const signature = tweetnacl.sign.detached(blob, new Uint8Array(this._privateKey)).buffer;
return signature;
}
/**
* Verify
* @param sig - signature to verify
* @param msg - message to verify
* @param pk - public key
* @returns - true if the signature is valid, false otherwise
*/
static verify(sig, msg, pk) {
const [signature, message, publicKey] = [sig, msg, pk].map(x => {
if (typeof x === 'string') {
x = (0, agent_1.fromHex)(x);
}
if (x instanceof Uint8Array) {
x = x.buffer;
}
return new Uint8Array(x);
});
return ed25519_1.ed25519.verify(message, signature, publicKey);
}
}
exports.Ed25519KeyIdentity = Ed25519KeyIdentity;
_Ed25519KeyIdentity_publicKey = new WeakMap(), _Ed25519KeyIdentity_privateKey = new WeakMap();
//# sourceMappingURL=ed25519.js.map
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -9,5 +32,7 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

const borc_1 = __importDefault(require("borc"));
const utils_1 = require("@noble/hashes/utils");
const tweetnacl = __importStar(require("tweetnacl"));
const buffer_1 = require("../buffer");
const der_1 = require("./der");
function _coseToDerEncodedBlob(cose) {
return (0, agent_1.wrapDER)(cose, agent_1.DER_COSE_OID).buffer;
return (0, der_1.wrapDER)(cose, der_1.DER_COSE_OID).buffer;
}

@@ -20,2 +45,3 @@ /**

* See https://webauthn.guide/#registration (subsection "Example: Parsing the authenticator data").
*
* @param authData The authData field of the attestation response.

@@ -50,2 +76,3 @@ * @returns The COSE key of the authData.

* generated.
*
* @param challenge The challenge to transform into a byte array. By default a hard

@@ -82,3 +109,3 @@ * coded string.

user: {
id: (0, utils_1.randomBytes)(16),
id: tweetnacl.randomBytes(16),
name: 'Internet Identity',

@@ -109,8 +136,2 @@ displayName: 'Internet Identity',

class WebAuthnIdentity extends agent_1.SignIdentity {
constructor(rawId, cose, authenticatorAttachment) {
super();
this.rawId = rawId;
this.authenticatorAttachment = authenticatorAttachment;
this._publicKey = new CosePublicKey(cose);
}
/**

@@ -125,3 +146,3 @@ * Create an identity from a JSON serialization.

}
return new this((0, agent_1.fromHex)(rawId), (0, agent_1.fromHex)(publicKey), undefined);
return new this((0, buffer_1.fromHexString)(rawId), (0, buffer_1.fromHexString)(publicKey), undefined);
}

@@ -146,2 +167,8 @@ /**

}
constructor(rawId, cose, authenticatorAttachment) {
super();
this.rawId = rawId;
this.authenticatorAttachment = authenticatorAttachment;
this._publicKey = new CosePublicKey(cose);
}
getPublicKey() {

@@ -199,4 +226,4 @@ return this._publicKey;

return {
publicKey: (0, agent_1.toHex)(this._publicKey.getCose()),
rawId: (0, agent_1.toHex)(this.rawId),
publicKey: (0, buffer_1.toHexString)(this._publicKey.getCose()),
rawId: (0, buffer_1.toHexString)(this.rawId),
};

@@ -203,0 +230,0 @@ }

@@ -5,3 +5,3 @@ export { Ed25519KeyIdentity, Ed25519PublicKey } from './identity/ed25519';

export { WebAuthnIdentity } from './identity/webauthn';
export { wrapDER, unwrapDER, DER_COSE_OID, ED25519_OID } from '@dfinity/agent';
export { wrapDER, unwrapDER, DER_COSE_OID, ED25519_OID } from './identity/der';
/**

@@ -8,0 +8,0 @@ * @deprecated due to size of dependencies. Use `@dfinity/identity-secp256k1` instead.

@@ -25,7 +25,7 @@ "use strict";

Object.defineProperty(exports, "WebAuthnIdentity", { enumerable: true, get: function () { return webauthn_1.WebAuthnIdentity; } });
var agent_1 = require("@dfinity/agent");
Object.defineProperty(exports, "wrapDER", { enumerable: true, get: function () { return agent_1.wrapDER; } });
Object.defineProperty(exports, "unwrapDER", { enumerable: true, get: function () { return agent_1.unwrapDER; } });
Object.defineProperty(exports, "DER_COSE_OID", { enumerable: true, get: function () { return agent_1.DER_COSE_OID; } });
Object.defineProperty(exports, "ED25519_OID", { enumerable: true, get: function () { return agent_1.ED25519_OID; } });
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; } });
/**

@@ -32,0 +32,0 @@ * @deprecated due to size of dependencies. Use `@dfinity/identity-secp256k1` instead.

@@ -64,2 +64,3 @@ import { DerEncodedPublicKey, HttpAgentRequest, PublicKey, Signature, SignIdentity } from '@dfinity/agent';

* passing the previous delegation chain into the options argument. For example:
*
* @example

@@ -79,2 +80,3 @@ * const rootKey = createKey();

* const identity = DelegationIdentity.fromDelegation(bottomKey, middleToBottom);
*
* @param from The identity that will delegate.

@@ -95,2 +97,3 @@ * @param to The identity that gets delegated. It can now sign messages as if it was the

* Creates a DelegationChain object from a JSON string.
*
* @param json The JSON string to parse.

@@ -101,2 +104,3 @@ */

* Creates a DelegationChain object from a list of delegations and a DER-encoded public key.
*
* @param delegations The list of delegations.

@@ -120,2 +124,3 @@ * @param publicKey The DER-encoded public key of the key-pair signing the first delegation.

* Create a delegation without having access to delegateKey.
*
* @param key The key used to sign the reqyests.

@@ -122,0 +127,0 @@ * @param delegation A delegation object created using `createDelegation`.

@@ -12,5 +12,6 @@ var __rest = (this && this.__rest) || function (s, e) {

};
import { fromHex, requestIdOf, SignIdentity, toHex, } from '@dfinity/agent';
import { requestIdOf, SignIdentity, } from '@dfinity/agent';
import { Principal } from '@dfinity/principal';
import * as cbor from 'simple-cbor';
import { fromHexString, toHexString } from '../buffer';
const domainSeparator = new TextEncoder().encode('\x1Aic-request-auth-delegation');

@@ -22,3 +23,3 @@ const requestDomainSeparator = new TextEncoder().encode('\x0Aic-request');

}
return fromHex(value);
return fromHexString(value);
}

@@ -47,3 +48,3 @@ /**

// with an OID). After de-hex, if it's not obvious what it is, it's an ArrayBuffer.
return Object.assign({ expiration: this.expiration.toString(16), pubkey: toHex(this.pubkey) }, (this.targets && { targets: this.targets.map(p => p.toHex()) }));
return Object.assign({ expiration: this.expiration.toString(16), pubkey: toHexString(this.pubkey) }, (this.targets && { targets: this.targets.map(p => p.toHex()) }));
}

@@ -53,2 +54,3 @@ }

* Sign a single delegation object for a period of time.
*
* @param from The identity that lends its delegation.

@@ -83,6 +85,2 @@ * @param to The identity that receives the delegation.

export class DelegationChain {
constructor(delegations, publicKey) {
this.delegations = delegations;
this.publicKey = publicKey;
}
/**

@@ -94,2 +92,3 @@ * Create a delegation chain between two (or more) keys. By default, the expiration time

* passing the previous delegation chain into the options argument. For example:
*
* @example

@@ -109,2 +108,3 @@ * const rootKey = createKey();

* const identity = DelegationIdentity.fromDelegation(bottomKey, middleToBottom);
*
* @param from The identity that will delegate.

@@ -126,2 +126,3 @@ * @param to The identity that gets delegated. It can now sign messages as if it was the

* Creates a DelegationChain object from a JSON string.
*
* @param json The JSON string to parse.

@@ -141,3 +142,3 @@ */

return {
delegation: new Delegation(_parseBlob(pubkey), BigInt('0x' + expiration), // expiration in JSON is an hexa string (See toJSON() below).
delegation: new Delegation(_parseBlob(pubkey), BigInt(`0x${expiration}`), // expiration in JSON is an hexa string (See toJSON() below).
targets &&

@@ -157,2 +158,3 @@ targets.map((t) => {

* Creates a DelegationChain object from a list of delegations and a DER-encoded public key.
*
* @param delegations The list of delegations.

@@ -164,2 +166,6 @@ * @param publicKey The DER-encoded public key of the key-pair signing the first delegation.

}
constructor(delegations, publicKey) {
this.delegations = delegations;
this.publicKey = publicKey;
}
toJSON() {

@@ -171,9 +177,9 @@ return {

return {
delegation: Object.assign({ expiration: delegation.expiration.toString(16), pubkey: toHex(delegation.pubkey) }, (targets && {
delegation: Object.assign({ expiration: delegation.expiration.toString(16), pubkey: toHexString(delegation.pubkey) }, (targets && {
targets: targets.map(t => t.toHex()),
})),
signature: toHex(signature),
signature: toHexString(signature),
};
}),
publicKey: toHex(this.publicKey),
publicKey: toHexString(this.publicKey),
};

@@ -189,9 +195,5 @@ }

export class DelegationIdentity extends SignIdentity {
constructor(_inner, _delegation) {
super();
this._inner = _inner;
this._delegation = _delegation;
}
/**
* Create a delegation without having access to delegateKey.
*
* @param key The key used to sign the reqyests.

@@ -203,2 +205,7 @@ * @param delegation A delegation object created using `createDelegation`.

}
constructor(_inner, _delegation) {
super();
this._inner = _inner;
this._delegation = _delegation;
}
getDelegation() {

@@ -209,3 +216,2 @@ return this._delegation;

return {
derKey: this._delegation.publicKey,
toDer: () => this._delegation.publicKey,

@@ -212,0 +218,0 @@ };

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

*/
export declare type CryptoKeyOptions = {
export type CryptoKeyOptions = {
extractable?: boolean;

@@ -8,0 +8,0 @@ keyUsages?: KeyUsage[];

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

function _getEffectiveCrypto(subtleCrypto) {
if (typeof global !== 'undefined' && global['crypto'] && global['crypto']['subtle']) {
return global['crypto']['subtle'];
}
if (subtleCrypto) {

@@ -33,9 +30,2 @@ return subtleCrypto;

export class ECDSAKeyIdentity extends SignIdentity {
// `fromKeyPair` and `generate` should be used for instantiation, not this constructor.
constructor(keyPair, derKey, subtleCrypto) {
super();
this._keyPair = keyPair;
this._derKey = derKey;
this._subtleCrypto = subtleCrypto;
}
/**

@@ -71,2 +61,9 @@ * Generates a randomly generated identity for use in calls to the Internet Computer.

}
// `fromKeyPair` and `generate` should be used for instantiation, not this constructor.
constructor(keyPair, derKey, subtleCrypto) {
super();
this._keyPair = keyPair;
this._derKey = derKey;
this._subtleCrypto = subtleCrypto;
}
/**

@@ -73,0 +70,0 @@ * Return the internally-used key pair.

import { DerEncodedPublicKey, KeyPair, PublicKey, Signature, SignIdentity } from '@dfinity/agent';
export declare class Ed25519PublicKey implements PublicKey {
#private;
static from(key: PublicKey): Ed25519PublicKey;

@@ -10,4 +9,4 @@ static fromRaw(rawKey: ArrayBuffer): Ed25519PublicKey;

private static derDecode;
get rawKey(): ArrayBuffer;
get derKey(): DerEncodedPublicKey;
private readonly rawKey;
private readonly derKey;
private constructor();

@@ -18,3 +17,3 @@ toDer(): DerEncodedPublicKey;

export declare class Ed25519KeyIdentity extends SignIdentity {
#private;
protected _privateKey: ArrayBuffer;
static generate(seed?: Uint8Array): Ed25519KeyIdentity;

@@ -25,3 +24,4 @@ static fromParsedJson(obj: JsonnableEd25519KeyIdentity): Ed25519KeyIdentity;

static fromSecretKey(secretKey: ArrayBuffer): Ed25519KeyIdentity;
protected constructor(publicKey: PublicKey, privateKey: ArrayBuffer);
protected _publicKey: Ed25519PublicKey;
protected constructor(publicKey: PublicKey, _privateKey: ArrayBuffer);
/**

@@ -38,3 +38,3 @@ * Serialize this key to JSON.

*/
getPublicKey(): Required<PublicKey>;
getPublicKey(): PublicKey;
/**

@@ -45,14 +45,6 @@ * Signs a blob of data, with this identity's private key.

sign(challenge: ArrayBuffer): Promise<Signature>;
/**
* Verify
* @param sig - signature to verify
* @param msg - message to verify
* @param pk - public key
* @returns - true if the signature is valid, false otherwise
*/
static verify(sig: ArrayBuffer | Uint8Array | string, msg: ArrayBuffer | Uint8Array | string, pk: ArrayBuffer | Uint8Array | string): boolean;
}
declare type PublicKeyHex = string;
declare type SecretKeyHex = string;
export declare type JsonnableEd25519KeyIdentity = [PublicKeyHex, SecretKeyHex];
type PublicKeyHex = string;
type SecretKeyHex = string;
export type JsonnableEd25519KeyIdentity = [PublicKeyHex, SecretKeyHex];
export {};

@@ -1,26 +0,6 @@

var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _Ed25519PublicKey_rawKey, _Ed25519PublicKey_derKey, _Ed25519KeyIdentity_publicKey, _Ed25519KeyIdentity_privateKey;
import { SignIdentity, uint8ToBuf, ED25519_OID, unwrapDER, wrapDER, fromHex, toHex, } from '@dfinity/agent';
import { ed25519 } from '@noble/curves/ed25519';
import { SignIdentity } from '@dfinity/agent';
import * as tweetnacl from 'tweetnacl';
import { fromHexString, toHexString } from '../buffer';
import { ED25519_OID, unwrapDER, wrapDER } from './der';
export class Ed25519PublicKey {
// `fromRaw` and `fromDer` should be used for instantiation, not this constructor.
constructor(key) {
_Ed25519PublicKey_rawKey.set(this, void 0);
_Ed25519PublicKey_derKey.set(this, void 0);
if (key.byteLength !== Ed25519PublicKey.RAW_KEY_LENGTH) {
throw new Error('An Ed25519 public key must be exactly 32bytes long');
}
__classPrivateFieldSet(this, _Ed25519PublicKey_rawKey, key, "f");
__classPrivateFieldSet(this, _Ed25519PublicKey_derKey, Ed25519PublicKey.derEncode(key), "f");
}
static from(key) {

@@ -45,8 +25,7 @@ return this.fromDer(key.toDer());

}
get rawKey() {
return __classPrivateFieldGet(this, _Ed25519PublicKey_rawKey, "f");
// `fromRaw` and `fromDer` should be used for instantiation, not this constructor.
constructor(key) {
this.rawKey = key;
this.derKey = Ed25519PublicKey.derEncode(key);
}
get derKey() {
return __classPrivateFieldGet(this, _Ed25519PublicKey_derKey, "f");
}
toDer() {

@@ -59,29 +38,15 @@ return this.derKey;

}
_Ed25519PublicKey_rawKey = new WeakMap(), _Ed25519PublicKey_derKey = new WeakMap();
// The length of Ed25519 public keys is always 32 bytes.
Ed25519PublicKey.RAW_KEY_LENGTH = 32;
export class Ed25519KeyIdentity extends SignIdentity {
// `fromRaw` and `fromDer` should be used for instantiation, not this constructor.
constructor(publicKey, privateKey) {
super();
_Ed25519KeyIdentity_publicKey.set(this, void 0);
_Ed25519KeyIdentity_privateKey.set(this, void 0);
__classPrivateFieldSet(this, _Ed25519KeyIdentity_publicKey, Ed25519PublicKey.from(publicKey), "f");
__classPrivateFieldSet(this, _Ed25519KeyIdentity_privateKey, new Uint8Array(privateKey), "f");
}
static generate(seed = new Uint8Array(32)) {
static generate(seed) {
if (seed && seed.length !== 32) {
throw new Error('Ed25519 Seed needs to be 32 bytes long.');
}
if (!seed)
seed = ed25519.utils.randomPrivateKey();
const sk = new Uint8Array(32);
for (let i = 0; i < 32; i++)
sk[i] = new Uint8Array(seed)[i];
const pk = ed25519.getPublicKey(sk);
return Ed25519KeyIdentity.fromKeyPair(pk, sk);
const { publicKey, secretKey } = seed === undefined ? tweetnacl.sign.keyPair() : tweetnacl.sign.keyPair.fromSeed(seed);
return new this(Ed25519PublicKey.fromRaw(publicKey), secretKey);
}
static fromParsedJson(obj) {
const [publicKeyDer, privateKeyRaw] = obj;
return new Ed25519KeyIdentity(Ed25519PublicKey.fromDer(fromHex(publicKeyDer)), fromHex(privateKeyRaw));
return new Ed25519KeyIdentity(Ed25519PublicKey.fromDer(fromHexString(publicKeyDer)), fromHexString(privateKeyRaw));
}

@@ -104,5 +69,11 @@ static fromJSON(json) {

static fromSecretKey(secretKey) {
const publicKey = ed25519.getPublicKey(new Uint8Array(secretKey));
return Ed25519KeyIdentity.fromKeyPair(publicKey, secretKey);
const keyPair = tweetnacl.sign.keyPair.fromSecretKey(new Uint8Array(secretKey));
return Ed25519KeyIdentity.fromKeyPair(keyPair.publicKey, keyPair.secretKey);
}
// `fromRaw` and `fromDer` should be used for instantiation, not this constructor.
constructor(publicKey, _privateKey) {
super();
this._privateKey = _privateKey;
this._publicKey = Ed25519PublicKey.from(publicKey);
}
/**

@@ -112,3 +83,3 @@ * Serialize this key to JSON.

toJSON() {
return [toHex(__classPrivateFieldGet(this, _Ed25519KeyIdentity_publicKey, "f").toDer()), toHex(__classPrivateFieldGet(this, _Ed25519KeyIdentity_privateKey, "f"))];
return [toHexString(this._publicKey.toDer()), toHexString(this._privateKey)];
}

@@ -120,4 +91,4 @@ /**

return {
secretKey: __classPrivateFieldGet(this, _Ed25519KeyIdentity_privateKey, "f"),
publicKey: __classPrivateFieldGet(this, _Ed25519KeyIdentity_publicKey, "f"),
secretKey: this._privateKey,
publicKey: this._publicKey,
};

@@ -129,3 +100,3 @@ }

getPublicKey() {
return __classPrivateFieldGet(this, _Ed25519KeyIdentity_publicKey, "f");
return this._publicKey;
}

@@ -138,32 +109,6 @@ /**

const blob = new Uint8Array(challenge);
// Some implementations of Ed25519 private keys append a public key to the end of the private key. We only want the private key.
const signature = uint8ToBuf(ed25519.sign(blob, __classPrivateFieldGet(this, _Ed25519KeyIdentity_privateKey, "f").slice(0, 32)));
// add { __signature__: void; } to the signature to make it compatible with the agent
Object.defineProperty(signature, '__signature__', {
enumerable: false,
value: undefined,
});
const signature = tweetnacl.sign.detached(blob, new Uint8Array(this._privateKey)).buffer;
return signature;
}
/**
* Verify
* @param sig - signature to verify
* @param msg - message to verify
* @param pk - public key
* @returns - true if the signature is valid, false otherwise
*/
static verify(sig, msg, pk) {
const [signature, message, publicKey] = [sig, msg, pk].map(x => {
if (typeof x === 'string') {
x = fromHex(x);
}
if (x instanceof Uint8Array) {
x = x.buffer;
}
return new Uint8Array(x);
});
return ed25519.verify(message, signature, publicKey);
}
}
_Ed25519KeyIdentity_publicKey = new WeakMap(), _Ed25519KeyIdentity_privateKey = new WeakMap();
//# sourceMappingURL=ed25519.js.map

@@ -1,4 +0,6 @@

import { SignIdentity, wrapDER, DER_COSE_OID, fromHex, toHex, } from '@dfinity/agent';
import { SignIdentity } from '@dfinity/agent';
import borc from 'borc';
import { randomBytes } from '@noble/hashes/utils';
import * as tweetnacl from 'tweetnacl';
import { fromHexString, toHexString } from '../buffer';
import { DER_COSE_OID, wrapDER } from './der';
function _coseToDerEncodedBlob(cose) {

@@ -13,2 +15,3 @@ return wrapDER(cose, DER_COSE_OID).buffer;

* See https://webauthn.guide/#registration (subsection "Example: Parsing the authenticator data").
*
* @param authData The authData field of the attestation response.

@@ -42,2 +45,3 @@ * @returns The COSE key of the authData.

* generated.
*
* @param challenge The challenge to transform into a byte array. By default a hard

@@ -74,3 +78,3 @@ * coded string.

user: {
id: randomBytes(16),
id: tweetnacl.randomBytes(16),
name: 'Internet Identity',

@@ -101,8 +105,2 @@ displayName: 'Internet Identity',

export class WebAuthnIdentity extends SignIdentity {
constructor(rawId, cose, authenticatorAttachment) {
super();
this.rawId = rawId;
this.authenticatorAttachment = authenticatorAttachment;
this._publicKey = new CosePublicKey(cose);
}
/**

@@ -117,3 +115,3 @@ * Create an identity from a JSON serialization.

}
return new this(fromHex(rawId), fromHex(publicKey), undefined);
return new this(fromHexString(rawId), fromHexString(publicKey), undefined);
}

@@ -138,2 +136,8 @@ /**

}
constructor(rawId, cose, authenticatorAttachment) {
super();
this.rawId = rawId;
this.authenticatorAttachment = authenticatorAttachment;
this._publicKey = new CosePublicKey(cose);
}
getPublicKey() {

@@ -191,4 +195,4 @@ return this._publicKey;

return {
publicKey: toHex(this._publicKey.getCose()),
rawId: toHex(this.rawId),
publicKey: toHexString(this._publicKey.getCose()),
rawId: toHexString(this.rawId),
};

@@ -195,0 +199,0 @@ }

@@ -5,3 +5,3 @@ export { Ed25519KeyIdentity, Ed25519PublicKey } from './identity/ed25519';

export { WebAuthnIdentity } from './identity/webauthn';
export { wrapDER, unwrapDER, DER_COSE_OID, ED25519_OID } from '@dfinity/agent';
export { wrapDER, unwrapDER, DER_COSE_OID, ED25519_OID } from './identity/der';
/**

@@ -8,0 +8,0 @@ * @deprecated due to size of dependencies. Use `@dfinity/identity-secp256k1` instead.

@@ -5,3 +5,3 @@ export { Ed25519KeyIdentity, Ed25519PublicKey } from './identity/ed25519';

export { WebAuthnIdentity } from './identity/webauthn';
export { wrapDER, unwrapDER, DER_COSE_OID, ED25519_OID } from '@dfinity/agent';
export { wrapDER, unwrapDER, DER_COSE_OID, ED25519_OID } from './identity/der';
/**

@@ -8,0 +8,0 @@ * @deprecated due to size of dependencies. Use `@dfinity/identity-secp256k1` instead.

{
"name": "@dfinity/identity",
"version": "0.20.2",
"version": "0.21.1",
"author": "DFINITY Stiftung <sdk@dfinity.org>",

@@ -48,4 +48,4 @@ "license": "Apache-2.0",

"peerDependencies": {
"@dfinity/agent": "^0.20.2",
"@dfinity/principal": "^0.20.2",
"@dfinity/agent": "^0.21.1",
"@dfinity/principal": "^0.21.1",
"@peculiar/webcrypto": "^1.4.0"

@@ -52,0 +52,0 @@ },

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

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