Socket
Socket
Sign inDemoInstall

@dfinity/identity

Package Overview
Dependencies
Maintainers
7
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.9.3 to 0.10.0-beta.1

lib/cjs/buffer.d.ts

33

lib/cjs/identity/delegation.d.ts

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

import { HttpAgentRequest, PublicKey, SignIdentity } from '@dfinity/agent';
import { BinaryBlob, DerEncodedBlob } from '@dfinity/candid';
import { DerEncodedPublicKey, HttpAgentRequest, PublicKey, Signature, SignIdentity } from '@dfinity/agent';
import { Principal } from '@dfinity/principal';

@@ -12,6 +11,6 @@ import * as cbor from 'simple-cbor';

export declare class Delegation {
readonly pubkey: BinaryBlob;
readonly pubkey: ArrayBuffer;
readonly expiration: bigint;
readonly targets?: Principal[] | undefined;
constructor(pubkey: BinaryBlob, expiration: bigint, targets?: Principal[] | undefined);
constructor(pubkey: ArrayBuffer, expiration: bigint, targets?: Principal[] | undefined);
toCBOR(): cbor.CborValue;

@@ -22,7 +21,5 @@ toJSON(): JsonnableDelegation;

* Type of ReturnType<Delegation.toJSON>.
* The goal here is to stringify all non-JSON-compatible types to some bytes representation we can stringify as hex.
* The goal here is to stringify all non-JSON-compatible types to some bytes representation we can
* stringify as hex.
* (Hex shouldn't be ambiguous ever, because you can encode as DER with semantic OIDs).
* * expiration is a BigInt of Nanoseconds since epoch as hex
* * pubkey is hex of DER publicKey
* * targets is array of strings, where each string is hex of principal blob (*NOT* textual representation)
*/

@@ -32,3 +29,3 @@ interface JsonnableDelegation {

pubkey: string;
targets?: Array<string>;
targets?: string[];
}

@@ -43,5 +40,5 @@ /**

delegation: Delegation;
signature: BinaryBlob;
signature: Signature;
}
interface IJsonnableDelegationChain {
export interface JsonnableDelegationChain {
publicKey: string;

@@ -64,3 +61,3 @@ delegations: Array<{

readonly delegations: SignedDelegation[];
readonly publicKey: DerEncodedBlob;
readonly publicKey: DerEncodedPublicKey;
/**

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

previous?: DelegationChain;
targets?: Array<Principal>;
targets?: Principal[];
}): Promise<DelegationChain>;

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

*/
static fromJSON(json: string | IJsonnableDelegationChain): DelegationChain;
static fromJSON(json: string | JsonnableDelegationChain): DelegationChain;
/**

@@ -115,5 +112,5 @@ * Creates a DelegationChain object from a list of delegations and a DER-encoded public key.

*/
static fromDelegations(delegations: SignedDelegation[], publicKey: DerEncodedBlob): DelegationChain;
protected constructor(delegations: SignedDelegation[], publicKey: DerEncodedBlob);
toJSON(): IJsonnableDelegationChain;
static fromDelegations(delegations: SignedDelegation[], publicKey: DerEncodedPublicKey): DelegationChain;
protected constructor(delegations: SignedDelegation[], publicKey: DerEncodedPublicKey);
toJSON(): JsonnableDelegationChain;
}

@@ -139,5 +136,5 @@ /**

getPublicKey(): PublicKey;
sign(blob: BinaryBlob): Promise<BinaryBlob>;
sign(blob: ArrayBuffer): Promise<Signature>;
transformRequest(request: HttpAgentRequest): Promise<unknown>;
}
export {};

@@ -35,8 +35,7 @@ "use strict";

const agent_1 = require("@dfinity/agent");
const candid_1 = require("@dfinity/candid");
const principal_1 = require("@dfinity/principal");
const buffer_1 = require("buffer/");
const cbor = __importStar(require("simple-cbor"));
const buffer_1 = require("../buffer");
const domainSeparator = new TextEncoder().encode('\x1Aic-request-auth-delegation');
const requestDomainSeparator = buffer_1.Buffer.from(new TextEncoder().encode('\x0Aic-request'));
const requestDomainSeparator = new TextEncoder().encode('\x0Aic-request');
function _parseBlob(value) {

@@ -46,3 +45,3 @@ if (typeof value !== 'string' || value.length < 64) {

}
return candid_1.blobFromHex(value);
return buffer_1.fromHexString(value);
}

@@ -69,5 +68,5 @@ /**

// every string should be hex and once-de-hexed,
// discoverable what it is (e.g. de-hex to get JSON with a 'type' property, or de-hex to DER 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: this.pubkey.toString('hex') }, (this.targets && { targets: this.targets.map(p => p.toHex()) }));
// discoverable what it is (e.g. de-hex to get JSON with a 'type' property, or de-hex to DER
// 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: buffer_1.toHexString(this.pubkey) }, (this.targets && { targets: this.targets.map(p => p.toHex()) }));
}

@@ -92,4 +91,7 @@ }

// a user gesture if you await an async call thats not fetch, xhr, or setTimeout.
const challenge = new Uint8Array([...domainSeparator, ...agent_1.requestIdOf(delegation)]);
const signature = await from.sign(candid_1.blobFromUint8Array(challenge));
const challenge = new Uint8Array([
...domainSeparator,
...new Uint8Array(agent_1.requestIdOf(delegation)),
]);
const signature = await from.sign(challenge);
return {

@@ -174,3 +176,3 @@ delegation,

});
return new this(parsedDelegations, candid_1.derBlobFromBlob(_parseBlob(publicKey)));
return new this(parsedDelegations, _parseBlob(publicKey));
}

@@ -192,9 +194,9 @@ /**

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

@@ -241,3 +243,3 @@ }

content: body,
sender_sig: await this.sign(candid_1.blobFromUint8Array(buffer_1.Buffer.concat([requestDomainSeparator, requestId]))),
sender_sig: await this.sign(new Uint8Array([...requestDomainSeparator, ...new Uint8Array(requestId)])),
sender_delegation: this._delegation.delegations,

@@ -244,0 +246,0 @@ sender_pubkey: this._delegation.publicKey,

@@ -13,6 +13,6 @@ /**

*
* @param paylod The payload to encode as the bit string
* @param payload The payload to encode as the bit string
* @param oid The DER encoded (and SEQUENCE wrapped!) OID to tag the payload with
*/
export declare const wrapDER: (payload: ArrayBuffer, oid: Uint8Array) => Uint8Array;
export declare function wrapDER(payload: ArrayBuffer, oid: Uint8Array): Uint8Array;
/**

@@ -19,0 +19,0 @@ * Extracts a payload from the given `derEncoded` data, and checks that it was tagged with the given `oid`.

@@ -92,6 +92,6 @@ "use strict";

*
* @param paylod The payload to encode as the bit string
* @param payload The payload to encode as the bit string
* @param oid The DER encoded (and SEQUENCE wrapped!) OID to tag the payload with
*/
const wrapDER = (payload, oid) => {
function wrapDER(payload, oid) {
// The Bit String header needs to include the unused bit count byte in its length

@@ -116,3 +116,3 @@ const bitStringHeaderLength = 2 + encodeLenBytes(payload.byteLength + 1);

return buf;
};
}
exports.wrapDER = wrapDER;

@@ -131,4 +131,5 @@ /**

const expect = (n, msg) => {
if (buf[offset++] !== n)
if (buf[offset++] !== n) {
throw new Error('Expected: ' + msg);
}
};

@@ -135,0 +136,0 @@ const buf = new Uint8Array(derEncoded);

@@ -1,7 +0,6 @@

import { KeyPair, PublicKey, SignIdentity } from '@dfinity/agent';
import { BinaryBlob, DerEncodedBlob } from '@dfinity/candid';
import { DerEncodedPublicKey, KeyPair, PublicKey, Signature, SignIdentity } from '@dfinity/agent';
export declare class Ed25519PublicKey implements PublicKey {
static from(key: PublicKey): Ed25519PublicKey;
static fromRaw(rawKey: BinaryBlob): Ed25519PublicKey;
static fromDer(derKey: BinaryBlob): Ed25519PublicKey;
static fromRaw(rawKey: ArrayBuffer): Ed25519PublicKey;
static fromDer(derKey: DerEncodedPublicKey): Ed25519PublicKey;
private static RAW_KEY_LENGTH;

@@ -13,14 +12,14 @@ private static derEncode;

private constructor();
toDer(): DerEncodedBlob;
toRaw(): BinaryBlob;
toDer(): DerEncodedPublicKey;
toRaw(): ArrayBuffer;
}
export declare class Ed25519KeyIdentity extends SignIdentity {
protected _privateKey: BinaryBlob;
protected _privateKey: ArrayBuffer;
static generate(seed?: Uint8Array): Ed25519KeyIdentity;
static fromParsedJson(obj: JsonnableEd25519KeyIdentity): Ed25519KeyIdentity;
static fromJSON(json: string): Ed25519KeyIdentity;
static fromKeyPair(publicKey: BinaryBlob, privateKey: BinaryBlob): Ed25519KeyIdentity;
static fromKeyPair(publicKey: ArrayBuffer, privateKey: ArrayBuffer): Ed25519KeyIdentity;
static fromSecretKey(secretKey: ArrayBuffer): Ed25519KeyIdentity;
protected _publicKey: Ed25519PublicKey;
protected constructor(publicKey: PublicKey, _privateKey: BinaryBlob);
protected constructor(publicKey: PublicKey, _privateKey: ArrayBuffer);
/**

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

*/
sign(challenge: BinaryBlob | ArrayBuffer): Promise<BinaryBlob>;
sign(challenge: ArrayBuffer): Promise<Signature>;
}

