{"version":3,"file":"RsaPublicJwk.mjs","names":[],"sources":["../../../../../../src/modules/kms/jwk/kty/rsa/RsaPublicJwk.ts"],"sourcesContent":["import { TypedArrayEncoder } from '../../../../../utils'\nimport { KeyManagementError } from '../../../error/KeyManagementError'\nimport type { KnownJwaKeyAgreementAlgorithm, KnownJwaSignatureAlgorithm } from '../../jwa'\nimport type { PublicJwkType } from '../PublicJwk'\nimport type { KmsJwkPublicRsa } from './rsaJwk'\nimport { rsaPublicJwkToPublicKey, rsaPublicKeyToPublicJwk } from './rsaPublicKey'\n\nexport class RsaPublicJwk implements PublicJwkType<KmsJwkPublicRsa> {\n  public static supportedEncryptionKeyAgreementAlgorithms: KnownJwaKeyAgreementAlgorithm[] = []\n  public static supportedSignatureAlgorithms: KnownJwaSignatureAlgorithm[] = [\n    'PS256',\n    'RS256',\n    'RS384',\n    'PS384',\n    'RS512',\n    'PS512',\n  ]\n  public static multicodecPrefix = 4613\n\n  public multicodecPrefix = RsaPublicJwk.multicodecPrefix\n  public supportedEncryptionKeyAgreementAlgorithms = RsaPublicJwk.supportedEncryptionKeyAgreementAlgorithms\n\n  public get supportedSignatureAlgorithms() {\n    const keyBits = TypedArrayEncoder.fromBase64Url(this.jwk.n).length * 8\n\n    // RSA needs minimum bit lengths for each algorithm\n    const minBits2048 = ['PS256', 'RS256'] satisfies KnownJwaSignatureAlgorithm[]\n    const minBits3072 = [...minBits2048, 'RS384', 'PS384'] satisfies KnownJwaSignatureAlgorithm[]\n    const minBits4096 = [...minBits3072, 'RS512', 'PS512'] satisfies KnownJwaSignatureAlgorithm[]\n\n    return keyBits >= 4096 ? minBits4096 : keyBits >= 3072 ? minBits3072 : keyBits >= 2048 ? minBits2048 : []\n  }\n\n  public constructor(public readonly jwk: KmsJwkPublicRsa) {}\n\n  public get publicKey() {\n    return {\n      kty: this.jwk.kty,\n      ...rsaPublicJwkToPublicKey(this.jwk),\n    }\n  }\n\n  /**\n   * Not supported for RSA\n   */\n  public get compressedPublicKey() {\n    return null\n  }\n\n  public get multicodec(): Uint8Array {\n    throw new KeyManagementError('multicodec not supported for RsaPublicJwk')\n  }\n\n  public static fromPublicKey(publicKey: { modulus: Uint8Array; exponent: Uint8Array }) {\n    return new RsaPublicJwk(rsaPublicKeyToPublicJwk(publicKey))\n  }\n\n  public static fromMulticodec(_multicodec: Uint8Array): RsaPublicJwk {\n    throw new KeyManagementError('fromMulticodec not supported for RsaPublicJwk')\n  }\n}\n"],"mappings":";;;;;AAOA,IAAa,eAAb,MAAa,aAAuD;CAelE,IAAW,+BAA+B;EACxC,MAAM,UAAU,kBAAkB,cAAc,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS;EAGrE,MAAM,cAAc,CAAC,SAAS,OAAO;EACrC,MAAM,cAAc;GAAC,GAAG;GAAa;GAAS;EAAO;EACrD,MAAM,cAAc;GAAC,GAAG;GAAa;GAAS;EAAO;EAErD,OAAO,WAAW,OAAO,cAAc,WAAW,OAAO,cAAc,WAAW,OAAO,cAAc,CAAC;CAC1G;CAEA,YAAmB,KAAsC;EAAtB,KAAA,MAAA;EAdnC,KAAO,mBAAmB,aAAa;EACvC,KAAO,4CAA4C,aAAa;CAaN;CAE1D,IAAW,YAAY;EACrB,OAAO;GACL,KAAK,KAAK,IAAI;GACd,GAAG,wBAAwB,KAAK,GAAG;EACrC;CACF;;;;CAKA,IAAW,sBAAsB;EAC/B,OAAO;CACT;CAEA,IAAW,aAAyB;EAClC,MAAM,IAAI,mBAAmB,2CAA2C;CAC1E;CAEA,OAAc,cAAc,WAA0D;EACpF,OAAO,IAAI,aAAa,wBAAwB,SAAS,CAAC;CAC5D;CAEA,OAAc,eAAe,aAAuC;EAClE,MAAM,IAAI,mBAAmB,+CAA+C;CAC9E;AACF;AApDE,aAAc,4CAA6E,CAAC;AAC5F,aAAc,+BAA6D;CACzE;CACA;CACA;CACA;CACA;CACA;AACF;AACA,aAAc,mBAAmB"}