Socket
Socket
Sign inDemoInstall

@dfinity/identity

Package Overview
Dependencies
Maintainers
11
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.19.2 to 0.19.3-react-native

14

lib/cjs/identity/delegation.js

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

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

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

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

@@ -74,3 +73,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, buffer_1.toHexString)(this.pubkey) }, (this.targets && { targets: this.targets.map(p => p.toHex()) }));
return Object.assign({ expiration: this.expiration.toString(16), pubkey: (0, agent_1.toHex)(this.pubkey) }, (this.targets && { targets: this.targets.map(p => p.toHex()) }));
}

@@ -168,3 +167,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 &&

@@ -197,9 +196,9 @@ targets.map((t) => {

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

@@ -235,2 +234,3 @@ }

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

@@ -237,0 +237,0 @@ };

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

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

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

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

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

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

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

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

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

@@ -45,2 +45,10 @@ * 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;
}

@@ -47,0 +55,0 @@ declare type PublicKeyHex = string;

"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 __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;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Ed25519KeyIdentity = exports.Ed25519PublicKey = void 0;
const agent_1 = require("@dfinity/agent");
const tweetnacl = __importStar(require("tweetnacl"));
const buffer_1 = require("../buffer");
const der_1 = require("./der");
const ed25519_1 = require("@noble/curves/ed25519");
class Ed25519PublicKey {
// `fromRaw` and `fromDer` should be used for instantiation, not this constructor.
constructor(key) {
this.rawKey = key;
this.derKey = Ed25519PublicKey.derEncode(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");
}

@@ -47,6 +39,6 @@ static from(key) {

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

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

}
get rawKey() {
return __classPrivateFieldGet(this, _Ed25519PublicKey_rawKey, "f");
}
get derKey() {
return __classPrivateFieldGet(this, _Ed25519PublicKey_derKey, "f");
}
toDer() {

@@ -66,2 +64,3 @@ return this.derKey;

exports.Ed25519PublicKey = Ed25519PublicKey;
_Ed25519PublicKey_rawKey = new WeakMap(), _Ed25519PublicKey_derKey = new WeakMap();
// The length of Ed25519 public keys is always 32 bytes.

@@ -71,17 +70,24 @@ Ed25519PublicKey.RAW_KEY_LENGTH = 32;

// `fromRaw` and `fromDer` should be used for instantiation, not this constructor.
constructor(publicKey, _privateKey) {
constructor(publicKey, privateKey) {
super();
this._privateKey = _privateKey;
this._publicKey = Ed25519PublicKey.from(publicKey);
_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) {
static generate(seed = new Uint8Array(32)) {
if (seed && seed.length !== 32) {
throw new Error('Ed25519 Seed needs to be 32 bytes long.');
}
const { publicKey, secretKey } = seed === undefined ? tweetnacl.sign.keyPair() : tweetnacl.sign.keyPair.fromSeed(seed);
return new this(Ed25519PublicKey.fromRaw(publicKey), secretKey);
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);
}
static fromParsedJson(obj) {
const [publicKeyDer, privateKeyRaw] = obj;
return new Ed25519KeyIdentity(Ed25519PublicKey.fromDer((0, buffer_1.fromHexString)(publicKeyDer)), (0, buffer_1.fromHexString)(privateKeyRaw));
return new Ed25519KeyIdentity(Ed25519PublicKey.fromDer((0, agent_1.fromHex)(publicKeyDer)), (0, agent_1.fromHex)(privateKeyRaw));
}

@@ -104,4 +110,4 @@ static fromJSON(json) {

static fromSecretKey(secretKey) {
const keyPair = tweetnacl.sign.keyPair.fromSecretKey(new Uint8Array(secretKey));
return Ed25519KeyIdentity.fromKeyPair(keyPair.publicKey, keyPair.secretKey);
const publicKey = ed25519_1.ed25519.getPublicKey(new Uint8Array(secretKey));
return Ed25519KeyIdentity.fromKeyPair(publicKey, secretKey);
}

@@ -112,3 +118,3 @@ /**

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

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

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

@@ -129,3 +135,3 @@ }

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

@@ -138,7 +144,33 @@ /**

const blob = new Uint8Array(challenge);
const signature = tweetnacl.sign.detached(blob, new Uint8Array(this._privateKey)).buffer;
// 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,
});
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) {

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

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

@@ -107,3 +82,3 @@ /**

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

@@ -149,3 +124,3 @@ displayName: 'Internet Identity',

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

@@ -222,4 +197,4 @@ /**

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

@@ -226,0 +201,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 './identity/der';
export { wrapDER, unwrapDER, DER_COSE_OID, ED25519_OID } from '@dfinity/agent';
/**

@@ -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 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; } });
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; } });
/**

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

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

};
import { requestIdOf, SignIdentity, } from '@dfinity/agent';
import { fromHex, requestIdOf, SignIdentity, toHex, } 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');

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

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

@@ -48,3 +47,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: toHexString(this.pubkey) }, (this.targets && { targets: this.targets.map(p => p.toHex()) }));
return Object.assign({ expiration: this.expiration.toString(16), pubkey: toHex(this.pubkey) }, (this.targets && { targets: this.targets.map(p => p.toHex()) }));
}

@@ -141,3 +140,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 &&

@@ -170,9 +169,9 @@ targets.map((t) => {

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

@@ -207,2 +206,3 @@ }

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

@@ -209,0 +209,0 @@ };

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

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

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

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

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

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

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

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

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

@@ -45,2 +45,10 @@ * 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;
}

@@ -47,0 +55,0 @@ declare type PublicKeyHex = string;

@@ -1,10 +0,25 @@

import { SignIdentity } from '@dfinity/agent';
import * as tweetnacl from 'tweetnacl';
import { fromHexString, toHexString } from '../buffer';
import { ED25519_OID, unwrapDER, wrapDER } from './der';
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';
export class Ed25519PublicKey {
// `fromRaw` and `fromDer` should be used for instantiation, not this constructor.
constructor(key) {
this.rawKey = key;
this.derKey = Ed25519PublicKey.derEncode(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");
}

@@ -30,2 +45,8 @@ static from(key) {

}
get rawKey() {
return __classPrivateFieldGet(this, _Ed25519PublicKey_rawKey, "f");
}
get derKey() {
return __classPrivateFieldGet(this, _Ed25519PublicKey_derKey, "f");
}
toDer() {

@@ -38,2 +59,3 @@ return this.derKey;

}
_Ed25519PublicKey_rawKey = new WeakMap(), _Ed25519PublicKey_derKey = new WeakMap();
// The length of Ed25519 public keys is always 32 bytes.

@@ -43,17 +65,24 @@ Ed25519PublicKey.RAW_KEY_LENGTH = 32;

// `fromRaw` and `fromDer` should be used for instantiation, not this constructor.
constructor(publicKey, _privateKey) {
constructor(publicKey, privateKey) {
super();
this._privateKey = _privateKey;
this._publicKey = Ed25519PublicKey.from(publicKey);
_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) {
static generate(seed = new Uint8Array(32)) {
if (seed && seed.length !== 32) {
throw new Error('Ed25519 Seed needs to be 32 bytes long.');
}
const { publicKey, secretKey } = seed === undefined ? tweetnacl.sign.keyPair() : tweetnacl.sign.keyPair.fromSeed(seed);
return new this(Ed25519PublicKey.fromRaw(publicKey), secretKey);
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);
}
static fromParsedJson(obj) {
const [publicKeyDer, privateKeyRaw] = obj;
return new Ed25519KeyIdentity(Ed25519PublicKey.fromDer(fromHexString(publicKeyDer)), fromHexString(privateKeyRaw));
return new Ed25519KeyIdentity(Ed25519PublicKey.fromDer(fromHex(publicKeyDer)), fromHex(privateKeyRaw));
}

@@ -76,4 +105,4 @@ static fromJSON(json) {

static fromSecretKey(secretKey) {
const keyPair = tweetnacl.sign.keyPair.fromSecretKey(new Uint8Array(secretKey));
return Ed25519KeyIdentity.fromKeyPair(keyPair.publicKey, keyPair.secretKey);
const publicKey = ed25519.getPublicKey(new Uint8Array(secretKey));
return Ed25519KeyIdentity.fromKeyPair(publicKey, secretKey);
}

@@ -84,3 +113,3 @@ /**

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

@@ -92,4 +121,4 @@ /**

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

@@ -101,3 +130,3 @@ }

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

@@ -110,6 +139,32 @@ /**

const blob = new Uint8Array(challenge);
const signature = tweetnacl.sign.detached(blob, new Uint8Array(this._privateKey)).buffer;
// 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,
});
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,6 +0,4 @@

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

@@ -76,3 +74,3 @@ return wrapDER(cose, DER_COSE_OID).buffer;

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

@@ -118,3 +116,3 @@ displayName: 'Internet Identity',

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

@@ -191,4 +189,4 @@ /**

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

@@ -195,0 +193,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 './identity/der';
export { wrapDER, unwrapDER, DER_COSE_OID, ED25519_OID } from '@dfinity/agent';
/**

@@ -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 './identity/der';
export { wrapDER, unwrapDER, DER_COSE_OID, ED25519_OID } from '@dfinity/agent';
/**

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

{
"name": "@dfinity/identity",
"version": "0.19.2",
"version": "0.19.3-react-native",
"author": "DFINITY Stiftung <sdk@dfinity.org>",

@@ -44,3 +44,2 @@ "license": "Apache-2.0",

"make:docs/reference": "typedoc src/index.ts --out ../../docs/generated/identity",
"release": "npm publish",
"test": "jest",

@@ -50,10 +49,10 @@ "test:coverage": "jest --verbose --collectCoverage"

"peerDependencies": {
"@dfinity/agent": "^0.19.2",
"@dfinity/principal": "^0.19.2",
"@dfinity/agent": "^0.19.3-react-native",
"@dfinity/principal": "^0.19.3-react-native",
"@peculiar/webcrypto": "^1.4.0"
},
"dependencies": {
"@noble/curves": "^1.2.0",
"@noble/hashes": "^1.3.1",
"borc": "^2.1.1",
"tweetnacl": "^1.0.1"
"borc": "^2.1.1"
},

@@ -60,0 +59,0 @@ "devDependencies": {

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