@@ -45,0 +44,0 @@ declare type PublicKeyHex = string;

@@ -24,5 +24,4 @@ "use strict";

const agent_1 = require("@dfinity/agent");
const candid_1 = require("@dfinity/candid");
const buffer_1 = require("buffer/");
const tweetnacl = __importStar(require("tweetnacl"));
const buffer_1 = require("../buffer");
const der_1 = require("./der");

@@ -45,3 +44,3 @@ class Ed25519PublicKey {

static derEncode(publicKey) {
return candid_1.derBlobFromBlob(candid_1.blobFromUint8Array(der_1.wrapDER(publicKey, der_1.ED25519_OID)));
return der_1.wrapDER(publicKey, der_1.ED25519_OID).buffer;
}

@@ -53,3 +52,3 @@ static derDecode(key) {

}
return candid_1.blobFromUint8Array(unwrapped);
return unwrapped;
}

@@ -78,7 +77,7 @@ toDer() {

const { publicKey, secretKey } = seed === undefined ? tweetnacl.sign.keyPair() : tweetnacl.sign.keyPair.fromSeed(seed);
return new this(Ed25519PublicKey.fromRaw(candid_1.blobFromUint8Array(publicKey)), candid_1.blobFromUint8Array(secretKey));
return new this(Ed25519PublicKey.fromRaw(publicKey), secretKey);
}
static fromParsedJson(obj) {
const [publicKeyDer, privateKeyRaw] = obj;
return new Ed25519KeyIdentity(Ed25519PublicKey.fromDer(candid_1.blobFromHex(publicKeyDer)), candid_1.blobFromHex(privateKeyRaw));
return new Ed25519KeyIdentity(Ed25519PublicKey.fromDer(buffer_1.fromHexString(publicKeyDer)), buffer_1.fromHexString(privateKeyRaw));
}

@@ -96,12 +95,3 @@ static fromJSON(json) {

else if (typeof parsed === 'object' && parsed !== null) {
const { publicKey, _publicKey, secretKey, _privateKey } = parsed;
const pk = publicKey
? Ed25519PublicKey.fromRaw(candid_1.blobFromUint8Array(new Uint8Array(publicKey.data)))
: Ed25519PublicKey.fromDer(candid_1.blobFromUint8Array(new Uint8Array(_publicKey.data)));
if (publicKey && secretKey && secretKey.data) {
return new Ed25519KeyIdentity(pk, candid_1.blobFromUint8Array(new Uint8Array(secretKey.data)));
}
else if (_publicKey && _privateKey && _privateKey.data) {
return new Ed25519KeyIdentity(pk, candid_1.blobFromUint8Array(new Uint8Array(_privateKey.data)));
}
throw new Error('Deprecated JSON format for Ed25519 keys.');
}

@@ -115,4 +105,3 @@ throw new Error(`Deserialization error: Invalid JSON type for string: ${JSON.stringify(json)}`);

const keyPair = tweetnacl.sign.keyPair.fromSecretKey(new Uint8Array(secretKey));
const identity = Ed25519KeyIdentity.fromKeyPair(candid_1.blobFromUint8Array(keyPair.publicKey), candid_1.blobFromUint8Array(keyPair.secretKey));
return identity;
return Ed25519KeyIdentity.fromKeyPair(keyPair.publicKey, keyPair.secretKey);
}

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

toJSON() {
return [candid_1.blobToHex(this._publicKey.toDer()), candid_1.blobToHex(this._privateKey)];
return [buffer_1.toHexString(this._publicKey.toDer()), buffer_1.toHexString(this._privateKey)];
}

@@ -131,3 +120,3 @@ /**

return {
secretKey: candid_1.blobFromUint8Array(new Uint8Array(this._privateKey)),
secretKey: this._privateKey,
publicKey: this._publicKey,

@@ -147,7 +136,5 @@ };

async sign(challenge) {
const blob = challenge instanceof buffer_1.Buffer
? candid_1.blobFromBuffer(challenge)
: candid_1.blobFromUint8Array(new Uint8Array(challenge));
const signature = tweetnacl.sign.detached(blob, this._privateKey);
return candid_1.blobFromUint8Array(signature);
const blob = new Uint8Array(challenge);
const signature = tweetnacl.sign.detached(blob, new Uint8Array(this._privateKey)).buffer;
return signature;
}

@@ -154,0 +141,0 @@ }

@@ -1,9 +0,8 @@

import { PublicKey, SignIdentity } from '@dfinity/agent';
import { BinaryBlob, DerEncodedBlob } from '@dfinity/candid';
import { DerEncodedPublicKey, PublicKey, Signature, SignIdentity } from '@dfinity/agent';
export declare class CosePublicKey implements PublicKey {
protected _cose: BinaryBlob;
protected _encodedKey: DerEncodedBlob;
constructor(_cose: BinaryBlob);
toDer(): DerEncodedBlob;
getCose(): BinaryBlob;
protected _cose: ArrayBuffer;
protected _encodedKey: DerEncodedPublicKey;
constructor(_cose: ArrayBuffer);
toDer(): DerEncodedPublicKey;
getCose(): ArrayBuffer;
}

@@ -15,3 +14,3 @@ /**

export declare class WebAuthnIdentity extends SignIdentity {
readonly rawId: BinaryBlob;
readonly rawId: ArrayBuffer;
/**

@@ -28,5 +27,5 @@ * Create an identity from a JSON serialization.

protected _publicKey: CosePublicKey;
protected constructor(rawId: BinaryBlob, cose: BinaryBlob);
protected constructor(rawId: ArrayBuffer, cose: ArrayBuffer);
getPublicKey(): PublicKey;
sign(blob: BinaryBlob): Promise<BinaryBlob>;
sign(blob: ArrayBuffer): Promise<Signature>;
/**

@@ -39,4 +38,2 @@ * Allow for JSON serialization of all information needed to reuse this identity.

* ReturnType<WebAuthnIdentity.toJSON>
* * publicKey is hex(der(publicKey))
* * rawId is the string representation of the local WebAuthn Credential.id (iirc it is base64url encoded)
*/

@@ -43,0 +40,0 @@ export interface JsonnableWebAuthnIdentitiy {

@@ -27,8 +27,8 @@ "use strict";

const agent_1 = require("@dfinity/agent");
const candid_1 = require("@dfinity/candid");
const borc_1 = __importDefault(require("borc"));
const tweetnacl = __importStar(require("tweetnacl"));
const buffer_1 = require("../buffer");
const der_1 = require("./der");
function _coseToDerEncodedBlob(cose) {
return candid_1.derBlobFromBlob(candid_1.blobFromUint8Array(der_1.wrapDER(cose, der_1.DER_COSE_OID)));
return der_1.wrapDER(cose, der_1.DER_COSE_OID).buffer;
}

@@ -143,3 +143,3 @@ /**

}
return new this(candid_1.blobFromHex(rawId), candid_1.blobFromHex(publicKey));
return new this(buffer_1.fromHexString(rawId), buffer_1.fromHexString(publicKey));
}

@@ -161,3 +161,3 @@ /**

const attObject = borc_1.default.decodeFirst(new Uint8Array(response.attestationObject));
return new this(candid_1.blobFromUint8Array(new Uint8Array(creds.rawId)), candid_1.blobFromUint8Array(new Uint8Array(_authDataToCose(attObject.authData))));
return new this(creds.rawId, _authDataToCose(attObject.authData));
}

@@ -191,3 +191,3 @@ getPublicKey() {

}
return candid_1.blobFromUint8Array(new Uint8Array(cbor));
return cbor.buffer;
}

@@ -203,4 +203,4 @@ else {

return {
publicKey: this._publicKey.getCose().toString('hex'),
rawId: this.rawId.toString('hex'),
publicKey: buffer_1.toHexString(this._publicKey.getCose()),
rawId: buffer_1.toHexString(this.rawId),
};

@@ -207,0 +207,0 @@ }

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

import { HttpAgentRequest, PublicKey, SignIdentity } from '@dfinity/agent';
import { BinaryBlob, DerEncodedBlob } from '@dfinity/candid';
import { DerEncodedPublicKey, HttpAgentRequest, PublicKey, Signature, SignIdentity } from '@dfinity/agent';
import { Principal } from '@dfinity/principal';

@@ -12,6 +11,6 @@ import * as cbor from 'simple-cbor';

export declare class Delegation {
readonly pubkey: BinaryBlob;
readonly pubkey: ArrayBuffer;
readonly expiration: bigint;
readonly targets?: Principal[] | undefined;
constructor(pubkey: BinaryBlob, expiration: bigint, targets?: Principal[] | undefined);
constructor(pubkey: ArrayBuffer, expiration: bigint, targets?: Principal[] | undefined);
toCBOR(): cbor.CborValue;

@@ -22,7 +21,5 @@ toJSON(): JsonnableDelegation;

* Type of ReturnType<Delegation.toJSON>.
* The goal here is to stringify all non-JSON-compatible types to some bytes representation we can stringify as hex.
* The goal here is to stringify all non-JSON-compatible types to some bytes representation we can
* stringify as hex.
* (Hex shouldn't be ambiguous ever, because you can encode as DER with semantic OIDs).
* * expiration is a BigInt of Nanoseconds since epoch as hex
* * pubkey is hex of DER publicKey
* * targets is array of strings, where each string is hex of principal blob (*NOT* textual representation)
*/

@@ -32,3 +29,3 @@ interface JsonnableDelegation {

pubkey: string;
targets?: Array<string>;
targets?: string[];
}

@@ -43,5 +40,5 @@ /**

delegation: Delegation;
signature: BinaryBlob;
signature: Signature;
}
interface IJsonnableDelegationChain {
export interface JsonnableDelegationChain {
publicKey: string;

@@ -64,3 +61,3 @@ delegations: Array<{

readonly delegations: SignedDelegation[];
readonly publicKey: DerEncodedBlob;
readonly publicKey: DerEncodedPublicKey;
/**

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

previous?: DelegationChain;
targets?: Array<Principal>;
targets?: Principal[];
}): Promise<DelegationChain>;

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

*/
static fromJSON(json: string | IJsonnableDelegationChain): DelegationChain;
static fromJSON(json: string | JsonnableDelegationChain): DelegationChain;
/**

@@ -115,5 +112,5 @@ * Creates a DelegationChain object from a list of delegations and a DER-encoded public key.

*/
static fromDelegations(delegations: SignedDelegation[], publicKey: DerEncodedBlob): DelegationChain;
protected constructor(delegations: SignedDelegation[], publicKey: DerEncodedBlob);
toJSON(): IJsonnableDelegationChain;
static fromDelegations(delegations: SignedDelegation[], publicKey: DerEncodedPublicKey): DelegationChain;
protected constructor(delegations: SignedDelegation[], publicKey: DerEncodedPublicKey);
toJSON(): JsonnableDelegationChain;
}

