@cloud-cryptographic-wallet/asn1-parser
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -1,2 +0,8 @@ | ||
export * from "./parse-public-key.js"; | ||
export * from "./parse-signature.js"; | ||
declare function parsePublicKey(inputBuffer: ArrayBuffer): ArrayBuffer; | ||
declare function parseSignature(inputBuffer: ArrayBuffer): { | ||
r: ArrayBuffer; | ||
s: ArrayBuffer; | ||
}; | ||
export { parsePublicKey, parseSignature }; |
@@ -1,3 +0,50 @@ | ||
export * from "./parse-public-key.js"; | ||
export * from "./parse-signature.js"; | ||
// src/parse-public-key.ts | ||
import * as asn1js from "asn1js"; | ||
function parsePublicKey(inputBuffer) { | ||
const schema = new asn1js.Sequence({ | ||
value: [ | ||
new asn1js.Sequence({ | ||
value: [new asn1js.ObjectIdentifier(), new asn1js.ObjectIdentifier()] | ||
}), | ||
new asn1js.BitString({ name: "publicKey" }) | ||
] | ||
}); | ||
const parsed = asn1js.verifySchema(inputBuffer, schema); | ||
const publicKey = parsed.result.publicKey.valueBlock.valueHex; | ||
return publicKey.slice(1); | ||
} | ||
// src/parse-signature.ts | ||
import * as asn1js2 from "asn1js"; | ||
function normalize(inputBuffer) { | ||
if (inputBuffer.byteLength === 32) { | ||
return inputBuffer; | ||
} | ||
if (inputBuffer.byteLength === 33) { | ||
return inputBuffer.slice(1); | ||
} | ||
if (inputBuffer.byteLength === 31) { | ||
return new Uint8Array([0, ...new Uint8Array(inputBuffer)]).buffer; | ||
} | ||
throw new Error(`parseSignature: Unexpected byte length of inputBuffer. actual: ${inputBuffer.byteLength}`); | ||
} | ||
function parseSignature(inputBuffer) { | ||
const schema = new asn1js2.Sequence({ | ||
value: [ | ||
new asn1js2.Integer({ name: "r" }), | ||
new asn1js2.Integer({ name: "s" }) | ||
] | ||
}); | ||
const parsed = asn1js2.verifySchema(inputBuffer, schema); | ||
if (!parsed.verified) { | ||
throw new Error("parseSignature: failed to parse"); | ||
} | ||
const r = parsed.result.r.valueBlock.valueHex; | ||
const s = parsed.result.s.valueBlock.valueHex; | ||
return { r: normalize(r), s: normalize(s) }; | ||
} | ||
export { | ||
parsePublicKey, | ||
parseSignature | ||
}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@cloud-cryptographic-wallet/asn1-parser", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"repository": { | ||
@@ -11,3 +11,8 @@ "type": "git", | ||
"main": "./dist/index.js", | ||
"exports": "./dist/index.js", | ||
"exports": { | ||
"import": "./dist/index.js", | ||
"require": "./dist/index.cjs", | ||
"node": "./dist/index.cjs", | ||
"default": "./dist/index.js" | ||
}, | ||
"types": "./dist/index.d.ts", | ||
@@ -27,4 +32,3 @@ "engines": { | ||
"scripts": { | ||
"prebuild": "rm -rf dist", | ||
"build": "tsc" | ||
"build": "tsup" | ||
}, | ||
@@ -35,6 +39,7 @@ "dependencies": { | ||
"devDependencies": { | ||
"@cloud-cryptographic-wallet/signer": "^0.0.3", | ||
"@types/asn1js": "^2.0.2" | ||
"@cloud-cryptographic-wallet/signer": "^0.0.4", | ||
"@types/asn1js": "^2.0.2", | ||
"tsup": "^5.12.1" | ||
}, | ||
"gitHead": "302d5d14fd3294b3218fc2d2137418573b8c022c" | ||
"gitHead": "a4c4787f203e0fec56267b0ca4a1f90df172d168" | ||
} |
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
19343
297
3
12