mirror of
https://github.com/selfxyz/self.git
synced 2026-04-05 03:00:53 -04:00
modify other files for new signature data types
This commit is contained in:
@@ -23,27 +23,27 @@ export const DEVELOPMENT_MODE = true
|
||||
export const DEFAULT_MAJORITY = "18"
|
||||
|
||||
export const MAX_PADDED_ECONTENT_LEN: Partial<Record<keyof typeof SignatureAlgorithmIndex, number>> = {
|
||||
rsa_65537_sha256_2048: 384,
|
||||
rsa_65537_sha1_2048: 320,
|
||||
rsapss_65537_sha256_2048: 384,
|
||||
ecdsa_secp256r1_sha1_256: 320,
|
||||
ecdsa_secp256r1_sha256_256: 384,
|
||||
ecdsa_secp384r1_sha384_384: 512,
|
||||
rsa_sha256_65537_2048: 384,
|
||||
rsa_sha1_65537_2048: 320,
|
||||
rsapss_sha256_65537_2048: 384,
|
||||
ecdsa_sha1_secp256r1_256: 320,
|
||||
ecdsa_sha256_secp256r1_256: 384,
|
||||
ecdsa_sha384_secp384r1_384: 512,
|
||||
}
|
||||
|
||||
export const MAX_PADDED_SIGNED_ATTR_LEN: Partial<Record<keyof typeof SignatureAlgorithmIndex, number>> = {
|
||||
rsa_65537_sha256_2048: 192,
|
||||
rsa_65537_sha1_2048: 192,
|
||||
rsapss_65537_sha256_2048: 192,
|
||||
ecdsa_secp256r1_sha1_256: 192,
|
||||
ecdsa_secp256r1_sha256_256: 192,
|
||||
ecdsa_secp384r1_sha384_384: 192,
|
||||
rsa_sha256_65537_2048: 192,
|
||||
rsa_sha1_65537_2048: 192,
|
||||
rsapss_sha256_65537_2048: 192,
|
||||
ecdsa_sha1_secp256r1_256: 192,
|
||||
ecdsa_sha256_secp256r1_256: 192,
|
||||
ecdsa_sha384_secp384r1_384: 192,
|
||||
}
|
||||
|
||||
export const MAX_CERT_BYTES: Partial<Record<keyof typeof SignatureAlgorithmIndex, number>> = {
|
||||
rsa_65537_sha256_4096: 512,
|
||||
rsa_65537_sha1_4096: 640,
|
||||
rsapss_65537_sha256_4096: 768,
|
||||
rsa_sha256_65537_4096: 512,
|
||||
rsa_sha1_65537_4096: 640,
|
||||
rsapss_sha256_65537_4096: 768,
|
||||
}
|
||||
|
||||
export const ECDSA_K_LENGTH_FACTOR = 2;
|
||||
@@ -59,15 +59,17 @@ export const circuitNameFromMode = {
|
||||
}
|
||||
|
||||
export enum SignatureAlgorithmIndex {
|
||||
rsa_65537_sha256_2048 = 1,
|
||||
rsa_65537_sha1_2048 = 3,
|
||||
rsapss_65537_sha256_2048 = 4,
|
||||
ecdsa_secp256r1_sha1_256 = 7,
|
||||
ecdsa_secp256r1_sha256_256 = 8,
|
||||
ecdsa_secp384r1_sha384_384 = 9,
|
||||
rsa_65537_sha256_4096 = 10,
|
||||
rsa_65537_sha1_4096 = 11,
|
||||
rsapss_65537_sha256_4096 = 12,
|
||||
rsa_sha256_65537_2048 = 1,
|
||||
rsa_sha1_65537_2048 = 3,
|
||||
rsapss_sha256_65537_2048 = 4,
|
||||
ecdsa_sha1_secp256r1_256 = 7,
|
||||
ecdsa_sha256_secp256r1_256 = 8,
|
||||
ecdsa_sha384_secp384r1_384 = 9,
|
||||
rsa_sha256_65537_4096 = 10,
|
||||
rsa_sha1_65537_4096 = 11,
|
||||
rsapss_sha256_65537_4096 = 12,
|
||||
rsa_sha256_3_2048 = 13,
|
||||
rsa_sha256_65537_3072 = 14,
|
||||
}
|
||||
|
||||
export const attributeToPosition = {
|
||||
|
||||
@@ -50,17 +50,15 @@ export function parseCertificate(pem: string) {
|
||||
|
||||
}
|
||||
|
||||
export const getCircuitName = (circuitMode: Mode, signatureAlgorithm: string, hashFunction: string) => {
|
||||
export const getCircuitName = (circuitMode: Mode, signatureAlgorithm: string, hashFunction: string, domainParameter: string, keyLength: string) => {
|
||||
const circuit = circuitNameFromMode[circuitMode];
|
||||
if (circuit == 'vc_and_disclose') {
|
||||
return 'vc_and_disclose';
|
||||
}
|
||||
else if (signatureAlgorithm === 'ecdsa') {
|
||||
return circuit + "_" + signatureAlgorithm + "_secp256r1_" + hashFunction;
|
||||
}
|
||||
else {
|
||||
return circuit + "_" + signatureAlgorithm + "_65537_" + hashFunction;
|
||||
if (circuit == 'dsc') {
|
||||
return circuit + "_" + signatureAlgorithm + "_" + hashFunction + "_" + domainParameter + "_" + keyLength;
|
||||
}
|
||||
return circuit + "_" + signatureAlgorithm + "_" + hashFunction + "_" + domainParameter + "_" + keyLength;
|
||||
}
|
||||
|
||||
export function getSignatureAlgorithmDetails(oid: string): { signatureAlgorithm: string, hashFunction: string } {
|
||||
|
||||
@@ -29,9 +29,9 @@ import {
|
||||
import { sampleDataHashes_small, sampleDataHashes_large } from '../constants/sampleDataHashes';
|
||||
import { countryCodes } from '../constants/constants';
|
||||
import { parseCertificate } from './certificates/handleCertificate';
|
||||
|
||||
import { SignatureAlgorithm } from './types';
|
||||
export function genMockPassportData(
|
||||
signatureType: 'rsa_sha1' | 'rsa_sha256' | 'rsapss_sha256' | 'ecdsa_sha256' | 'ecdsa_sha1' | 'ecdsa_sha384' | 'brainpoolP256r1_sha256',
|
||||
signatureType: SignatureAlgorithm,
|
||||
nationality: keyof typeof countryCodes,
|
||||
birthDate: string,
|
||||
expiryDate: string,
|
||||
@@ -77,37 +77,37 @@ export function genMockPassportData(
|
||||
let sampleDataHashes: [number, number[]][];
|
||||
|
||||
switch (signatureType) {
|
||||
case 'rsa_sha1':
|
||||
case 'rsa_sha1_65537_2048':
|
||||
sampleDataHashes = sampleDataHashes_small;
|
||||
privateKeyPem = mock_dsc_key_sha1_rsa_4096;
|
||||
dsc = mock_dsc_sha1_rsa_4096;
|
||||
break;
|
||||
case 'rsa_sha256':
|
||||
case 'rsa_sha256_65537_2048':
|
||||
sampleDataHashes = sampleDataHashes_large;
|
||||
privateKeyPem = mock_dsc_key_sha256_rsa_4096;
|
||||
dsc = mock_dsc_sha256_rsa_4096;
|
||||
break;
|
||||
case 'rsapss_sha256':
|
||||
case 'rsapss_sha256_65537_2048':
|
||||
sampleDataHashes = sampleDataHashes_large;
|
||||
privateKeyPem = mock_dsc_key_sha256_rsapss_4096;
|
||||
dsc = mock_dsc_sha256_rsapss_4096;
|
||||
break;
|
||||
case 'ecdsa_sha256':
|
||||
case 'ecdsa_sha256_secp256r1_256':
|
||||
sampleDataHashes = sampleDataHashes_large;
|
||||
privateKeyPem = mock_dsc_key_sha256_ecdsa;
|
||||
dsc = mock_dsc_sha256_ecdsa;
|
||||
break;
|
||||
case 'ecdsa_sha1':
|
||||
case 'ecdsa_sha1_secp256r1_256':
|
||||
sampleDataHashes = sampleDataHashes_small;
|
||||
privateKeyPem = mock_dsc_key_sha1_ecdsa;
|
||||
dsc = mock_dsc_sha1_ecdsa;
|
||||
break;
|
||||
case 'ecdsa_sha384':
|
||||
case 'ecdsa_sha384_secp384r1_384':
|
||||
sampleDataHashes = sampleDataHashes_small;
|
||||
privateKeyPem = mock_dsc_key_sha384_ecdsa;
|
||||
dsc = mock_dsc_sha384_ecdsa;
|
||||
break;
|
||||
case 'brainpoolP256r1_sha256':
|
||||
case 'ecdsa_sha256_brainpoolP256r1_256':
|
||||
sampleDataHashes = sampleDataHashes_small;
|
||||
privateKeyPem = mock_dsc_key_sha256_brainpoolP256r1;
|
||||
dsc = mock_dsc_sha256_brainpoolP256r1;
|
||||
|
||||
@@ -172,7 +172,7 @@ export function generateCircuitInputsProve(
|
||||
const { mrz, eContent, signedAttr, encryptedDigest, dsc, dg2Hash } = passportData;
|
||||
const { signatureAlgorithm, hashFunction, hashLen, x, y, modulus, curve, exponent, bits } = parseCertificate(passportData.dsc);
|
||||
|
||||
const signatureAlgorithmFullName = `${signatureAlgorithm}_${curve || exponent}_${hashFunction}_${bits}`;
|
||||
const signatureAlgorithmFullName = `${signatureAlgorithm}_${hashFunction}_${curve || exponent}_${bits}`;
|
||||
let pubKey: any;
|
||||
let signature: any;
|
||||
|
||||
@@ -217,6 +217,8 @@ export function generateCircuitInputsProve(
|
||||
throw new Error(`This length of datagroups (${eContent.length} bytes) is currently unsupported. Please contact us so we add support!`);
|
||||
}
|
||||
|
||||
console.log('signatureAlgorithmFullName', signatureAlgorithmFullName);
|
||||
console.log('MAX_PADDED_ECONTENT_LEN[signatureAlgorithmFullName]', MAX_PADDED_ECONTENT_LEN[signatureAlgorithmFullName]);
|
||||
const [eContentPadded, eContentLen] = shaPad(
|
||||
new Uint8Array(eContent),
|
||||
MAX_PADDED_ECONTENT_LEN[signatureAlgorithmFullName]
|
||||
|
||||
@@ -26,8 +26,8 @@ export function customHasher(pubKeyFormatted: string[]) {
|
||||
export function getLeaf(dsc: string): string {
|
||||
const { signatureAlgorithm, hashFunction, modulus, x, y, bits, curve, exponent } = parseCertificate(dsc);
|
||||
const { n, k } = getNAndK(signatureAlgorithm);
|
||||
console.log(`${signatureAlgorithm}_${curve || exponent}_${hashFunction}_${bits}`)
|
||||
const sigAlgKey = `${signatureAlgorithm}_${curve || exponent}_${hashFunction}_${bits}`;
|
||||
console.log(`${signatureAlgorithm}_${hashFunction}_${curve || exponent}_${bits}`);
|
||||
const sigAlgKey = `${signatureAlgorithm}_${hashFunction}_${curve || exponent}_${bits}`;
|
||||
const sigAlgIndex = SignatureAlgorithmIndex[sigAlgKey];
|
||||
|
||||
if (sigAlgIndex == undefined) {
|
||||
@@ -47,9 +47,11 @@ export function getLeaf(dsc: string): string {
|
||||
export function getLeafCSCA(dsc: string): string {
|
||||
const { signatureAlgorithm, hashFunction, modulus, x, y, bits, curve, exponent } = parseCertificate(dsc);
|
||||
const { n, k } = getNAndKCSCA(signatureAlgorithm);
|
||||
console.log(`${signatureAlgorithm}_${curve || exponent}_${hashFunction}_${bits}`)
|
||||
const sigAlgKey = `${signatureAlgorithm}_${curve || exponent}_${hashFunction}_${bits}`;
|
||||
console.log(`${signatureAlgorithm}_${hashFunction}_${curve || exponent}_${bits}`)
|
||||
const sigAlgKey = `${signatureAlgorithm}_${hashFunction}_${curve || exponent}_${bits}`;
|
||||
console.log('sigAlgKey', sigAlgKey);
|
||||
const sigAlgIndex = SignatureAlgorithmIndex[sigAlgKey];
|
||||
console.log('sigAlgIndex', sigAlgIndex);
|
||||
|
||||
if (sigAlgIndex == undefined) {
|
||||
console.error(`\x1b[31mInvalid signature algorithm: ${sigAlgKey}\x1b[0m`);
|
||||
|
||||
@@ -9,7 +9,8 @@ export type PassportData = {
|
||||
mockUser?: boolean;
|
||||
};
|
||||
|
||||
export type SignatureAlgorithm = 'rsa_sha1' | 'rsa_sha256' | 'rsapss_sha256' | 'ecdsa_sha256' | 'ecdsa_sha1' | 'ecdsa_sha384';
|
||||
// Define the signature algorithm in "algorithm_hashfunction_domainPapameter_keyLength"
|
||||
export type SignatureAlgorithm = 'rsa_sha1_65537_2048' | 'rsa_sha256_65537_2048' | 'rsapss_sha256_65537_2048' | 'ecdsa_sha256_secp256r1_256' | 'ecdsa_sha1_secp256r1_256' | 'ecdsa_sha384_secp384r1_384' | 'ecdsa_sha256_brainpoolP256r1_256' | 'rsa_sha256_3_2048' | 'rsa_sha256_65537_3072';
|
||||
|
||||
export type Proof = {
|
||||
proof: {
|
||||
|
||||
Reference in New Issue
Block a user