@@ -139,5 +136,5 @@ /**

getPublicKey(): PublicKey;
sign(blob: BinaryBlob): Promise<BinaryBlob>;
sign(blob: ArrayBuffer): Promise<Signature>;
transformRequest(request: HttpAgentRequest): Promise<unknown>;
}
export {};

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

};
import { requestIdOf, SignIdentity } from '@dfinity/agent';
import { blobFromHex, blobFromUint8Array, derBlobFromBlob, } from '@dfinity/candid';
import { requestIdOf, SignIdentity, } from '@dfinity/agent';
import { Principal } from '@dfinity/principal';
import { Buffer } from 'buffer/';
import * as cbor from 'simple-cbor';
import { fromHexString, toHexString } from '../buffer';
const domainSeparator = new TextEncoder().encode('\x1Aic-request-auth-delegation');
const requestDomainSeparator = Buffer.from(new TextEncoder().encode('\x0Aic-request'));
const requestDomainSeparator = new TextEncoder().encode('\x0Aic-request');
function _parseBlob(value) {

@@ -24,3 +23,3 @@ if (typeof value !== 'string' || value.length < 64) {

}
return blobFromHex(value);
return fromHexString(value);
}

@@ -47,5 +46,5 @@ /**

// every string should be hex and once-de-hexed,
// discoverable what it is (e.g. de-hex to get JSON with a 'type' property, or de-hex to DER 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: this.pubkey.toString('hex') }, (this.targets && { targets: this.targets.map(p => p.toHex()) }));
// discoverable what it is (e.g. de-hex to get JSON with a 'type' property, or de-hex to DER
// 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()) }));
}

@@ -69,4 +68,7 @@ }

// a user gesture if you await an async call thats not fetch, xhr, or setTimeout.
const challenge = new Uint8Array([...domainSeparator, ...requestIdOf(delegation)]);
const signature = await from.sign(blobFromUint8Array(challenge));
const challenge = new Uint8Array([
...domainSeparator,
...new Uint8Array(requestIdOf(delegation)),
]);
const signature = await from.sign(challenge);
return {

@@ -151,3 +153,3 @@ delegation,

});
return new this(parsedDelegations, derBlobFromBlob(_parseBlob(publicKey)));
return new this(parsedDelegations, _parseBlob(publicKey));
}

@@ -169,9 +171,9 @@ /**

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

@@ -217,3 +219,3 @@ }

content: body,
sender_sig: await this.sign(blobFromUint8Array(Buffer.concat([requestDomainSeparator, requestId]))),
sender_sig: await this.sign(new Uint8Array([...requestDomainSeparator, ...new Uint8Array(requestId)])),
sender_delegation: this._delegation.delegations,

@@ -220,0 +222,0 @@ sender_pubkey: this._delegation.publicKey,

@@ -13,6 +13,6 @@ /**

*
* @param paylod The payload to encode as the bit string
* @param payload The payload to encode as the bit string
* @param oid The DER encoded (and SEQUENCE wrapped!) OID to tag the payload with
*/
export declare const wrapDER: (payload: ArrayBuffer, oid: Uint8Array) => Uint8Array;
export declare function wrapDER(payload: ArrayBuffer, oid: Uint8Array): Uint8Array;
/**

@@ -19,0 +19,0 @@ * Extracts a payload from the given `derEncoded` data, and checks that it was tagged with the given `oid`.

@@ -89,6 +89,6 @@ const bufEquals = (b1, b2) => {

*
* @param paylod The payload to encode as the bit string
* @param payload The payload to encode as the bit string
* @param oid The DER encoded (and SEQUENCE wrapped!) OID to tag the payload with
*/
export const wrapDER = (payload, oid) => {
export function wrapDER(payload, oid) {
// The Bit String header needs to include the unused bit count byte in its length

@@ -113,3 +113,3 @@ const bitStringHeaderLength = 2 + encodeLenBytes(payload.byteLength + 1);

return buf;
};
}
/**

@@ -127,4 +127,5 @@ * Extracts a payload from the given `derEncoded` data, and checks that it was tagged with the given `oid`.

const expect = (n, msg) => {
if (buf[offset++] !== n)
if (buf[offset++] !== n) {
throw new Error('Expected: ' + msg);
}
};

@@ -131,0 +132,0 @@ const buf = new Uint8Array(derEncoded);

@@ -1,7 +0,6 @@

import { KeyPair, PublicKey, SignIdentity } from '@dfinity/agent';
import { BinaryBlob, DerEncodedBlob } from '@dfinity/candid';
import { DerEncodedPublicKey, KeyPair, PublicKey, Signature, SignIdentity } from '@dfinity/agent';
export declare class Ed25519PublicKey implements PublicKey {
static from(key: PublicKey): Ed25519PublicKey;
static fromRaw(rawKey: BinaryBlob): Ed25519PublicKey;
static fromDer(derKey: BinaryBlob): Ed25519PublicKey;
static fromRaw(rawKey: ArrayBuffer): Ed25519PublicKey;
static fromDer(derKey: DerEncodedPublicKey): Ed25519PublicKey;
private static RAW_KEY_LENGTH;

@@ -13,14 +12,14 @@ private static derEncode;

private constructor();
toDer(): DerEncodedBlob;
toRaw(): BinaryBlob;
toDer(): DerEncodedPublicKey;
toRaw(): ArrayBuffer;
}
export declare class Ed25519KeyIdentity extends SignIdentity {
protected _privateKey: BinaryBlob;
protected _privateKey: ArrayBuffer;
static generate(seed?: Uint8Array): Ed25519KeyIdentity;
static fromParsedJson(obj: JsonnableEd25519KeyIdentity): Ed25519KeyIdentity;
static fromJSON(json: string): Ed25519KeyIdentity;
static fromKeyPair(publicKey: BinaryBlob, privateKey: BinaryBlob): Ed25519KeyIdentity;
static fromKeyPair(publicKey: ArrayBuffer, privateKey: ArrayBuffer): Ed25519KeyIdentity;
static fromSecretKey(secretKey: ArrayBuffer): Ed25519KeyIdentity;
protected _publicKey: Ed25519PublicKey;
protected constructor(publicKey: PublicKey, _privateKey: BinaryBlob);
protected constructor(publicKey: PublicKey, _privateKey: ArrayBuffer);
/**

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

*/
sign(challenge: BinaryBlob | ArrayBuffer): Promise<BinaryBlob>;
sign(challenge: ArrayBuffer): Promise<Signature>;
}

