You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

@turnkey/crypto

Package Overview
Dependencies
Maintainers
8
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turnkey/crypto - npm Package Compare versions

Comparing version
2.1.0
to
2.2.0
+1
-0
./dist/index.js

@@ -18,2 +18,3 @@ 'use strict';

exports.hpkeEncrypt = crypto.hpkeEncrypt;
exports.toDerSignature = crypto.toDerSignature;
exports.uncompressRawPublicKey = crypto.uncompressRawPublicKey;

@@ -20,0 +21,0 @@ exports.decryptCredentialBundle = turnkey.decryptCredentialBundle;

# @turnkey/crypto
## 2.2.0
### Minor Changes
- Added `toDerSignature` function used to convert a raw ECDSA signature into DER-encoded format for compatibility with our backend, which requires DER signatures
## 2.1.0

@@ -4,0 +10,0 @@

@@ -103,3 +103,23 @@ /// <reference lib="dom" />

export declare const fromDerSignature: (derSignature: string) => Uint8Array;
/**
* Converts a raw ECDSA signature to DER-encoded format.
*
* This function takes a raw ECDSA signature, which is a concatenation of two 32-byte integers (r and s),
* and converts it into the DER-encoded format. DER (Distinguished Encoding Rules) is a binary encoding
* for data structures described by ASN.1.
*
* @param {string} rawSignature - The raw signature in hexadecimal string format.
* @returns {string} - The DER-encoded signature in hexadecimal string format.
*
* @throws {Error} - Throws an error if the input signature is invalid or if the encoding process fails.
*
* @example
* // Example usage:
* const rawSignature = "0x487cdb8a88f2f4044b701cbb116075c4cabe5fe4657a6358b395c0aab70694db3453a8057e442bd1aff0ecabe8a82c831f0edd7f2158b7c1feb3de9b1f20309b1c";
* const derSignature = toDerSignature(rawSignature);
* console.log(derSignature); // Outputs the DER-encoded signature as a hex string
* // "30440220487cdb8a88f2f4044b701cbb116075c4cabe5fe4657a6358b395c0aab70694db02203453a8057e442bd1aff0ecabe8a82c831f0edd7f2158b7c1feb3de9b1f20309b"
*/
export declare const toDerSignature: (rawSignature: string) => string;
export {};
//# sourceMappingURL=crypto.d.ts.map

@@ -394,2 +394,54 @@ 'use strict';

};
/**
* Converts a raw ECDSA signature to DER-encoded format.
*
* This function takes a raw ECDSA signature, which is a concatenation of two 32-byte integers (r and s),
* and converts it into the DER-encoded format. DER (Distinguished Encoding Rules) is a binary encoding
* for data structures described by ASN.1.
*
* @param {string} rawSignature - The raw signature in hexadecimal string format.
* @returns {string} - The DER-encoded signature in hexadecimal string format.
*
* @throws {Error} - Throws an error if the input signature is invalid or if the encoding process fails.
*
* @example
* // Example usage:
* const rawSignature = "0x487cdb8a88f2f4044b701cbb116075c4cabe5fe4657a6358b395c0aab70694db3453a8057e442bd1aff0ecabe8a82c831f0edd7f2158b7c1feb3de9b1f20309b1c";
* const derSignature = toDerSignature(rawSignature);
* console.log(derSignature); // Outputs the DER-encoded signature as a hex string
* // "30440220487cdb8a88f2f4044b701cbb116075c4cabe5fe4657a6358b395c0aab70694db02203453a8057e442bd1aff0ecabe8a82c831f0edd7f2158b7c1feb3de9b1f20309b"
*/
const toDerSignature = (rawSignature) => {
const rawSignatureBuf = encoding.uint8ArrayFromHexString(rawSignature);
// Split raw signature into r and s, each 32 bytes
const r = rawSignatureBuf.slice(0, 32);
const s = rawSignatureBuf.slice(32, 64);
// Helper function to encode an integer with DER structure
const encodeDerInteger = (integer) => {
// Check if integer is defined and has at least one byte
if (integer === undefined ||
integer.length === 0 ||
integer[0] === undefined) {
throw new Error("Invalid integer: input is undefined or empty.");
}
// Add a leading zero if the integer's most significant byte is >= 0x80
const needsPadding = integer[0] & 0x80;
const paddedInteger = needsPadding
? new Uint8Array([0x00, ...integer])
: integer;
// Prepend the integer tag (0x02) and length
return new Uint8Array([0x02, paddedInteger.length, ...paddedInteger]);
};
// DER encode r and s
const rEncoded = encodeDerInteger(r);
const sEncoded = encodeDerInteger(s);
// Combine as a DER sequence: 0x30, total length, rEncoded, sEncoded
const derSignature = new Uint8Array([
0x30,
rEncoded.length + sEncoded.length,
...rEncoded,
...sEncoded,
]);
return encoding.uint8ArrayToHexString(derSignature);
};

@@ -406,3 +458,4 @@ exports.buildAdditionalAssociatedData = buildAdditionalAssociatedData;

exports.hpkeEncrypt = hpkeEncrypt;
exports.toDerSignature = toDerSignature;
exports.uncompressRawPublicKey = uncompressRawPublicKey;
//# sourceMappingURL=crypto.js.map

@@ -373,4 +373,56 @@ import { p256 } from '@noble/curves/p256';

};
/**
* Converts a raw ECDSA signature to DER-encoded format.
*
* This function takes a raw ECDSA signature, which is a concatenation of two 32-byte integers (r and s),
* and converts it into the DER-encoded format. DER (Distinguished Encoding Rules) is a binary encoding
* for data structures described by ASN.1.
*
* @param {string} rawSignature - The raw signature in hexadecimal string format.
* @returns {string} - The DER-encoded signature in hexadecimal string format.
*
* @throws {Error} - Throws an error if the input signature is invalid or if the encoding process fails.
*
* @example
* // Example usage:
* const rawSignature = "0x487cdb8a88f2f4044b701cbb116075c4cabe5fe4657a6358b395c0aab70694db3453a8057e442bd1aff0ecabe8a82c831f0edd7f2158b7c1feb3de9b1f20309b1c";
* const derSignature = toDerSignature(rawSignature);
* console.log(derSignature); // Outputs the DER-encoded signature as a hex string
* // "30440220487cdb8a88f2f4044b701cbb116075c4cabe5fe4657a6358b395c0aab70694db02203453a8057e442bd1aff0ecabe8a82c831f0edd7f2158b7c1feb3de9b1f20309b"
*/
const toDerSignature = (rawSignature) => {
const rawSignatureBuf = uint8ArrayFromHexString(rawSignature);
// Split raw signature into r and s, each 32 bytes
const r = rawSignatureBuf.slice(0, 32);
const s = rawSignatureBuf.slice(32, 64);
// Helper function to encode an integer with DER structure
const encodeDerInteger = (integer) => {
// Check if integer is defined and has at least one byte
if (integer === undefined ||
integer.length === 0 ||
integer[0] === undefined) {
throw new Error("Invalid integer: input is undefined or empty.");
}
// Add a leading zero if the integer's most significant byte is >= 0x80
const needsPadding = integer[0] & 0x80;
const paddedInteger = needsPadding
? new Uint8Array([0x00, ...integer])
: integer;
// Prepend the integer tag (0x02) and length
return new Uint8Array([0x02, paddedInteger.length, ...paddedInteger]);
};
// DER encode r and s
const rEncoded = encodeDerInteger(r);
const sEncoded = encodeDerInteger(s);
// Combine as a DER sequence: 0x30, total length, rEncoded, sEncoded
const derSignature = new Uint8Array([
0x30,
rEncoded.length + sEncoded.length,
...rEncoded,
...sEncoded,
]);
return uint8ArrayToHexString(derSignature);
};
export { buildAdditionalAssociatedData, compressRawPublicKey, extractPrivateKeyFromPKCS8Bytes, formatHpkeBuf, fromDerSignature, generateP256KeyPair, getPublicKey, hpkeAuthEncrypt, hpkeDecrypt, hpkeEncrypt, uncompressRawPublicKey };
export { buildAdditionalAssociatedData, compressRawPublicKey, extractPrivateKeyFromPKCS8Bytes, formatHpkeBuf, fromDerSignature, generateP256KeyPair, getPublicKey, hpkeAuthEncrypt, hpkeDecrypt, hpkeEncrypt, toDerSignature, uncompressRawPublicKey };
//# sourceMappingURL=crypto.mjs.map

@@ -18,2 +18,3 @@ 'use strict';

exports.hpkeEncrypt = crypto.hpkeEncrypt;
exports.toDerSignature = crypto.toDerSignature;
exports.uncompressRawPublicKey = crypto.uncompressRawPublicKey;

@@ -20,0 +21,0 @@ exports.decryptCredentialBundle = turnkey.decryptCredentialBundle;

+1
-1

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

export { buildAdditionalAssociatedData, compressRawPublicKey, extractPrivateKeyFromPKCS8Bytes, formatHpkeBuf, fromDerSignature, generateP256KeyPair, getPublicKey, hpkeAuthEncrypt, hpkeDecrypt, hpkeEncrypt, uncompressRawPublicKey } from './crypto.mjs';
export { buildAdditionalAssociatedData, compressRawPublicKey, extractPrivateKeyFromPKCS8Bytes, formatHpkeBuf, fromDerSignature, generateP256KeyPair, getPublicKey, hpkeAuthEncrypt, hpkeDecrypt, hpkeEncrypt, toDerSignature, uncompressRawPublicKey } from './crypto.mjs';
export { decryptCredentialBundle, decryptExportBundle, encryptPrivateKeyToBundle, encryptWalletToBundle, verifyStampSignature } from './turnkey.mjs';
//# sourceMappingURL=index.mjs.map
{
"name": "@turnkey/crypto",
"version": "2.1.0",
"version": "2.2.0",
"main": "./dist/index.js",

@@ -5,0 +5,0 @@ "module": "./dist/index.mjs",

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