UNPKG

signify-ts

Version:

Signing at the edge for KERI, ACDC, and KERIA

1,829 lines (1,812 loc) 215 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var src_exports = {}; __export(src_exports, { Agent: () => Agent, Algos: () => Algos, Authenticater: () => Authenticater, B64ChrByIdx: () => B64ChrByIdx, B64IdxByChr: () => B64IdxByChr, BexCodex: () => BexCodex, BexDex: () => BexDex, CesrNumber: () => CesrNumber, Challenges: () => Challenges, Cigar: () => Cigar, Cipher: () => Cipher, Codex: () => Codex, Config: () => Config, Contacts: () => Contacts, Controller: () => Controller, Counter: () => Counter, CounterCodex: () => CounterCodex, Creatory: () => Creatory, CredentialTypes: () => CredentialTypes, Credentials: () => Credentials, CtrDex: () => CtrDex, Decrypter: () => Decrypter, Diger: () => Diger, DigiCodex: () => DigiCodex, DigiDex: () => DigiDex, DipLabels: () => DipLabels, DrtLabels: () => DrtLabels, EmptyMaterialError: () => EmptyMaterialError, Encrypter: () => Encrypter, Escrows: () => Escrows, EventResult: () => EventResult, Exchanges: () => Exchanges, FALSY: () => FALSY, GroupKeeper: () => GroupKeeper, Groups: () => Groups, HEADER_SIG_INPUT: () => HEADER_SIG_INPUT, HEADER_SIG_TIME: () => HEADER_SIG_TIME, Hab: () => Hab, Habery: () => Habery, IcpLabels: () => IcpLabels, Ident: () => Ident, Identifier: () => Identifier, IdrDex: () => IdrDex, Ids: () => Ids, IdxBthSigDex: () => IdxBthSigDex, IdxCrtSigDex: () => IdxCrtSigDex, IdxSigDex: () => IdxSigDex, Ilks: () => Ilks, IndexedBothSigCodex: () => IndexedBothSigCodex, IndexedCurrentSigCodex: () => IndexedCurrentSigCodex, IndexedSigCodex: () => IndexedSigCodex, Indexer: () => Indexer, IndexerCodex: () => IndexerCodex, Inputage: () => Inputage, Ipex: () => Ipex, IxnLabels: () => IxnLabels, KeyEvents: () => KeyEvents, KeyManager: () => KeyManager, KeyStates: () => KeyStates, KsnLabels: () => KsnLabels, LargeVrzDex: () => LargeVrzDex, MINSIGSIZE: () => MINSIGSIZE, MINSNIFFSIZE: () => MINSNIFFSIZE, Manager: () => Manager, Matter: () => Matter, MatterCodex: () => MatterCodex, MtrDex: () => MtrDex, NonTransCodex: () => NonTransCodex, NonTransDex: () => NonTransDex, Notifications: () => Notifications, NumCodex: () => NumCodex, NumDex: () => NumDex, Oobis: () => Oobis, Operations: () => Operations, Prefixer: () => Prefixer, RandyCreator: () => RandyCreator, RandyKeeper: () => RandyKeeper, Registries: () => Registries, RegistryResult: () => RegistryResult, RotLabels: () => RotLabels, RpyLabels: () => RpyLabels, Saider: () => Saider, Salter: () => Salter, SaltyCreator: () => SaltyCreator, SaltyKeeper: () => SaltyKeeper, Schemas: () => Schemas, Seqner: () => Seqner, Serder: () => Serder, Serials: () => Serials, Siger: () => Siger, Signage: () => Signage, Signer: () => Signer, SignifyClient: () => SignifyClient, Sizage: () => Sizage, SmallVrzDex: () => SmallVrzDex, TRUTHY: () => TRUTHY, Tholder: () => Tholder, Tier: () => Tier, TraitCodex: () => TraitCodex, TraitDex: () => TraitDex, Unqualified: () => Unqualified, VEREX: () => VEREX, VERFULLSIZE: () => VERFULLSIZE, Verfer: () => Verfer, Version: () => Version, Versionage: () => Versionage, Xizage: () => Xizage, ample: () => ample, arrayEquals: () => arrayEquals, b: () => b, b64ToInt: () => b64ToInt, bytesToInt: () => bytesToInt, concat: () => concat, d: () => d, default: () => src_default, desiginput: () => desiginput, designature: () => designature, deversify: () => deversify, dumps: () => dumps, exchange: () => exchange, extractValues: () => extractValues, incept: () => incept, intToB64: () => intToB64, intToB64b: () => intToB64b, intToBytes: () => intToBytes, interact: () => interact, messagize: () => messagize, normalize: () => normalize, nowUTC: () => nowUTC, openManager: () => openManager, pad: () => pad, parseRangeHeaders: () => parseRangeHeaders, randomNonce: () => randomNonce, randomPasscode: () => randomPasscode, range: () => range, readInt: () => readInt, ready: () => ready, reply: () => reply, riKey: () => riKey, rotate: () => rotate, serializeACDCAttachment: () => serializeACDCAttachment, serializeIssExnAttachment: () => serializeIssExnAttachment, siginput: () => siginput, signature: () => signature, sizeify: () => sizeify, versify: () => versify }); module.exports = __toCommonJS(src_exports); // src/exports.ts var exports_exports = {}; __export(exports_exports, { Agent: () => Agent, Algos: () => Algos, Authenticater: () => Authenticater, B64ChrByIdx: () => B64ChrByIdx, B64IdxByChr: () => B64IdxByChr, BexCodex: () => BexCodex, BexDex: () => BexDex, CesrNumber: () => CesrNumber, Challenges: () => Challenges, Cigar: () => Cigar, Cipher: () => Cipher, Codex: () => Codex, Config: () => Config, Contacts: () => Contacts, Controller: () => Controller, Counter: () => Counter, CounterCodex: () => CounterCodex, Creatory: () => Creatory, CredentialTypes: () => CredentialTypes, Credentials: () => Credentials, CtrDex: () => CtrDex, Decrypter: () => Decrypter, Diger: () => Diger, DigiCodex: () => DigiCodex, DigiDex: () => DigiDex, DipLabels: () => DipLabels, DrtLabels: () => DrtLabels, EmptyMaterialError: () => EmptyMaterialError, Encrypter: () => Encrypter, Escrows: () => Escrows, EventResult: () => EventResult, Exchanges: () => Exchanges, FALSY: () => FALSY, GroupKeeper: () => GroupKeeper, Groups: () => Groups, HEADER_SIG_INPUT: () => HEADER_SIG_INPUT, HEADER_SIG_TIME: () => HEADER_SIG_TIME, Hab: () => Hab, Habery: () => Habery, IcpLabels: () => IcpLabels, Ident: () => Ident, Identifier: () => Identifier, IdrDex: () => IdrDex, Ids: () => Ids, IdxBthSigDex: () => IdxBthSigDex, IdxCrtSigDex: () => IdxCrtSigDex, IdxSigDex: () => IdxSigDex, Ilks: () => Ilks, IndexedBothSigCodex: () => IndexedBothSigCodex, IndexedCurrentSigCodex: () => IndexedCurrentSigCodex, IndexedSigCodex: () => IndexedSigCodex, Indexer: () => Indexer, IndexerCodex: () => IndexerCodex, Inputage: () => Inputage, Ipex: () => Ipex, IxnLabels: () => IxnLabels, KeyEvents: () => KeyEvents, KeyManager: () => KeyManager, KeyStates: () => KeyStates, KsnLabels: () => KsnLabels, LargeVrzDex: () => LargeVrzDex, MINSIGSIZE: () => MINSIGSIZE, MINSNIFFSIZE: () => MINSNIFFSIZE, Manager: () => Manager, Matter: () => Matter, MatterCodex: () => MatterCodex, MtrDex: () => MtrDex, NonTransCodex: () => NonTransCodex, NonTransDex: () => NonTransDex, Notifications: () => Notifications, NumCodex: () => NumCodex, NumDex: () => NumDex, Oobis: () => Oobis, Operations: () => Operations, Prefixer: () => Prefixer, RandyCreator: () => RandyCreator, RandyKeeper: () => RandyKeeper, Registries: () => Registries, RegistryResult: () => RegistryResult, RotLabels: () => RotLabels, RpyLabels: () => RpyLabels, Saider: () => Saider, Salter: () => Salter, SaltyCreator: () => SaltyCreator, SaltyKeeper: () => SaltyKeeper, Schemas: () => Schemas, Seqner: () => Seqner, Serder: () => Serder, Serials: () => Serials, Siger: () => Siger, Signage: () => Signage, Signer: () => Signer, SignifyClient: () => SignifyClient, Sizage: () => Sizage, SmallVrzDex: () => SmallVrzDex, TRUTHY: () => TRUTHY, Tholder: () => Tholder, Tier: () => Tier, TraitCodex: () => TraitCodex, TraitDex: () => TraitDex, Unqualified: () => Unqualified, VEREX: () => VEREX, VERFULLSIZE: () => VERFULLSIZE, Verfer: () => Verfer, Version: () => Version, Versionage: () => Versionage, Xizage: () => Xizage, ample: () => ample, arrayEquals: () => arrayEquals, b: () => b, b64ToInt: () => b64ToInt, bytesToInt: () => bytesToInt, concat: () => concat, d: () => d, desiginput: () => desiginput, designature: () => designature, deversify: () => deversify, dumps: () => dumps, exchange: () => exchange, extractValues: () => extractValues, incept: () => incept, intToB64: () => intToB64, intToB64b: () => intToB64b, intToBytes: () => intToBytes, interact: () => interact, messagize: () => messagize, normalize: () => normalize, nowUTC: () => nowUTC, openManager: () => openManager, pad: () => pad, parseRangeHeaders: () => parseRangeHeaders, randomNonce: () => randomNonce, randomPasscode: () => randomPasscode, range: () => range, readInt: () => readInt, ready: () => ready, reply: () => reply, riKey: () => riKey, rotate: () => rotate, serializeACDCAttachment: () => serializeACDCAttachment, serializeIssExnAttachment: () => serializeIssExnAttachment, siginput: () => siginput, signature: () => signature, sizeify: () => sizeify, versify: () => versify }); // src/ready.ts var import_libsodium_wrappers_sumo = __toESM(require("libsodium-wrappers-sumo"), 1); var ready = async () => { await import_libsodium_wrappers_sumo.default.ready; }; // src/keri/core/encrypter.ts var import_libsodium_wrappers_sumo6 = __toESM(require("libsodium-wrappers-sumo"), 1); // src/keri/core/kering.ts var EmptyMaterialError = class { _err; constructor(err) { this._err = new Error(err); } get err() { return this._err; } }; // src/keri/core/core.ts var Serials = /* @__PURE__ */ ((Serials2) => { Serials2["JSON"] = "JSON"; return Serials2; })(Serials || {}); var Ident = /* @__PURE__ */ ((Ident2) => { Ident2["KERI"] = "KERI"; Ident2["ACDC"] = "ACDC"; return Ident2; })(Ident || {}); var Version = class { major; minor; constructor(major = 1, minor = 0) { this.major = major; this.minor = minor; } }; var Versionage = new Version(); var Ilks = { icp: "icp", rot: "rot", ixn: "ixn", dip: "dip", drt: "drt", rct: "rct", vrc: "vrc", rpy: "rpy", exn: "exn", vcp: "vcp", iss: "iss", rev: "rev", bis: "bis", brv: "brv" }; var IcpLabels = [ "v", "i", "s", "t", "kt", "k", "n", "bt", "b", "c", "a" ]; var DipLabels = [ "v", "i", "s", "t", "kt", "k", "n", "bt", "b", "c", "a", "di" ]; var RotLabels = [ "v", "i", "s", "t", "p", "kt", "k", "n", "bt", "br", "ba", "a" ]; var DrtLabels = [ "v", "i", "s", "t", "p", "kt", "k", "n", "bt", "br", "ba", "a" ]; var IxnLabels = ["v", "i", "s", "t", "p", "a"]; var KsnLabels = [ "v", "i", "s", "t", "p", "d", "f", "dt", "et", "kt", "k", "n", "bt", "b", "c", "ee", "di", "r" ]; var RpyLabels = ["v", "t", "d", "dt", "r", "a"]; var encoder = new TextEncoder(); var decoder = new TextDecoder(); var VERFULLSIZE = 17; var MINSNIFFSIZE = 12 + VERFULLSIZE; var MINSIGSIZE = 4; var VEREX = "(KERI|ACDC)([0-9a-f])([0-9a-f])([A-Z]{4})([0-9a-f]{6})_"; function deversify(versionString) { let kind; let size; let proto; const version = Versionage; const re = new RegExp(VEREX); const match = re.exec(versionString); if (match) { [proto, version.major, version.minor, kind, size] = [ match[1], +match[2], +match[3], match[4], match[5] ]; if (!Object.values(Serials).includes(kind)) { throw new Error(`Invalid serialization kind = ${kind}`); } if (!Object.values(Ident).includes(proto)) { throw new Error(`Invalid serialization kind = ${kind}`); } const ta = kind; kind = Serials[ta]; const pa = proto; proto = Ident[pa]; return [proto, kind, version, size]; } throw new Error(`Invalid version string = ${versionString}`); } function versify(ident = "KERI" /* KERI */, version, kind = "JSON" /* JSON */, size = 0) { version = version == void 0 ? Versionage : version; return `${ident}${version.major.toString( 16 )}${version.minor.toString()}${kind}${size.toString(16).padStart(6, "0")}_`; } var B64ChrByIdx = /* @__PURE__ */ new Map([ [0, "A"], [1, "B"], [2, "C"], [3, "D"], [4, "E"], [5, "F"], [6, "G"], [7, "H"], [8, "I"], [9, "J"], [10, "K"], [11, "L"], [12, "M"], [13, "N"], [14, "O"], [15, "P"], [16, "Q"], [17, "R"], [18, "S"], [19, "T"], [20, "U"], [21, "V"], [22, "W"], [23, "X"], [24, "Y"], [25, "Z"], [26, "a"], [27, "b"], [28, "c"], [29, "d"], [30, "e"], [31, "f"], [32, "g"], [33, "h"], [34, "i"], [35, "j"], [36, "k"], [37, "l"], [38, "m"], [39, "n"], [40, "o"], [41, "p"], [42, "q"], [43, "r"], [44, "s"], [45, "t"], [46, "u"], [47, "v"], [48, "w"], [49, "x"], [50, "y"], [51, "z"], [52, "0"], [53, "1"], [54, "2"], [55, "3"], [56, "4"], [57, "5"], [58, "6"], [59, "7"], [60, "8"], [61, "9"], [62, "-"], [63, "_"] ]); var B64IdxByChr = new Map( Array.from(B64ChrByIdx, (entry) => [entry[1], entry[0]]) ); function intToB64(i, l = 1) { let out = ""; while (l != 0) { out = B64ChrByIdx.get(i % 64) + out; i = Math.floor(i / 64); if (i == 0) { break; } } const x = l - out.length; for (let i2 = 0; i2 < x; i2++) { out = "A" + out; } return out; } function intToB64b(n, l = 1) { const s = intToB64(n, l); return b(s); } function b64ToInt(s) { if (s.length == 0) { throw new Error("Empty string, conversion undefined."); } let i = 0; const rev = s.split("").reverse(); rev.forEach((c, e) => { i |= B64IdxByChr.get(c) << e * 6; }); return i; } function b(s) { return encoder.encode(s); } function d(u) { return decoder.decode(u); } function concat(one, two) { const out = new Uint8Array(one.length + two.length); out.set(one); out.set(two, one.length); return out; } function readInt(array) { let value = 0; for (let i = 0; i < array.length; i++) { value = value * 256 + array[i]; } return value; } // src/keri/core/matter.ts var import_buffer2 = require("buffer"); // src/keri/core/base64.ts var import_buffer = require("buffer"); function encodeBase64Url(buffer) { if (!import_buffer.Buffer.isBuffer(buffer)) { throw new TypeError("`buffer` must be a buffer."); } return buffer.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+/, ""); } function decodeBase64Url(input) { if (!(typeof input === "string")) { throw new TypeError("`input` must be a string."); } const n = input.length % 4; const padded = input + "=".repeat(n > 0 ? 4 - n : n); const base64String = padded.replace(/-/g, "+").replace(/_/g, "/"); return import_buffer.Buffer.from(base64String, "base64"); } // src/keri/core/matter.ts var Codex = class { has(prop) { const m = new Map( Array.from(Object.entries(this), (v) => [v[1], v[0]]) ); return m.has(prop); } }; var MatterCodex = class extends Codex { Ed25519_Seed = "A"; // Ed25519 256 bit random seed for private key Ed25519N = "B"; // Ed25519 verification key non-transferable, basic derivation. X25519 = "C"; // X25519 public encryption key, converted from Ed25519 or Ed25519N. Ed25519 = "D"; // Ed25519 verification key basic derivation Blake3_256 = "E"; // Blake3 256 bit digest self-addressing derivation. SHA3_256 = "H"; // SHA3 256 bit digest self-addressing derivation. SHA2_256 = "I"; // SHA2 256 bit digest self-addressing derivation. ECDSA_256k1_Seed = "J"; // ECDSA secp256k1 256 bit random Seed for private key X25519_Private = "O"; // X25519 private decryption key converted from Ed25519 X25519_Cipher_Seed = "P"; // X25519 124 char b64 Cipher of 44 char qb64 Seed ECDSA_256r1_Seed = "Q"; // ECDSA secp256r1 256 bit random Seed for private key Salt_128 = "0A"; // 128 bit random salt or 128 bit number (see Huge) Ed25519_Sig = "0B"; // Ed25519 signature. ECDSA_256k1_Sig = "0C"; // ECDSA secp256k1 signature. ECDSA_256r1_Sig = "0I"; // ECDSA secp256r1 signature. StrB64_L0 = "4A"; // String Base64 Only Lead Size 0 StrB64_L1 = "5A"; // String Base64 Only Lead Size 1 StrB64_L2 = "6A"; // String Base64 Only Lead Size 2 ECDSA_256k1N = "1AAA"; // ECDSA secp256k1 verification key non-transferable, basic derivation. ECDSA_256k1 = "1AAB"; // ECDSA public verification or encryption key, basic derivation X25519_Cipher_Salt = "1AAH"; // X25519 100 char b64 Cipher of 24 char qb64 Salt ECDSA_256r1N = "1AAI"; // ECDSA secp256r1 verification key non-transferable, basic derivation. ECDSA_256r1 = "1AAJ"; // ECDSA secp256r1 verification or encryption key, basic derivation StrB64_Big_L0 = "7AAA"; // String Base64 Only Big Lead Size 0 StrB64_Big_L1 = "8AAA"; // String Base64 Only Big Lead Size 1 StrB64_Big_L2 = "9AAA"; // String Base64 Only Big Lead Size 2 }; var MtrDex = new MatterCodex(); var NonTransCodex = class extends Codex { Ed25519N = "B"; // Ed25519 verification key non-transferable, basic derivation. ECDSA_256k1N = "1AAA"; // ECDSA secp256k1 verification key non-transferable, basic derivation. Ed448N = "1AAC"; // Ed448 non-transferable prefix public signing verification key. Basic derivation. ECDSA_256r1N = "1AAI"; // ECDSA secp256r1 verification key non-transferable, basic derivation. }; var NonTransDex = new NonTransCodex(); var DigiCodex = class extends Codex { Blake3_256 = "E"; // Blake3 256 bit digest self-addressing derivation. Blake2b_256 = "F"; // Blake2b 256 bit digest self-addressing derivation. Blake2s_256 = "G"; // Blake2s 256 bit digest self-addressing derivation. SHA3_256 = "H"; // SHA3 256 bit digest self-addressing derivation. SHA2_256 = "I"; // SHA2 256 bit digest self-addressing derivation. Blake3_512 = "0D"; // Blake3 512 bit digest self-addressing derivation. Blake2b_512 = "0E"; // Blake2b 512 bit digest self-addressing derivation. SHA3_512 = "0F"; // SHA3 512 bit digest self-addressing derivation. SHA2_512 = "0G"; // SHA2 512 bit digest self-addressing derivation. }; var DigiDex = new DigiCodex(); var NumCodex = class extends Codex { Short = "M"; // Short 2 byte b2 number Long = "0H"; // Long 4 byte b2 number Big = "N"; // Big 8 byte b2 number Huge = "0A"; // Huge 16 byte b2 number (same as Salt_128) }; var NumDex = new NumCodex(); var BexCodex = class extends Codex { StrB64_L0 = "4A"; // String Base64 Only Leader Size 0 StrB64_L1 = "5A"; // String Base64 Only Leader Size 1 StrB64_L2 = "6A"; // String Base64 Only Leader Size 2 StrB64_Big_L0 = "7AAA"; // String Base64 Only Big Leader Size 0 StrB64_Big_L1 = "8AAA"; // String Base64 Only Big Leader Size 1 StrB64_Big_L2 = "9AAA"; // String Base64 Only Big Leader Size 2 }; var BexDex = new BexCodex(); var SmallVarRawSizeCodex = class extends Codex { Lead0 = "4"; // First Selector Character for all ls == 0 codes Lead1 = "5"; // First Selector Character for all ls == 1 codes Lead2 = "6"; // First Selector Character for all ls == 2 codes }; var SmallVrzDex = new SmallVarRawSizeCodex(); var LargeVarRawSizeCodex = class extends Codex { Lead0_Big = "7"; // First Selector Character for all ls == 0 codes Lead1_Big = "8"; // First Selector Character for all ls == 1 codes Lead2_Big = "9"; // First Selector Character for all ls == 2 codes }; var LargeVrzDex = new LargeVarRawSizeCodex(); var Sizage = class { hs; ss; ls; fs; constructor(hs, ss, fs, ls) { this.hs = hs; this.ss = ss; this.fs = fs; this.ls = ls; } }; var Matter = class _Matter { static Sizes = new Map( Object.entries({ A: new Sizage(1, 0, 44, 0), B: new Sizage(1, 0, 44, 0), C: new Sizage(1, 0, 44, 0), D: new Sizage(1, 0, 44, 0), E: new Sizage(1, 0, 44, 0), F: new Sizage(1, 0, 44, 0), G: new Sizage(1, 0, 44, 0), H: new Sizage(1, 0, 44, 0), I: new Sizage(1, 0, 44, 0), J: new Sizage(1, 0, 44, 0), K: new Sizage(1, 0, 76, 0), L: new Sizage(1, 0, 76, 0), M: new Sizage(1, 0, 4, 0), N: new Sizage(1, 0, 12, 0), O: new Sizage(1, 0, 44, 0), P: new Sizage(1, 0, 124, 0), Q: new Sizage(1, 0, 44, 0), "0A": new Sizage(2, 0, 24, 0), "0B": new Sizage(2, 0, 88, 0), "0C": new Sizage(2, 0, 88, 0), "0D": new Sizage(2, 0, 88, 0), "0E": new Sizage(2, 0, 88, 0), "0F": new Sizage(2, 0, 88, 0), "0G": new Sizage(2, 0, 88, 0), "0H": new Sizage(2, 0, 8, 0), "0I": new Sizage(2, 0, 88, 0), "1AAA": new Sizage(4, 0, 48, 0), "1AAB": new Sizage(4, 0, 48, 0), "1AAC": new Sizage(4, 0, 80, 0), "1AAD": new Sizage(4, 0, 80, 0), "1AAE": new Sizage(4, 0, 56, 0), "1AAF": new Sizage(4, 0, 8, 0), "1AAG": new Sizage(4, 0, 36, 0), "1AAH": new Sizage(4, 0, 100, 0), "1AAI": new Sizage(4, 0, 48, 0), "1AAJ": new Sizage(4, 0, 48, 0), "2AAA": new Sizage(4, 0, 8, 1), "3AAA": new Sizage(4, 0, 8, 2), "4A": new Sizage(2, 2, void 0, 0), "5A": new Sizage(2, 2, void 0, 1), "6A": new Sizage(2, 2, void 0, 2), "7AAA": new Sizage(4, 4, void 0, 0), "8AAA": new Sizage(4, 4, void 0, 1), "9AAA": new Sizage(4, 4, void 0, 2), "4B": new Sizage(2, 2, void 0, 0), "5B": new Sizage(2, 2, void 0, 1), "6B": new Sizage(2, 2, void 0, 2), "7AAB": new Sizage(4, 4, void 0, 0), "8AAB": new Sizage(4, 4, void 0, 1), "9AAB": new Sizage(4, 4, void 0, 2) }) ); static Hards = /* @__PURE__ */ new Map([ ["A", 1], ["B", 1], ["C", 1], ["D", 1], ["E", 1], ["F", 1], ["G", 1], ["H", 1], ["I", 1], ["J", 1], ["K", 1], ["L", 1], ["M", 1], ["N", 1], ["O", 1], ["P", 1], ["Q", 1], ["R", 1], ["S", 1], ["T", 1], ["U", 1], ["V", 1], ["W", 1], ["X", 1], ["Y", 1], ["Z", 1], ["a", 1], ["b", 1], ["c", 1], ["d", 1], ["e", 1], ["f", 1], ["g", 1], ["h", 1], ["i", 1], ["j", 1], ["k", 1], ["l", 1], ["m", 1], ["n", 1], ["o", 1], ["p", 1], ["q", 1], ["r", 1], ["s", 1], ["t", 1], ["u", 1], ["v", 1], ["w", 1], ["x", 1], ["y", 1], ["z", 1], ["0", 2], ["1", 4], ["2", 4], ["3", 4], ["4", 2], ["5", 2], ["6", 2], ["7", 4], ["8", 4], ["9", 4] ]); _code = ""; _size = -1; _raw = new Uint8Array(0); constructor({ raw, code = MtrDex.Ed25519N, qb64b, qb64, qb2, rize }) { let size = -1; if (raw != void 0) { if (code.length == 0) { throw new Error( "Improper initialization need either (raw and code) or qb64b or qb64 or qb2." ); } if (SmallVrzDex.has(code[0]) || LargeVrzDex.has(code[0])) { if (rize !== void 0) { if (rize < 0) throw new Error( `missing var raw size for code=${code}` ); } else { rize = raw.length; } const ls = (3 - rize % 3) % 3; size = Math.floor((rize + ls) / 3); if (SmallVrzDex.has(code[0])) { if (size <= 64 ** 2 - 1) { const hs = 2; const s = Object.values(SmallVrzDex)[ls]; code = `${s}${code.substring(1, hs)}`; } else if (size <= 64 ** 4 - 1) { const hs = 4; const s = Object.values(LargeVrzDex)[ls]; code = `${s}${"AAAA".substring(0, hs - 2)}${code[1]}`; } else { throw new Error( `Unsupported raw size for code=${code}` ); } } else { if (size <= 64 ** 4 - 1) { const hs = 4; const s = Object.values(LargeVrzDex)[ls]; code = `${s}${code.substring(1, hs)}`; } else { throw new Error( `Unsupported raw size for code=${code}` ); } } } else { const sizage = _Matter.Sizes.get(code); if (sizage.fs == -1) { throw new Error(`Unsupported variable size code=${code}`); } rize = _Matter._rawSize(code); } raw = raw.slice(0, rize); if (raw.length != rize) { throw new Error( `Not enougth raw bytes for code=${code} expected ${rize} got ${raw.length}.` ); } this._code = code; this._size = size; this._raw = raw; } else if (qb64 !== void 0) { this._exfil(qb64); } else if (qb64b !== void 0) { const qb642 = d(qb64b); this._exfil(qb642); } else if (qb2 !== void 0) { this._bexfil(qb2); } else { throw new EmptyMaterialError("EmptyMaterialError"); } } get code() { return this._code; } get size() { return this._size; } get raw() { return this._raw; } get qb64() { return this._infil(); } get qb64b() { return b(this.qb64); } get transferable() { return !NonTransDex.has(this.code); } get digestive() { return DigiDex.has(this.code); } static _rawSize(code) { const sizage = this.Sizes.get(code); const cs = sizage.hs + sizage.ss; if (sizage.fs === -1) { throw Error(`Non-fixed raw size code ${code}.`); } return Math.floor((sizage.fs - cs) * 3 / 4) - sizage.ls; } static _leadSize(code) { const sizage = this.Sizes.get(code); return sizage.ls; } get both() { const sizage = _Matter.Sizes.get(this.code); return `${this.code}${intToB64(this.size, sizage.ss)}`; } _infil() { const code = this.code; const size = this.size; const raw = this.raw; const ps = (3 - raw.length % 3) % 3; const sizage = _Matter.Sizes.get(code); if (sizage.fs === void 0) { const cs = sizage.hs + sizage.ss; if (cs % 4) { throw new Error( `Whole code size not multiple of 4 for variable length material. cs=${cs}` ); } if (size < 0 || size > 64 ** sizage.ss - 1) { throw new Error(`Invalid size=${size} for code=${code}.`); } const both = `${code}${intToB64(size, sizage.ss)}`; if (both.length % 4 !== ps - sizage.ls) { throw new Error( `Invalid code=${both} for converted raw pad size=${ps}.` ); } const bytes = new Uint8Array(sizage.ls + raw.length); for (let i = 0; i < sizage.ls; i++) { bytes[i] = 0; } for (let i = 0; i < raw.length; i++) { const odx = i + ps; bytes[odx] = raw[i]; } return both + encodeBase64Url(import_buffer2.Buffer.from(bytes)); } else { const both = code; const cs = both.length; if (cs % 4 != ps - sizage.ls) { throw new Error( `Invalid code=${both} for converted raw pad size=${ps}, ${raw.length}.` ); } const bytes = new Uint8Array(ps + raw.length); for (let i = 0; i < ps; i++) { bytes[i] = 0; } for (let i = 0; i < raw.length; i++) { const odx = i + ps; bytes[odx] = raw[i]; } return both + encodeBase64Url(import_buffer2.Buffer.from(bytes)).slice(cs % 4); } } _exfil(qb64) { if (qb64.length == 0) { throw new Error("Empty Material"); } const first = qb64[0]; if (!Array.from(_Matter.Hards.keys()).includes(first)) { throw new Error(`Unexpected code ${first}`); } const hs = _Matter.Hards.get(first); if (qb64.length < hs) { throw new Error(`Shortage Error`); } const hard = qb64.slice(0, hs); if (!Array.from(_Matter.Sizes.keys()).includes(hard)) { throw new Error(`Unsupported code ${hard}`); } const sizage = _Matter.Sizes.get(hard); const cs = sizage.hs + sizage.ss; let size = -1; if (sizage.fs == -1) { throw new Error("Variable size codes not supported yet"); } else { size = sizage.fs; } if (qb64.length < sizage.fs) { throw new Error(`Need ${sizage.fs - qb64.length} more chars.`); } qb64 = qb64.slice(0, sizage.fs); const ps = cs % 4; const pbs = 2 * (ps == 0 ? sizage.ls : ps); let raw; if (ps != 0) { const base = new Array(ps + 1).join("A") + qb64.slice(cs); const paw = decodeBase64Url(base); const pi = readInt(paw.subarray(0, ps)); if (pi & 2 ** pbs - 1) { throw new Error( `Non zeroed prepad bits = {pi & (2 ** pbs - 1 ):<06b} in {qb64b[cs:cs+1]}.` ); } raw = paw.subarray(ps); } else { const base = qb64.slice(cs); const paw = decodeBase64Url(base); const li = readInt(paw.subarray(0, sizage.ls)); if (li != 0) { if (li == 1) { throw new Error(`Non zeroed lead byte = 0x{li:02x}.`); } else { throw new Error(`Non zeroed lead bytes = 0x{li:04x}`); } } raw = paw.subarray(sizage.ls); } this._code = hard; this._size = size; this._raw = Uint8Array.from(raw); } _bexfil(qb2) { throw new Error(`qb2 not yet supported: ${qb2}`); } }; // src/keri/core/verfer.ts var import_libsodium_wrappers_sumo2 = __toESM(require("libsodium-wrappers-sumo"), 1); var import_ecdsa_secp256r1 = __toESM(require("ecdsa-secp256r1"), 1); var Verfer = class extends Matter { _verify; constructor({ raw, code, qb64, qb64b, qb2 }) { super({ raw, code, qb64, qb64b, qb2 }); if (Array.from([MtrDex.Ed25519N, MtrDex.Ed25519]).includes(this.code)) { this._verify = this._ed25519; } else if (Array.from([MtrDex.ECDSA_256r1N, MtrDex.ECDSA_256r1]).includes( this.code )) { this._verify = this._secp256r1; } else { throw new Error(`Unsupported code = ${this.code} for verifier.`); } } verify(sig, ser) { return this._verify(sig, ser, this.raw); } _ed25519(sig, ser, key) { try { return import_libsodium_wrappers_sumo2.default.crypto_sign_verify_detached(sig, ser, key); } catch (error) { throw new Error(error); } } _secp256r1(sig, ser, key) { try { const publicKey = import_ecdsa_secp256r1.default.fromCompressedPublicKey(key); return publicKey.verify(ser, sig); } catch (error) { throw new Error(error); } } }; // src/keri/core/signer.ts var import_libsodium_wrappers_sumo3 = __toESM(require("libsodium-wrappers-sumo"), 1); // src/keri/core/cigar.ts var Cigar = class extends Matter { _verfer; constructor({ raw, code, qb64, qb64b, qb2 }, verfer) { super({ raw, code, qb64, qb64b, qb2 }); this._verfer = verfer; } get verfer() { return this._verfer; } set verfer(verfer) { this._verfer = verfer; } }; // src/keri/core/indexer.ts var import_buffer3 = require("buffer"); var IndexerCodex = class { Ed25519_Sig = "A"; // Ed25519 sig appears same in both lists if any. Ed25519_Crt_Sig = "B"; // Ed25519 sig appears in current list only. ECDSA_256k1_Sig = "C"; // ECDSA secp256k1 sig appears same in both lists if any. ECDSA_256k1_Crt_Sig = "D"; // ECDSA secp256k1 sig appears in current list. ECDSA_256r1_Sig = "E"; // ECDSA secp256r1 sig appears same in both lists if any. ECDSA_256r1_Crt_Sig = "F"; // ECDSA secp256r1 sig appears in current list. Ed448_Sig = "0A"; // Ed448 signature appears in both lists. Ed448_Crt_Sig = "0B"; // Ed448 signature appears in current list only. Ed25519_Big_Sig = "2A"; // Ed25519 sig appears in both lists. Ed25519_Big_Crt_Sig = "2B"; // Ed25519 sig appears in current list only. ECDSA_256k1_Big_Sig = "2C"; // ECDSA secp256k1 sig appears in both lists. ECDSA_256k1_Big_Crt_Sig = "2D"; // ECDSA secp256k1 sig appears in current list only. ECDSA_256r1_Big_Sig = "2E"; // ECDSA secp256r1 sig appears in both lists. ECDSA_256r1_Big_Crt_Sig = "2F"; // ECDSA secp256r1 sig appears in current list only. Ed448_Big_Sig = "3A"; // Ed448 signature appears in both lists. Ed448_Big_Crt_Sig = "3B"; // Ed448 signature appears in current list only. }; var IdrDex = new IndexerCodex(); var IndexedSigCodex = class { Ed25519_Sig = "A"; // Ed25519 sig appears same in both lists if any. Ed25519_Crt_Sig = "B"; // Ed25519 sig appears in current list only. ECDSA_256k1_Sig = "C"; // ECDSA secp256k1 sig appears same in both lists if any. ECDSA_256k1_Crt_Sig = "D"; // ECDSA secp256k1 sig appears in current list. ECDSA_256r1_Sig = "E"; // ECDSA secp256r1 sig appears same in both lists if any. ECDSA_256r1_Crt_Sig = "F"; // ECDSA secp256r1 sig appears in current list. Ed448_Sig = "0A"; // Ed448 signature appears in both lists. Ed448_Crt_Sig = "0B"; // Ed448 signature appears in current list only. Ed25519_Big_Sig = "2A"; // Ed25519 sig appears in both lists. Ed25519_Big_Crt_Sig = "2B"; // Ed25519 sig appears in current list only. ECDSA_256k1_Big_Sig = "2C"; // ECDSA secp256k1 sig appears in both lists. ECDSA_256k1_Big_Crt_Sig = "2D"; // ECDSA secp256k1 sig appears in current list only. ECDSA_256r1_Big_Sig = "2E"; // ECDSA secp256r1 sig appears in both lists. ECDSA_256r1_Big_Crt_Sig = "2F"; // ECDSA secp256r1 sig appears in current list only. Ed448_Big_Sig = "3A"; // Ed448 signature appears in both lists. Ed448_Big_Crt_Sig = "3B"; // Ed448 signature appears in current list only. has(prop) { const m = new Map( Array.from(Object.entries(this), (v) => [v[1], v[0]]) ); return m.has(prop); } }; var IdxSigDex = new IndexedSigCodex(); var IndexedCurrentSigCodex = class { Ed25519_Crt_Sig = "B"; // Ed25519 sig appears in current list only. ECDSA_256k1_Crt_Sig = "D"; // ECDSA secp256k1 sig appears in current list only. ECDSA_256r1_Crt_Sig = "F"; // ECDSA secp256r1 sig appears in current list. Ed448_Crt_Sig = "0B"; // Ed448 signature appears in current list only. Ed25519_Big_Crt_Sig = "2B"; // Ed25519 sig appears in current list only. ECDSA_256k1_Big_Crt_Sig = "2D"; // ECDSA secp256k1 sig appears in current list only. ECDSA_256r1_Big_Crt_Sig = "2F"; // ECDSA secp256r1 sig appears in current list only. Ed448_Big_Crt_Sig = "3B"; // Ed448 signature appears in current list only. has(prop) { const m = new Map( Array.from(Object.entries(this), (v) => [v[1], v[0]]) ); return m.has(prop); } }; var IdxCrtSigDex = new IndexedCurrentSigCodex(); var IndexedBothSigCodex = class { Ed25519_Sig = "A"; // Ed25519 sig appears same in both lists if any. ECDSA_256k1_Sig = "C"; // ECDSA secp256k1 sig appears same in both lists if any. Ed448_Sig = "0A"; // Ed448 signature appears in both lists. Ed25519_Big_Sig = "2A"; // Ed25519 sig appears in both listsy. ECDSA_256k1_Big_Sig = "2C"; // ECDSA secp256k1 sig appears in both lists. Ed448_Big_Sig = "3A"; // Ed448 signature appears in both lists. has(prop) { const m = new Map( Array.from(Object.entries(this), (v) => [v[1], v[0]]) ); return m.has(prop); } }; var IdxBthSigDex = new IndexedBothSigCodex(); var Xizage = class { hs; ss; os; fs; ls; constructor(hs, ss, os, fs, ls) { this.hs = hs; this.ss = ss; this.os = os; this.fs = fs; this.ls = ls; } }; var Indexer = class _Indexer { Codex = IdrDex; static Hards = /* @__PURE__ */ new Map([ ["A", 1], ["B", 1], ["C", 1], ["D", 1], ["E", 1], ["F", 1], ["G", 1], ["H", 1], ["I", 1], ["J", 1], ["K", 1], ["L", 1], ["M", 1], ["N", 1], ["O", 1], ["P", 1], ["Q", 1], ["R", 1], ["S", 1], ["T", 1], ["U", 1], ["V", 1], ["W", 1], ["X", 1], ["Y", 1], ["Z", 1], ["a", 1], ["b", 1], ["c", 1], ["d", 1], ["e", 1], ["f", 1], ["g", 1], ["h", 1], ["i", 1], ["j", 1], ["k", 1], ["l", 1], ["m", 1], ["n", 1], ["o", 1], ["p", 1], ["q", 1], ["r", 1], ["s", 1], ["t", 1], ["u", 1], ["v", 1], ["w", 1], ["x", 1], ["y", 1], ["z", 1], ["0", 2], ["1", 2], ["2", 2], ["3", 2], ["4", 2] ]); static Sizes = new Map( Object.entries({ A: new Xizage(1, 1, 0, 88, 0), B: new Xizage(1, 1, 0, 88, 0), C: new Xizage(1, 1, 0, 88, 0), D: new Xizage(1, 1, 0, 88, 0), E: new Xizage(1, 1, 0, 88, 0), F: new Xizage(1, 1, 0, 88, 0), "0A": new Xizage(2, 2, 1, 156, 0), "0B": new Xizage(2, 2, 1, 156, 0), "2A": new Xizage(2, 4, 2, 92, 0), "2B": new Xizage(2, 4, 2, 92, 0), "2C": new Xizage(2, 4, 2, 92, 0), "2D": new Xizage(2, 4, 2, 92, 0), "2E": new Xizage(2, 4, 2, 92, 0), "2F": new Xizage(2, 4, 2, 92, 0), "3A": new Xizage(2, 6, 3, 160, 0), "3B": new Xizage(2, 6, 3, 160, 0), "0z": new Xizage(2, 2, 0, void 0, 0), "1z": new Xizage(2, 2, 1, 76, 1), "4z": new Xizage(2, 6, 3, 80, 1) }) ); _code = ""; _index = -1; _ondex; _raw = new Uint8Array(0); constructor({ raw = void 0, code = IdrDex.Ed25519_Sig, index = 0, ondex = void 0, qb64b = void 0, qb64 = void 0, qb2 = void 0 }) { if (raw != void 0) { if (code == void 0) { throw new EmptyMaterialError( `Improper initialization need either (raw and code) or qb64b or qb64 or qb2.` ); } if (!_Indexer.Sizes.has(code)) { throw new Error(`Unsupported code=${code}.`); } const xizage = _Indexer.Sizes.get(code); const os = xizage.os; const fs = xizage.fs; const cs = xizage.hs + xizage.ss; const ms = xizage.ss - xizage.os; if (!Number.isInteger(index) || index < 0 || index > 64 ** ms - 1) { throw new Error(`Invalid index=${index} for code=${code}.`); } if (ondex != void 0 && xizage.os != 0 && !(ondex >= 0 && ondex <= 64 ** os - 1)) { throw new Error(`Invalid ondex=${ondex} for code=${code}.`); } if (IdxCrtSigDex.has(code) && ondex != void 0) { throw new Error(`Non None ondex=${ondex} for code=${code}.`); } if (IdxBthSigDex.has(code)) { if (ondex == void 0) { ondex = index; } else { if (ondex != index && os == 0) { throw new Error( `Non matching ondex=${ondex} and index=${index} for code=${code}.` ); } } } if (fs == void 0) { throw new Error("variable length unsupported"); } const rawsize = Math.floor((fs - cs) * 3 / 4); raw = raw.slice(0, rawsize); if (raw.length != rawsize) { throw new Error( `Not enougth raw bytes for code=${code} and index=${index} ,expected ${rawsize} got ${raw.length}.` ); } this._code = code; this._index = index; this._ondex = ondex; this._raw = raw; } else if (qb64b != void 0) { const qb642 = d(qb64b); this._exfil(qb642); } else if (qb64 != void 0) { this._exfil(qb64); } else if (qb2 != void 0) { this._bexfil(qb2); } else { throw new EmptyMaterialError( `Improper initialization need either (raw and code and index) or qb64b or qb64 or qb2.` ); } } _bexfil(qb2) { throw new Error(`qb2 not yet supported: ${qb2}`); } static _rawSize(code) { const xizage = _Indexer.Sizes.get(code); return Math.floor(xizage.fs - (xizage.hs + xizage.ss) * 3 / 4); } get code() { return this._code; } get raw() { return this._raw; } get index() { return this._index; } get ondex() { return this._ondex; } get qb64() { return this._infil(); } get qb64b() { return b(this.qb64); } _infil() { const code = this.code; const index = this.index; const ondex = this.ondex; const raw = this.raw; const ps = (3 - raw.length % 3) % 3; const xizage = _Indexer.Sizes.get(code); const cs = xizage.hs + xizage.ss; const ms = xizage.ss - xizage.os; if (index < 0 || index > 64 ** ms - 1) { throw new Error(`Invalid index=${index} for code=${code}.`); } if (ondex != void 0 && xizage.os != 0 && !(ondex >= 0 && ondex <= 64 ** xizage.os - 1)) { throw new Error( `Invalid ondex=${ondex} for os=${xizage.os} and code=${code}.` ); } const both = `${code}${intToB64(index, ms)}${intToB64( ondex == void 0 ? 0 : ondex, xizage.os )}`; if (both.length != cs) { throw new Error( `Mismatch code size = ${cs} with table = ${both.length}.` ); } if (cs % 4 != ps - xizage.ls) { throw new Error( `Invalid code=${both} for converted raw pad size=${ps}.` ); } const bytes = new Uint8Array(ps + raw.length); for (let i = 0; i < ps; i++) { bytes[i] = 0; } for (let i = 0; i < raw.length; i++) { const odx = i + ps; bytes[odx] = raw[i]; } const full = both + encodeBase64Url(import_buffer3.Buffer.from(bytes)).slice(ps - xizage.ls); if (full.length != xizage.fs) { throw new Error(`Invalid code=${both} for raw size=${raw.length}.`); } return full; } _exfil(qb64) { if (qb64.length == 0) { throw new Error("Empty Material"); } const first = qb64[0]; if (!Array.from(_Indexer.Hards.keys()).includes(first)) { throw new Error(`Unexpected code ${first}`); } const hs = _Indexer.Hards.get(first); if (qb64.length < hs) { throw new Error(`Need ${hs - qb64.length} more characters.`); } const hard = qb64.slice(0, hs); if (!Array.from(_Indexer.Sizes.keys()).includes(hard)) { throw new Error(`Unsupported code ${hard}`); } const xizage = _Indexer.Sizes.get(hard); const cs = xizage.hs + xizage.ss; const ms = xizage.ss - xizage.os; if (qb64.length < cs) { throw new Error(`Need ${cs - qb64.length} more characters.`); } const sindex = qb64.slice(hs, hs + ms); const index = b64ToInt(sindex); const sondex = qb64.slice(hs + ms, hs + ms + xizage.os); let ondex; if (IdxCrtSigDex.has(hard)) { ondex = xizage.os != 0 ? b64ToInt(sondex) : void 0; if (ondex != 0 && ondex != void 0) { throw new Error(`Invalid ondex=${ondex} for code=${hard}.`); } else { ondex = void 0; } } else { ondex = xizage.os != 0 ? b64ToInt(sondex) : index; } if (xizage.fs == void 0) { throw new Error("variable length not supported"); } if (qb64.length < xizage.fs) { throw new Error(`Need ${xizage.fs - qb64.length} more chars.`); } qb64 = qb64.slice(0, xizage.fs); const ps = cs % 4; const pbs = 2 * ps != 0 ? ps : xizage.ls; let raw; if (ps != 0) { const base = new Array(ps + 1).join("A") + qb64.slice(cs); const paw = decodeBase64Url(base); const pi = readInt(paw.slice(0, ps)); if (pi & 2 ** pbs - 1) { throw new Error( `Non zeroed prepad bits = {pi & (2 ** pbs - 1 ):<06b} in {qb64b[cs:cs+1]}.` ); } raw = paw.slice(ps); } else { const base = qb64.slice(cs); const paw = decodeBase64Url(base); const li = readInt(paw.slice(0, xizage.ls)); if (li != 0) { if (li == 1) { throw new Error(`Non zeroed lead byte = 0x{li:02x}.`); } else { throw new Error(`Non zeroed lead bytes = 0x{li:04x}`); } } raw = paw.slice(xizage.ls); } if (raw.length != Math.floor((qb64.length - cs) * 3 / 4)) { throw new Error(`Improperly qualified material = ${qb64}`); } this._code = hard; this._index = index; this._ondex = ondex; this._raw = new Uint8Array(raw); } }; // src/keri/core/siger.ts var Siger = class extends Indexer { _verfer; constructor({ raw, code, index, ondex, qb64, qb64b, qb2 }, verfer) { super({ raw, code, index, ondex, qb64, qb64b, qb2 }); if (!IdxSigDex.has(this.code)) { throw new Error(`Invalid code = ${this.code} for Siger.`); } this._verfer = verfer; } get verfer() { return this._verfer; } set verfer(verfer) { this._verfer = verfer; } }; // src/keri/core/signer.ts var import_buffer4 = require("buffer"); var Signer = class extends Matter { _sign; _verfer; constructor({ raw, code = MtrDex.Ed25519_Seed, qb64, qb64b, qb2, transferable = true }) { try { super({ raw, code, qb64, qb64b, qb2 }); } catch (e) { if (e instanceof EmptyMaterialError) { if (code == MtrDex.Ed25519_Seed) { const raw2 = import_libsodium_wrappers_sumo3.default.randombytes_buf( import_libsodium_wrappers_sumo3.default.crypto_sign_SEEDBYTES ); super({ raw: raw2, code, qb64, qb64b, qb2 }); } else { throw new Error(`Unsupported signer code = ${code}.`); } } else { throw e; } } let verfer; if (this.code == MtrDex.Ed25519_Seed) { this._sign = this._ed25519; const keypair = import_libsodium_wrappers_sumo3.default.crypto_sign_seed_keypair(this.raw); verfer = new Verfer({ raw: keypair.publicKey, code: transferable ? MtrDex.Ed25519 : MtrDex.Ed25519N }); } else { throw new Error(`Unsupported signer code = ${this.code}.`); } this._verfer = verfer; } /** * @description Property verfer: Returns Verfer instance Assumes ._verfer is correctly assigned */ get verfer() { return this._verfer; } sign(ser, index = null, only = false, ondex = void 0) { return this._sign(ser, this.raw, this.verfer, index, only, ondex); } _ed25519(ser, seed, verfer, index, only = false, ondex) { const sig = import_libsodium_wrappers_sumo3.default.crypto_sign_detached( ser, import_buffer4.Buffer.concat([seed, verfer.raw]) ); if (index == null) { return new Cigar({ raw: sig, code: MtrDex.Ed25519_Sig }, verfer); } else { let code; if (only) { ondex = void 0; if (index <= 63) { code = IdrDex.Ed25519_Crt_Sig; } else { code = IdrDex.Ed25519_Big_Crt_Sig; } } else { if (ondex == void 0) { ondex = index; } if (ondex == index && index <= 63) code = IdrDex.Ed25519_Sig; else code = IdrDex.Ed25519_Big_Sig; } return new Siger( { raw: sig, code, index, ondex }, verfer ); } } }; // src/keri/core/decrypter.ts var import_libsodium_wrappers_sumo5 = __toESM(require("libsodium-wrappers-sumo"), 1); // src/keri/core/salter.ts var import_libsodium_wrappers_sumo4 = __toESM(require("libsodium-wrappers-sumo"), 1); var Tier = /* @__PURE__ */ ((Tier3) => { Tier3["low"] = "low"; Tier3["med"] = "med"; Tier3["high"] = "high"; return Tier3; })(Tier || {}); var Salter = class extends Matter { _tier; constructor({ raw, code = MtrDex.Salt_128, tier = "low" /* low */, qb64, qb64b, qb2 }) { try { super({ raw, code, qb64, qb64b, qb2 }); } catch (e) { if (e instanceof EmptyMaterialError) { if (code == MtrDex.Salt_128) { const salt = import_libsodium_wrappers_sumo4.default.randombytes_buf( import_libsodium_wrappers_sumo4.default.crypto_pwhash_SALTBYTES ); super({ raw: salt, code }); } else { throw new Error( "invalid code for Salter, only Salt_128 accepted" ); } } else { throw e; } } if (this.code != MtrDex.Salt_128) { throw new Error("invalid code for Salter, only Salt_128 accepted"); } this._tier = tier !== null ? tier : "low" /* low */; } stretch(size = 32, path = "", tier = null, temp = false) { tier = tier == null ? this.tier : tier; let opslimit, memlimit; if (temp) { opslimit = 1; memlimit = 8192; } else { switch (tier) { case "low" /* low */: opslimit = 2; memlimit = 67108864; break; case "med" /* med */: opslimit = 3; memlimit = 268435456; break; case "high" /* high */: opslimit = 4; memlimit = 1073741824; break; default: throw new Error(`Unsupported security tier = ${tier}.`); } } return import_libsodium_wrappers_sumo4.default.crypto_pwhash( size, path, this.raw, opslimit, memlimit, import_libsodium_wrappers_sumo4.default.crypto_pwhash_ALG_ARGON2ID13 ); } signer(code = MtrDex.Ed25519_Seed, transferable = true, path = "", tier = null, temp = false) { const seed = this.stretch(Matter._rawSize