@@ -45,0 +44,0 @@ declare type PublicKeyHex = string;

import { SignIdentity } from '@dfinity/agent';
import { blobFromHex, blobFromUint8Array, blobToHex, derBlobFromBlob, blobFromBuffer, } from '@dfinity/candid';
import { Buffer } from 'buffer/';
import * as tweetnacl from 'tweetnacl';
import { fromHexString, toHexString } from '../buffer';
import { ED25519_OID, unwrapDER, wrapDER } from './der';

@@ -22,3 +21,3 @@ export class Ed25519PublicKey {

static derEncode(publicKey) {
return derBlobFromBlob(blobFromUint8Array(wrapDER(publicKey, ED25519_OID)));
return wrapDER(publicKey, ED25519_OID).buffer;
}

@@ -30,3 +29,3 @@ static derDecode(key) {

}
return blobFromUint8Array(unwrapped);
return unwrapped;
}

@@ -54,7 +53,7 @@ toDer() {

const { publicKey, secretKey } = seed === undefined ? tweetnacl.sign.keyPair() : tweetnacl.sign.keyPair.fromSeed(seed);
return new this(Ed25519PublicKey.fromRaw(blobFromUint8Array(publicKey)), blobFromUint8Array(secretKey));
return new this(Ed25519PublicKey.fromRaw(publicKey), secretKey);
}
static fromParsedJson(obj) {
const [publicKeyDer, privateKeyRaw] = obj;
return new Ed25519KeyIdentity(Ed25519PublicKey.fromDer(blobFromHex(publicKeyDer)), blobFromHex(privateKeyRaw));
return new Ed25519KeyIdentity(Ed25519PublicKey.fromDer(fromHexString(publicKeyDer)), fromHexString(privateKeyRaw));
}

@@ -72,12 +71,3 @@ static fromJSON(json) {

else if (typeof parsed === 'object' && parsed !== null) {
const { publicKey, _publicKey, secretKey, _privateKey } = parsed;
const pk = publicKey
? Ed25519PublicKey.fromRaw(blobFromUint8Array(new Uint8Array(publicKey.data)))
: Ed25519PublicKey.fromDer(blobFromUint8Array(new Uint8Array(_publicKey.data)));
if (publicKey && secretKey && secretKey.data) {
return new Ed25519KeyIdentity(pk, blobFromUint8Array(new Uint8Array(secretKey.data)));
}
else if (_publicKey && _privateKey && _privateKey.data) {
return new Ed25519KeyIdentity(pk, blobFromUint8Array(new Uint8Array(_privateKey.data)));
}
throw new Error('Deprecated JSON format for Ed25519 keys.');
}

@@ -91,4 +81,3 @@ throw new Error(`Deserialization error: Invalid JSON type for string: ${JSON.stringify(json)}`);

const keyPair = tweetnacl.sign.keyPair.fromSecretKey(new Uint8Array(secretKey));
const identity = Ed25519KeyIdentity.fromKeyPair(blobFromUint8Array(keyPair.publicKey), blobFromUint8Array(keyPair.secretKey));
return identity;
return Ed25519KeyIdentity.fromKeyPair(keyPair.publicKey, keyPair.secretKey);
}

