Socket
Socket
Sign inDemoInstall

@extrimian/kms-suite-es256k

Package Overview
Dependencies
5
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.2.0 to 1.2.2

4

dist/services/es256k-suite.d.ts

@@ -5,4 +5,4 @@ import { IES256kKeyPair, IES256kSuite, LANG, IJWK } from "@extrimian/kms-core";

constructor();
signJWS(content: any): Promise<string>;
verifyJWS(content: any, publicKey: IJWK): Promise<any>;
verifySignature(originalContent: string, flatSignature: any, publicKey: IJWK): Promise<boolean>;
private publicKeyToAddress;
load(secret: IES256kKeyPair): Promise<void>;

@@ -9,0 +9,0 @@ create(params?: {

@@ -51,18 +51,25 @@ "use strict";

var ethers_1 = require("ethers");
// import { generate,resolve } from "@transmute/did-key-secp256k1";
var es256k_jws_ts_1 = require("@transmute/es256k-jws-ts");
var ES256kSuite = /** @class */ (function () {
function ES256kSuite() {
}
ES256kSuite.prototype.signJWS = function (content) {
var privateKeyJwk = kms_core_1.BaseConverter.getPrivateJWKfromHex(this.wallet.privateKey, this.wallet.publicKey);
return es256k_jws_ts_1.JWS.sign(content, privateKeyJwk, { alg: 'ES256K' });
};
ES256kSuite.prototype.verifyJWS = function (content, publicKey) {
ES256kSuite.prototype.verifySignature = function (originalContent, flatSignature, publicKey) {
return __awaiter(this, void 0, void 0, function () {
var address, publicKeyHex, pbkAddress;
return __generator(this, function (_a) {
return [2 /*return*/, es256k_jws_ts_1.JWS.verify(content, publicKey)];
address = ethers_1.ethers.utils.verifyMessage(originalContent, flatSignature);
publicKeyHex = kms_core_1.BaseConverter.convert(publicKey, kms_core_1.Base.JWK, kms_core_1.Base.Hex);
pbkAddress = this.publicKeyToAddress(publicKeyHex);
return [2 /*return*/, pbkAddress == address];
});
});
};
ES256kSuite.prototype.publicKeyToAddress = function (publicKeyHex) {
// Calcular el hash Keccak-256 de la clave pública (omitir el byte inicial '04' si está presente)
var publicKeyHash = ethers_1.ethers.utils.keccak256(publicKeyHex);
// Tomar los últimos 20 bytes (40 caracteres) del hash
var addressBytes = publicKeyHash.slice(-40);
// Convertir a una dirección Ethereum con checksum
var address = ethers_1.ethers.utils.getAddress(addressBytes);
return address;
};
ES256kSuite.prototype.load = function (secret) {

@@ -69,0 +76,0 @@ return __awaiter(this, void 0, void 0, function () {

{
"name": "@extrimian/kms-suite-es256k",
"version": "1.2.0",
"version": "1.2.2",
"description": "",

@@ -23,3 +23,3 @@ "main": "dist/index.js",

"dependencies": {
"@extrimian/kms-core": "^1.2.0",
"@extrimian/kms-core": "^1.4.0-2",
"@transmute/did-key-secp256k1": "^0.2.1-unstable.35",

@@ -30,2 +30,2 @@ "@transmute/es256k-jws-ts": "^0.1.3",

}
}
}

@@ -10,6 +10,5 @@ import {

IJWK,
Base,
} from "@extrimian/kms-core";
import { ethers, wordlists, Wallet, utils } from "ethers";
// import { generate,resolve } from "@transmute/did-key-secp256k1";
import { JWS, } from "@transmute/es256k-jws-ts";

@@ -22,9 +21,24 @@ @suiteDecorator(Suite.ES256k)

signJWS(content: any): Promise<string> {
const privateKeyJwk = BaseConverter.getPrivateJWKfromHex(this.wallet.privateKey, this.wallet.publicKey);
return JWS.sign(content, privateKeyJwk as any, { alg: 'ES256K' });
async verifySignature(originalContent: string, flatSignature: any, publicKey: IJWK): Promise<boolean> {
// Verificar el token
const address = ethers.utils.verifyMessage(originalContent, flatSignature);
const publicKeyHex = BaseConverter.convert(publicKey, Base.JWK, Base.Hex) as IJWK;
const pbkAddress = this.publicKeyToAddress(publicKeyHex);
return pbkAddress == address;
}
async verifyJWS(content: any, publicKey: IJWK): Promise<any> {
return JWS.verify(content, publicKey as any);
private publicKeyToAddress(publicKeyHex) {
// Calcular el hash Keccak-256 de la clave pública (omitir el byte inicial '04' si está presente)
const publicKeyHash = ethers.utils.keccak256(publicKeyHex);
// Tomar los últimos 20 bytes (40 caracteres) del hash
const addressBytes = publicKeyHash.slice(-40);
// Convertir a una dirección Ethereum con checksum
const address = ethers.utils.getAddress(addressBytes);
return address;
}

@@ -31,0 +45,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc