@dfinity/identity
Advanced tools
Comparing version 0.10.0-beta.1 to 0.10.0
@@ -0,1 +1,6 @@ | ||
export declare const bufEquals: (b1: ArrayBuffer, b2: ArrayBuffer) => boolean; | ||
export declare const encodeLenBytes: (len: number) => number; | ||
export declare const encodeLen: (buf: Uint8Array, offset: number, len: number) => number; | ||
export declare const decodeLenBytes: (buf: Uint8Array, offset: number) => number; | ||
export declare const decodeLen: (buf: Uint8Array, offset: number) => number; | ||
/** | ||
@@ -10,2 +15,6 @@ * A DER encoded `SEQUENCE(OID)` for DER-encoded-COSE | ||
/** | ||
* A DER encoded `SEQUENCE(OID)` for secp256k1 with the ECDSA algorithm | ||
*/ | ||
export declare const SECP256K1_OID: Uint8Array; | ||
/** | ||
* Wraps the given `payload` in a DER encoding tagged with the given encoded `oid` like so: | ||
@@ -12,0 +21,0 @@ * `SEQUENCE(oid, BITSTRING(payload))` |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.unwrapDER = exports.wrapDER = exports.ED25519_OID = exports.DER_COSE_OID = void 0; | ||
exports.unwrapDER = exports.wrapDER = exports.SECP256K1_OID = exports.ED25519_OID = exports.DER_COSE_OID = exports.decodeLen = exports.decodeLenBytes = exports.encodeLen = exports.encodeLenBytes = exports.bufEquals = void 0; | ||
const bufEquals = (b1, b2) => { | ||
@@ -15,2 +15,3 @@ if (b1.byteLength !== b2.byteLength) | ||
}; | ||
exports.bufEquals = bufEquals; | ||
const encodeLenBytes = (len) => { | ||
@@ -33,2 +34,3 @@ if (len <= 0x7f) { | ||
}; | ||
exports.encodeLenBytes = encodeLenBytes; | ||
const encodeLen = (buf, offset, len) => { | ||
@@ -61,2 +63,3 @@ if (len <= 0x7f) { | ||
}; | ||
exports.encodeLen = encodeLen; | ||
const decodeLenBytes = (buf, offset) => { | ||
@@ -75,2 +78,16 @@ if (buf[offset] < 0x80) | ||
}; | ||
exports.decodeLenBytes = decodeLenBytes; | ||
const decodeLen = (buf, offset) => { | ||
const lenBytes = exports.decodeLenBytes(buf, offset); | ||
if (lenBytes === 1) | ||
return buf[offset]; | ||
else if (lenBytes === 2) | ||
return buf[offset + 1]; | ||
else if (lenBytes === 3) | ||
return (buf[offset + 1] << 8) + buf[offset + 2]; | ||
else if (lenBytes === 4) | ||
return (buf[offset + 1] << 16) + (buf[offset + 2] << 8) + buf[offset + 3]; | ||
throw new Error('Length too long (> 4 bytes)'); | ||
}; | ||
exports.decodeLen = decodeLen; | ||
/** | ||
@@ -93,2 +110,12 @@ * A DER encoded `SEQUENCE(OID)` for DER-encoded-COSE | ||
/** | ||
* A DER encoded `SEQUENCE(OID)` for secp256k1 with the ECDSA algorithm | ||
*/ | ||
exports.SECP256K1_OID = Uint8Array.from([ | ||
...[0x30, 0x10], | ||
...[0x06, 0x07], | ||
...[0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01], | ||
...[0x06, 0x05], | ||
...[0x2b, 0x81, 0x04, 0x00, 0x0a], // OID secp256k1 | ||
]); | ||
/** | ||
* Wraps the given `payload` in a DER encoding tagged with the given encoded `oid` like so: | ||
@@ -102,10 +129,10 @@ * `SEQUENCE(oid, BITSTRING(payload))` | ||
// The Bit String header needs to include the unused bit count byte in its length | ||
const bitStringHeaderLength = 2 + encodeLenBytes(payload.byteLength + 1); | ||
const bitStringHeaderLength = 2 + exports.encodeLenBytes(payload.byteLength + 1); | ||
const len = oid.byteLength + bitStringHeaderLength + payload.byteLength; | ||
let offset = 0; | ||
const buf = new Uint8Array(1 + encodeLenBytes(len) + len); | ||
const buf = new Uint8Array(1 + exports.encodeLenBytes(len) + len); | ||
// Sequence | ||
buf[offset++] = 0x30; | ||
// Sequence Length | ||
offset += encodeLen(buf, offset, len); | ||
offset += exports.encodeLen(buf, offset, len); | ||
// OID | ||
@@ -116,3 +143,3 @@ buf.set(oid, offset); | ||
buf[offset++] = 0x03; | ||
offset += encodeLen(buf, offset, payload.byteLength + 1); | ||
offset += exports.encodeLen(buf, offset, payload.byteLength + 1); | ||
// 0 padding | ||
@@ -142,4 +169,4 @@ buf[offset++] = 0x00; | ||
expect(0x30, 'sequence'); | ||
offset += decodeLenBytes(buf, offset); | ||
if (!bufEquals(buf.slice(offset, offset + oid.byteLength), oid)) { | ||
offset += exports.decodeLenBytes(buf, offset); | ||
if (!exports.bufEquals(buf.slice(offset, offset + oid.byteLength), oid)) { | ||
throw new Error('Not the expected OID.'); | ||
@@ -149,7 +176,12 @@ } | ||
expect(0x03, 'bit string'); | ||
offset += decodeLenBytes(buf, offset); | ||
const payloadLen = exports.decodeLen(buf, offset) - 1; // Subtracting 1 to account for the 0 padding | ||
offset += exports.decodeLenBytes(buf, offset); | ||
expect(0x00, '0 padding'); | ||
return buf.slice(offset); | ||
const result = buf.slice(offset); | ||
if (payloadLen !== result.length) { | ||
throw new Error(`DER payload mismatch: Expected length ${payloadLen} actual length ${result.length}`); | ||
} | ||
return result; | ||
}; | ||
exports.unwrapDER = unwrapDER; | ||
//# sourceMappingURL=der.js.map |
@@ -90,5 +90,2 @@ "use strict"; | ||
} | ||
else if (typeof parsed === 'object' && parsed !== null) { | ||
throw new Error('Deprecated JSON format for Ed25519 keys.'); | ||
} | ||
throw new Error(`Deserialization error: Invalid JSON type for string: ${JSON.stringify(json)}`); | ||
@@ -95,0 +92,0 @@ } |
export { Ed25519KeyIdentity, Ed25519PublicKey } from './identity/ed25519'; | ||
export { Secp256k1KeyIdentity, Secp256k1PublicKey } from './identity/secp256k1'; | ||
export { Delegation, DelegationIdentity, DelegationChain, SignedDelegation, } from './identity/delegation'; | ||
export { WebAuthnIdentity } from './identity/webauthn'; | ||
export { wrapDER, unwrapDER, DER_COSE_OID, ED25519_OID } from './identity/der'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ED25519_OID = exports.DER_COSE_OID = exports.unwrapDER = exports.wrapDER = exports.WebAuthnIdentity = exports.DelegationChain = exports.DelegationIdentity = exports.Delegation = exports.Ed25519PublicKey = exports.Ed25519KeyIdentity = void 0; | ||
exports.ED25519_OID = exports.DER_COSE_OID = exports.unwrapDER = exports.wrapDER = exports.WebAuthnIdentity = exports.DelegationChain = exports.DelegationIdentity = exports.Delegation = exports.Secp256k1PublicKey = exports.Secp256k1KeyIdentity = exports.Ed25519PublicKey = exports.Ed25519KeyIdentity = void 0; | ||
var ed25519_1 = require("./identity/ed25519"); | ||
Object.defineProperty(exports, "Ed25519KeyIdentity", { enumerable: true, get: function () { return ed25519_1.Ed25519KeyIdentity; } }); | ||
Object.defineProperty(exports, "Ed25519PublicKey", { enumerable: true, get: function () { return ed25519_1.Ed25519PublicKey; } }); | ||
var secp256k1_1 = require("./identity/secp256k1"); | ||
Object.defineProperty(exports, "Secp256k1KeyIdentity", { enumerable: true, get: function () { return secp256k1_1.Secp256k1KeyIdentity; } }); | ||
Object.defineProperty(exports, "Secp256k1PublicKey", { enumerable: true, get: function () { return secp256k1_1.Secp256k1PublicKey; } }); | ||
var delegation_1 = require("./identity/delegation"); | ||
@@ -8,0 +11,0 @@ Object.defineProperty(exports, "Delegation", { enumerable: true, get: function () { return delegation_1.Delegation; } }); |
@@ -0,1 +1,6 @@ | ||
export declare const bufEquals: (b1: ArrayBuffer, b2: ArrayBuffer) => boolean; | ||
export declare const encodeLenBytes: (len: number) => number; | ||
export declare const encodeLen: (buf: Uint8Array, offset: number, len: number) => number; | ||
export declare const decodeLenBytes: (buf: Uint8Array, offset: number) => number; | ||
export declare const decodeLen: (buf: Uint8Array, offset: number) => number; | ||
/** | ||
@@ -10,2 +15,6 @@ * A DER encoded `SEQUENCE(OID)` for DER-encoded-COSE | ||
/** | ||
* A DER encoded `SEQUENCE(OID)` for secp256k1 with the ECDSA algorithm | ||
*/ | ||
export declare const SECP256K1_OID: Uint8Array; | ||
/** | ||
* Wraps the given `payload` in a DER encoding tagged with the given encoded `oid` like so: | ||
@@ -12,0 +21,0 @@ * `SEQUENCE(oid, BITSTRING(payload))` |
@@ -1,2 +0,2 @@ | ||
const bufEquals = (b1, b2) => { | ||
export const bufEquals = (b1, b2) => { | ||
if (b1.byteLength !== b2.byteLength) | ||
@@ -12,3 +12,3 @@ return false; | ||
}; | ||
const encodeLenBytes = (len) => { | ||
export const encodeLenBytes = (len) => { | ||
if (len <= 0x7f) { | ||
@@ -30,3 +30,3 @@ return 1; | ||
}; | ||
const encodeLen = (buf, offset, len) => { | ||
export const encodeLen = (buf, offset, len) => { | ||
if (len <= 0x7f) { | ||
@@ -58,3 +58,3 @@ buf[offset] = len; | ||
}; | ||
const decodeLenBytes = (buf, offset) => { | ||
export const decodeLenBytes = (buf, offset) => { | ||
if (buf[offset] < 0x80) | ||
@@ -72,2 +72,14 @@ return 1; | ||
}; | ||
export const decodeLen = (buf, offset) => { | ||
const lenBytes = decodeLenBytes(buf, offset); | ||
if (lenBytes === 1) | ||
return buf[offset]; | ||
else if (lenBytes === 2) | ||
return buf[offset + 1]; | ||
else if (lenBytes === 3) | ||
return (buf[offset + 1] << 8) + buf[offset + 2]; | ||
else if (lenBytes === 4) | ||
return (buf[offset + 1] << 16) + (buf[offset + 2] << 8) + buf[offset + 3]; | ||
throw new Error('Length too long (> 4 bytes)'); | ||
}; | ||
/** | ||
@@ -90,2 +102,12 @@ * A DER encoded `SEQUENCE(OID)` for DER-encoded-COSE | ||
/** | ||
* A DER encoded `SEQUENCE(OID)` for secp256k1 with the ECDSA algorithm | ||
*/ | ||
export const SECP256K1_OID = Uint8Array.from([ | ||
...[0x30, 0x10], | ||
...[0x06, 0x07], | ||
...[0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01], | ||
...[0x06, 0x05], | ||
...[0x2b, 0x81, 0x04, 0x00, 0x0a], // OID secp256k1 | ||
]); | ||
/** | ||
* Wraps the given `payload` in a DER encoding tagged with the given encoded `oid` like so: | ||
@@ -142,6 +164,11 @@ * `SEQUENCE(oid, BITSTRING(payload))` | ||
expect(0x03, 'bit string'); | ||
const payloadLen = decodeLen(buf, offset) - 1; // Subtracting 1 to account for the 0 padding | ||
offset += decodeLenBytes(buf, offset); | ||
expect(0x00, '0 padding'); | ||
return buf.slice(offset); | ||
const result = buf.slice(offset); | ||
if (payloadLen !== result.length) { | ||
throw new Error(`DER payload mismatch: Expected length ${payloadLen} actual length ${result.length}`); | ||
} | ||
return result; | ||
}; | ||
//# sourceMappingURL=der.js.map |
@@ -67,5 +67,2 @@ import { SignIdentity } from '@dfinity/agent'; | ||
} | ||
else if (typeof parsed === 'object' && parsed !== null) { | ||
throw new Error('Deprecated JSON format for Ed25519 keys.'); | ||
} | ||
throw new Error(`Deserialization error: Invalid JSON type for string: ${JSON.stringify(json)}`); | ||
@@ -72,0 +69,0 @@ } |
export { Ed25519KeyIdentity, Ed25519PublicKey } from './identity/ed25519'; | ||
export { Secp256k1KeyIdentity, Secp256k1PublicKey } from './identity/secp256k1'; | ||
export { Delegation, DelegationIdentity, DelegationChain, SignedDelegation, } from './identity/delegation'; | ||
export { WebAuthnIdentity } from './identity/webauthn'; | ||
export { wrapDER, unwrapDER, DER_COSE_OID, ED25519_OID } from './identity/der'; |
export { Ed25519KeyIdentity, Ed25519PublicKey } from './identity/ed25519'; | ||
export { Secp256k1KeyIdentity, Secp256k1PublicKey } from './identity/secp256k1'; | ||
export { Delegation, DelegationIdentity, DelegationChain, } from './identity/delegation'; | ||
@@ -3,0 +4,0 @@ export { WebAuthnIdentity } from './identity/webauthn'; |
{ | ||
"name": "@dfinity/identity", | ||
"version": "0.10.0-beta.1", | ||
"version": "0.10.0", | ||
"author": "DFINITY Stiftung <sdk@dfinity.org>", | ||
@@ -39,7 +39,9 @@ "license": "Apache-2.0", | ||
"peerDependencies": { | ||
"@dfinity/agent": "^0.10.0-beta.1", | ||
"@dfinity/principal": "^0.10.0-beta.1" | ||
"@dfinity/agent": "^0.10.0", | ||
"@dfinity/principal": "^0.10.0" | ||
}, | ||
"dependencies": { | ||
"borc": "^2.1.1", | ||
"js-sha256": "^0.9.0", | ||
"secp256k1": "^4.0.2", | ||
"tweetnacl": "^1.0.1" | ||
@@ -50,2 +52,3 @@ }, | ||
"@types/jest": "^24.9.1", | ||
"@types/secp256k1": "^4.0.3", | ||
"@typescript-eslint/eslint-plugin": "^4.14.2", | ||
@@ -52,0 +55,0 @@ "@typescript-eslint/parser": "^4.14.2", |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
336664
48
2476
6
15
+ Addedjs-sha256@^0.9.0
+ Addedsecp256k1@^4.0.2
+ Addedbn.js@4.12.1(transitive)
+ Addedbrorand@1.1.0(transitive)
+ Addedelliptic@6.6.1(transitive)
+ Addedhash.js@1.1.7(transitive)
+ Addedhmac-drbg@1.0.1(transitive)
+ Addedminimalistic-assert@1.0.1(transitive)
+ Addedminimalistic-crypto-utils@1.0.1(transitive)
+ Addednode-addon-api@5.1.0(transitive)
+ Addednode-gyp-build@4.8.3(transitive)
+ Addedsecp256k1@4.0.4(transitive)