@@ -99,3 +88,3 @@ /**

toJSON() {
return [blobToHex(this._publicKey.toDer()), blobToHex(this._privateKey)];
return [toHexString(this._publicKey.toDer()), toHexString(this._privateKey)];
}

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

return {
secretKey: blobFromUint8Array(new Uint8Array(this._privateKey)),
secretKey: this._privateKey,
publicKey: this._publicKey,

@@ -123,9 +112,7 @@ };

async sign(challenge) {
const blob = challenge instanceof Buffer
? blobFromBuffer(challenge)
: blobFromUint8Array(new Uint8Array(challenge));
const signature = tweetnacl.sign.detached(blob, this._privateKey);
return blobFromUint8Array(signature);
const blob = new Uint8Array(challenge);
const signature = tweetnacl.sign.detached(blob, new Uint8Array(this._privateKey)).buffer;
return signature;
}
}
//# sourceMappingURL=ed25519.js.map

@@ -1,9 +0,8 @@

import { PublicKey, SignIdentity } from '@dfinity/agent';
import { BinaryBlob, DerEncodedBlob } from '@dfinity/candid';
import { DerEncodedPublicKey, PublicKey, Signature, SignIdentity } from '@dfinity/agent';
export declare class CosePublicKey implements PublicKey {
protected _cose: BinaryBlob;
protected _encodedKey: DerEncodedBlob;
constructor(_cose: BinaryBlob);
toDer(): DerEncodedBlob;
getCose(): BinaryBlob;
protected _cose: ArrayBuffer;
protected _encodedKey: DerEncodedPublicKey;
constructor(_cose: ArrayBuffer);
toDer(): DerEncodedPublicKey;
getCose(): ArrayBuffer;
}

@@ -15,3 +14,3 @@ /**

export declare class WebAuthnIdentity extends SignIdentity {
readonly rawId: BinaryBlob;
readonly rawId: ArrayBuffer;
/**

@@ -28,5 +27,5 @@ * Create an identity from a JSON serialization.

protected _publicKey: CosePublicKey;
protected constructor(rawId: BinaryBlob, cose: BinaryBlob);
protected constructor(rawId: ArrayBuffer, cose: ArrayBuffer);
getPublicKey(): PublicKey;
sign(blob: BinaryBlob): Promise<BinaryBlob>;
sign(blob: ArrayBuffer): Promise<Signature>;
/**

@@ -39,4 +38,2 @@ * Allow for JSON serialization of all information needed to reuse this identity.

* ReturnType<WebAuthnIdentity.toJSON>
* * publicKey is hex(der(publicKey))
* * rawId is the string representation of the local WebAuthn Credential.id (iirc it is base64url encoded)
*/

@@ -43,0 +40,0 @@ export interface JsonnableWebAuthnIdentitiy {

import { SignIdentity } from '@dfinity/agent';
import { blobFromHex, blobFromUint8Array, derBlobFromBlob, } from '@dfinity/candid';
import borc from 'borc';
import * as tweetnacl from 'tweetnacl';
import { fromHexString, toHexString } from '../buffer';
import { DER_COSE_OID, wrapDER } from './der';
function _coseToDerEncodedBlob(cose) {
return derBlobFromBlob(blobFromUint8Array(wrapDER(cose, DER_COSE_OID)));
return wrapDER(cose, DER_COSE_OID).buffer;
}

@@ -116,3 +116,3 @@ /**

}
return new this(blobFromHex(rawId), blobFromHex(publicKey));
return new this(fromHexString(rawId), fromHexString(publicKey));
}

@@ -134,3 +134,3 @@ /**

const attObject = borc.decodeFirst(new Uint8Array(response.attestationObject));
return new this(blobFromUint8Array(new Uint8Array(creds.rawId)), blobFromUint8Array(new Uint8Array(_authDataToCose(attObject.authData))));
return new this(creds.rawId, _authDataToCose(attObject.authData));
}

@@ -164,3 +164,3 @@ getPublicKey() {

}
return blobFromUint8Array(new Uint8Array(cbor));
return cbor.buffer;
}

@@ -176,4 +176,4 @@ else {

return {
publicKey: this._publicKey.getCose().toString('hex'),
rawId: this.rawId.toString('hex'),
publicKey: toHexString(this._publicKey.getCose()),
rawId: toHexString(this.rawId),
};

@@ -180,0 +180,0 @@ }

{
"name": "@dfinity/identity",
"version": "0.9.3",
"version": "0.10.0-beta.1",
"author": "DFINITY Stiftung <sdk@dfinity.org>",

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

"dfx",
"candid",
"motoko",

@@ -41,9 +40,7 @@ "javascript",

"peerDependencies": {
"@dfinity/agent": "^0.9.3",
"@dfinity/principal": "^0.9.3"
"@dfinity/agent": "^0.10.0-beta.1",
"@dfinity/principal": "^0.10.0-beta.1"
},
"dependencies": {
"borc": "^2.1.1",
"buffer": "^6.0.3",
"buffer-pipe": "0.0.4",
"tweetnacl": "^1.0.1"

@@ -50,0 +47,0 @@ },

declare module 'borc' {
import { Buffer } from 'buffer/';
class Decoder {

@@ -12,3 +10,3 @@ constructor(opts: { size: number; tags: Record<number, (val: any) => any> });

export function encode(o: any): Buffer;
export function encode(o: any): Uint8Array;

@@ -15,0 +13,0 @@ class Tagged {

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