import { $APP, shadow$provide } from "./shared.js";
import*as esm_import$$noble$curves$ed25519 from"@noble/curves/ed25519";var bb;$APP.Ya=function(a,b){return Promise.resolve(null).then(function(){var c=$APP.B(a);return crypto.subtle.importKey("raw",c,"HKDF",!1,["deriveBits"]).then(function(d){return crypto.subtle.deriveBits({name:"HKDF",hash:"SHA-256",salt:$APP.v(b),info:$APP.v("id-x25519|v1")},d,256).then(function(e){e=new Uint8Array(e);return{priv:e,pubB64:$APP.A(esm_import$$noble$curves$ed25519.x25519.getPublicKey(e))}})})})};
$APP.Za=function(a){return $APP.Ya(a,"ardegazu.ro/id/v1")};$APP.$a=function(a,b,c){return $APP.ia(a,$APP.v("board-x25519|v1|"+$APP.u(b)+"|"+$APP.u(a.publicKeyB64)+"|"+$APP.u(c))).then(function(d){return $APP.A(d)})};$APP.ab=function(a,b,c,d){return $APP.ka(b,d,$APP.v("board-x25519|v1|"+$APP.u(a)+"|"+$APP.u(b)+"|"+$APP.u(c)))};
bb=function(a,b,c,d,e){return crypto.subtle.importKey("raw",a,"HKDF",!1,["deriveKey"]).then(function(f){return crypto.subtle.deriveKey({name:"HKDF",hash:"SHA-256",salt:$APP.v(b),info:$APP.v("wrap|v1|"+$APP.u(c)+"|"+$APP.u(d)+"|"+$APP.u(e))},f,{name:"AES-GCM",length:256},!1,["encrypt","decrypt"])})};
$APP.cb=function(a,b,c,d,e){return Promise.resolve(null).then(function(){var f=$APP.w(32),g=esm_import$$noble$curves$ed25519.x25519.getPublicKey(f),k=$APP.A(g);f=esm_import$$noble$curves$ed25519.x25519.getSharedSecret(f,$APP.B(d));return bb(f,a,b,c,k).then(function(h){var q=$APP.w(12);return crypto.subtle.encrypt({name:"AES-GCM",iv:q,additionalData:$APP.v("v1|"+$APP.u(b)+"|wrap|"+$APP.u(c))},h,e).then(function(p){return{to:c,toX:d,ephPub:k,iv:$APP.y(q),ct:$APP.y(new Uint8Array(p))}})})})};
$APP.db=function(a,b,c,d){return Promise.resolve(null).then(function(){var e=esm_import$$noble$curves$ed25519.x25519.getSharedSecret(d.priv,$APP.B(c.ephPub));return bb(e,a,b,c.to,c.ephPub).then(function(f){return crypto.subtle.decrypt({name:"AES-GCM",iv:$APP.z(c.iv),additionalData:$APP.v("v1|"+$APP.u(b)+"|wrap|"+$APP.u(c.to))},f,$APP.z(c.ct)).then(function(g){return new Uint8Array(g)})})}).catch(function(){return null})};export const SUITE_SALT="ardegazu.ro/id/v1";export const deriveXKeyPair=$APP.Ya;export const deriveSuiteXKeyPair=$APP.Za;export const signXCert=$APP.$a;export const verifyXCert=$APP.ab;export const wrapTo=$APP.cb;export const unwrap=$APP.db;