signify-ts
Version:
Signing at the edge for KERI, ACDC, and KERIA
4 lines • 464 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../src/index.ts", "../src/exports.ts", "../src/ready.ts", "../src/keri/core/encrypter.ts", "../src/keri/core/kering.ts", "../src/keri/core/core.ts", "../src/keri/core/matter.ts", "../src/keri/core/base64.ts", "../src/keri/core/verfer.ts", "../src/keri/core/signer.ts", "../src/keri/core/cigar.ts", "../src/keri/core/indexer.ts", "../src/keri/core/siger.ts", "../src/keri/core/decrypter.ts", "../src/keri/core/salter.ts", "../src/keri/core/cipher.ts", "../src/keri/core/counter.ts", "../src/keri/core/seqner.ts", "../src/keri/core/diger.ts", "../src/keri/core/number.ts", "../src/keri/core/serder.ts", "../src/keri/core/prefixer.ts", "../src/keri/core/saider.ts", "../src/keri/core/utils.ts", "../src/keri/core/manager.ts", "../src/keri/core/tholder.ts", "../src/keri/core/eventing.ts", "../src/keri/app/habery.ts", "../src/keri/app/controller.ts", "../src/keri/core/httping.ts", "../src/keri/app/aiding.ts", "../src/keri/end/ending.ts", "../src/keri/core/authing.ts", "../src/keri/core/keeping.ts", "../src/keri/app/contacting.ts", "../src/keri/app/coring.ts", "../src/keri/core/vdring.ts", "../src/keri/app/credentialing.ts", "../src/keri/app/delegating.ts", "../src/keri/app/escrowing.ts", "../src/keri/core/bexter.ts", "../src/keri/core/pather.ts", "../src/keri/app/exchanging.ts", "../src/keri/app/grouping.ts", "../src/keri/app/notifying.ts", "../src/keri/app/clienting.ts"],
"sourcesContent": ["import * as exp from './exports';\nexport * from './exports';\nexport default exp;\n", "export * from './ready';\n\nexport * from './keri/app/habery';\nexport * from './keri/app/controller';\n\nexport * from './keri/app/aiding';\nexport * from './keri/app/clienting';\nexport * from './keri/app/contacting';\nexport * from './keri/app/coring';\nexport * from './keri/app/credentialing';\nexport * from './keri/app/escrowing';\nexport * from './keri/app/exchanging';\nexport * from './keri/app/grouping';\nexport * from './keri/app/notifying';\n\nexport * from './keri/core/authing';\nexport * from './keri/core/cigar';\nexport * from './keri/core/cipher';\nexport * from './keri/core/core';\nexport * from './keri/core/counter';\nexport * from './keri/core/decrypter';\nexport * from './keri/core/diger';\nexport * from './keri/core/encrypter';\nexport * from './keri/core/eventing';\nexport * from './keri/core/httping';\nexport * from './keri/core/indexer';\nexport * from './keri/core/keeping';\nexport * from './keri/core/kering';\nexport * from './keri/core/manager';\nexport * from './keri/core/matter';\nexport * from './keri/core/number';\nexport * from './keri/core/prefixer';\nexport * from './keri/core/saider';\nexport * from './keri/core/salter';\nexport * from './keri/core/seqner';\nexport * from './keri/core/serder';\nexport * from './keri/core/siger';\nexport * from './keri/core/signer';\nexport * from './keri/core/tholder';\nexport * from './keri/core/utils';\nexport * from './keri/core/verfer';\nexport * from './keri/core/state';\n\nexport * from './keri/end/ending';\n", "import _sodium from 'libsodium-wrappers-sumo';\n\nexport const ready: () => Promise<void> = async () => {\n await _sodium.ready;\n};\n", "import libsodium from 'libsodium-wrappers-sumo';\n\nimport { Matter, MatterArgs, MtrDex } from './matter';\nimport { Verfer } from './verfer';\nimport { Signer } from './signer';\nimport { Cipher } from './cipher';\nimport { arrayEquals } from './utils';\n\nexport class Encrypter extends Matter {\n private _encrypt: any;\n constructor(\n { raw, code = MtrDex.X25519, qb64, qb64b, qb2 }: MatterArgs,\n verkey: Uint8Array | null = null\n ) {\n if (raw == undefined && verkey != null) {\n const verfer = new Verfer({ qb64b: verkey });\n if (\n !Array.from([MtrDex.Ed25519N, MtrDex.Ed25519]).includes(\n verfer.code\n )\n ) {\n throw new Error(\n `Unsupported verkey derivation code = ${verfer.code}.`\n );\n }\n raw = libsodium.crypto_sign_ed25519_pk_to_curve25519(verfer.raw);\n }\n\n super({ raw, code, qb64, qb64b, qb2 });\n\n if (this.code == MtrDex.X25519) {\n this._encrypt = this._x25519;\n } else {\n throw new Error(`Unsupported encrypter code = ${this.code}.`);\n }\n }\n\n verifySeed(seed: Uint8Array) {\n const signer = new Signer({ qb64b: seed });\n const keypair = libsodium.crypto_sign_seed_keypair(signer.raw);\n const pubkey = libsodium.crypto_sign_ed25519_pk_to_curve25519(\n keypair.publicKey\n );\n return arrayEquals(pubkey, this.raw);\n }\n\n encrypt(ser: Uint8Array | null = null, matter: Matter | null = null) {\n if (ser == null && matter == null) {\n throw new Error('Neither ser nor matter are provided.');\n }\n\n if (ser != null) {\n matter = new Matter({ qb64b: ser });\n }\n\n let code;\n if (matter!.code == MtrDex.Salt_128) {\n code = MtrDex.X25519_Cipher_Salt;\n } else {\n code = MtrDex.X25519_Cipher_Seed;\n }\n\n return this._encrypt(matter!.qb64, this.raw, code);\n }\n\n _x25519(ser: Uint8Array, pubkey: Uint8Array, code: string) {\n const raw = libsodium.crypto_box_seal(ser, pubkey);\n return new Cipher({ raw: raw, code: code });\n }\n}\n", "export class EmptyMaterialError {\n private readonly _err: Error;\n constructor(err: string) {\n this._err = new Error(err);\n }\n\n get err() {\n return this._err;\n }\n}\n", "export enum Serials {\n JSON = 'JSON',\n}\n\nexport enum Ident {\n KERI = 'KERI',\n ACDC = 'ACDC',\n}\n\nexport class Version {\n public major: number;\n public minor: number;\n\n constructor(major: number = 1, minor: number = 0) {\n this.major = major;\n this.minor = minor;\n }\n}\n\nexport const Versionage = new Version();\n\nexport const Ilks = {\n icp: 'icp',\n rot: 'rot',\n ixn: 'ixn',\n dip: 'dip',\n drt: 'drt',\n rct: 'rct',\n vrc: 'vrc',\n rpy: 'rpy',\n exn: 'exn',\n vcp: 'vcp',\n iss: 'iss',\n rev: 'rev',\n bis: 'bis',\n brv: 'brv',\n};\n\nexport const IcpLabels = [\n 'v',\n 'i',\n 's',\n 't',\n 'kt',\n 'k',\n 'n',\n 'bt',\n 'b',\n 'c',\n 'a',\n];\n\nexport const DipLabels = [\n 'v',\n 'i',\n 's',\n 't',\n 'kt',\n 'k',\n 'n',\n 'bt',\n 'b',\n 'c',\n 'a',\n 'di',\n];\n\nexport const RotLabels = [\n 'v',\n 'i',\n 's',\n 't',\n 'p',\n 'kt',\n 'k',\n 'n',\n 'bt',\n 'br',\n 'ba',\n 'a',\n];\nexport const DrtLabels = [\n 'v',\n 'i',\n 's',\n 't',\n 'p',\n 'kt',\n 'k',\n 'n',\n 'bt',\n 'br',\n 'ba',\n 'a',\n];\nexport const IxnLabels = ['v', 'i', 's', 't', 'p', 'a'];\n\nexport const KsnLabels = [\n 'v',\n 'i',\n 's',\n 't',\n 'p',\n 'd',\n 'f',\n 'dt',\n 'et',\n 'kt',\n 'k',\n 'n',\n 'bt',\n 'b',\n 'c',\n 'ee',\n 'di',\n 'r',\n];\n\nexport const RpyLabels = ['v', 't', 'd', 'dt', 'r', 'a'];\n\nconst encoder = new TextEncoder();\nconst decoder = new TextDecoder();\n\nexport const VERFULLSIZE = 17;\nexport const MINSNIFFSIZE = 12 + VERFULLSIZE;\nexport const MINSIGSIZE = 4;\n\n// const version_pattern = 'KERI(?P<major>[0-9a-f])(?P<minor>[0-9a-f])\n// (?P<kind>[A-Z]{4})(?P<size>[0-9a-f]{6})'\n// const version_pattern1 = `KERI\\(\\?P<major>\\[0\\-9a\\-f\\]\\)\\(\\?P<minor>\\[0\\-9a\\-f\\]\\)\\\n// (\\?P<kind>\\[A\\-Z\\]\\{4\\}\\)\\(\\?P<size>\\[0\\-9a\\-f\\]\\{6\\}\\)_`\n\nexport const VEREX = '(KERI|ACDC)([0-9a-f])([0-9a-f])([A-Z]{4})([0-9a-f]{6})_';\n\nexport interface Dict<TValue> {\n [id: string]: TValue;\n}\n\n// Regex pattern matching\n\n/**\n * @description This function is use to deversify the version\n * Here we will use regex to to validate and extract serialization kind,size and version\n * @param {string} versionString version string\n * @return {Object} contaning prototol (KERI or ACDC), kind of serialization like cbor,json,mgpk\n * version = version of object ,size = raw size integer\n */\nexport function deversify(\n versionString: string\n): [Ident, Serials, Version, string] {\n let kind;\n let size;\n let proto;\n const version = Versionage;\n\n // we need to identify how to match the buffers pattern ,like we do regex matching for strings\n const re = new RegExp(VEREX);\n\n const match = re.exec(versionString);\n\n if (match) {\n [proto, version.major, version.minor, kind, size] = [\n match[1],\n +match[2],\n +match[3],\n match[4],\n match[5],\n ];\n if (!Object.values(Serials).includes(kind as Serials)) {\n throw new Error(`Invalid serialization kind = ${kind}`);\n }\n if (!Object.values(Ident).includes(proto as Ident)) {\n throw new Error(`Invalid serialization kind = ${kind}`);\n }\n\n const ta = kind as keyof typeof Serials;\n kind = Serials[ta];\n const pa = proto as keyof typeof Ident;\n proto = Ident[pa];\n\n return [proto, kind, version, size];\n }\n throw new Error(`Invalid version string = ${versionString}`);\n}\n\nexport function versify(\n ident: Ident = Ident.KERI,\n version?: Version,\n kind: Serials = Serials.JSON,\n size: number = 0\n) {\n version = version == undefined ? Versionage : version;\n\n return `${ident}${version.major.toString(\n 16\n )}${version.minor.toString()}${kind}${size.toString(16).padStart(6, '0')}_`;\n}\n\nexport const B64ChrByIdx = new Map<number, string>([\n [0, 'A'],\n [1, 'B'],\n [2, 'C'],\n [3, 'D'],\n [4, 'E'],\n [5, 'F'],\n [6, 'G'],\n [7, 'H'],\n [8, 'I'],\n [9, 'J'],\n [10, 'K'],\n [11, 'L'],\n [12, 'M'],\n [13, 'N'],\n [14, 'O'],\n [15, 'P'],\n [16, 'Q'],\n [17, 'R'],\n [18, 'S'],\n [19, 'T'],\n [20, 'U'],\n [21, 'V'],\n [22, 'W'],\n [23, 'X'],\n [24, 'Y'],\n [25, 'Z'],\n [26, 'a'],\n [27, 'b'],\n [28, 'c'],\n [29, 'd'],\n [30, 'e'],\n [31, 'f'],\n [32, 'g'],\n [33, 'h'],\n [34, 'i'],\n [35, 'j'],\n [36, 'k'],\n [37, 'l'],\n [38, 'm'],\n [39, 'n'],\n [40, 'o'],\n [41, 'p'],\n [42, 'q'],\n [43, 'r'],\n [44, 's'],\n [45, 't'],\n [46, 'u'],\n [47, 'v'],\n [48, 'w'],\n [49, 'x'],\n [50, 'y'],\n [51, 'z'],\n [52, '0'],\n [53, '1'],\n [54, '2'],\n [55, '3'],\n [56, '4'],\n [57, '5'],\n [58, '6'],\n [59, '7'],\n [60, '8'],\n [61, '9'],\n [62, '-'],\n [63, '_'],\n]);\n\nexport const B64IdxByChr = new Map<string, number>(\n Array.from(B64ChrByIdx, (entry) => [entry[1], entry[0]])\n);\n\nexport function intToB64(i: number, l = 1): string {\n let out = '';\n while (l != 0) {\n out = B64ChrByIdx.get(i % 64) + out;\n i = Math.floor(i / 64);\n if (i == 0) {\n break;\n }\n }\n\n const x = l - out.length;\n for (let i = 0; i < x; i++) {\n out = 'A' + out;\n }\n\n return out;\n}\n\nexport function intToB64b(n: number, l: number = 1): Uint8Array {\n const s = intToB64(n, l);\n return b(s);\n}\n\nexport function b64ToInt(s: string): number {\n if (s.length == 0) {\n throw new Error('Empty string, conversion undefined.');\n }\n\n let i = 0;\n const rev = s.split('').reverse();\n rev.forEach((c: string, e: number) => {\n i |= B64IdxByChr.get(c)! << (e * 6);\n });\n\n return i;\n}\n\nexport function b(s?: string): Uint8Array {\n return encoder.encode(s);\n}\n\nexport function d(u?: Uint8Array): string {\n return decoder.decode(u);\n}\n\nexport function concat(one: Uint8Array, two: Uint8Array): Uint8Array {\n const out = new Uint8Array(one.length + two.length);\n out.set(one);\n out.set(two, one.length);\n return out;\n}\n\nexport function readInt(array: Uint8Array) {\n let value = 0;\n for (let i = 0; i < array.length; i++) {\n value = value * 256 + array[i];\n }\n return value;\n}\n", "import { EmptyMaterialError } from './kering';\n\nimport { intToB64, readInt } from './core';\nimport { b, d } from './core';\nimport { Buffer } from 'buffer';\nimport { decodeBase64Url, encodeBase64Url } from './base64';\n\nexport class Codex {\n has(prop: string): boolean {\n const m = new Map(\n Array.from(Object.entries(this), (v) => [v[1], v[0]])\n );\n return m.has(prop);\n }\n}\n\nexport class MatterCodex extends Codex {\n Ed25519_Seed: string = 'A'; // Ed25519 256 bit random seed for private key\n Ed25519N: string = 'B'; // Ed25519 verification key non-transferable, basic derivation.\n X25519: string = 'C'; // X25519 public encryption key, converted from Ed25519 or Ed25519N.\n Ed25519: string = 'D'; // Ed25519 verification key basic derivation\n Blake3_256: string = 'E'; // Blake3 256 bit digest self-addressing derivation.\n SHA3_256: string = 'H'; // SHA3 256 bit digest self-addressing derivation.\n SHA2_256: string = 'I'; // SHA2 256 bit digest self-addressing derivation.\n ECDSA_256k1_Seed: string = 'J'; // ECDSA secp256k1 256 bit random Seed for private key\n X25519_Private: string = 'O'; // X25519 private decryption key converted from Ed25519\n X25519_Cipher_Seed: string = 'P'; // X25519 124 char b64 Cipher of 44 char qb64 Seed\n ECDSA_256r1_Seed: string = 'Q'; // ECDSA secp256r1 256 bit random Seed for private key\n Salt_128: string = '0A'; // 128 bit random salt or 128 bit number (see Huge)\n Ed25519_Sig: string = '0B'; // Ed25519 signature.\n ECDSA_256k1_Sig: string = '0C'; // ECDSA secp256k1 signature.\n ECDSA_256r1_Sig: string = '0I'; // ECDSA secp256r1 signature.\n StrB64_L0: string = '4A'; // String Base64 Only Lead Size 0\n StrB64_L1: string = '5A'; // String Base64 Only Lead Size 1\n StrB64_L2: string = '6A'; // String Base64 Only Lead Size 2\n ECDSA_256k1N: string = '1AAA'; // ECDSA secp256k1 verification key non-transferable, basic derivation.\n ECDSA_256k1: string = '1AAB'; // ECDSA public verification or encryption key, basic derivation\n X25519_Cipher_Salt: string = '1AAH'; // X25519 100 char b64 Cipher of 24 char qb64 Salt\n ECDSA_256r1N: string = '1AAI'; // ECDSA secp256r1 verification key non-transferable, basic derivation.\n ECDSA_256r1: string = '1AAJ'; // ECDSA secp256r1 verification or encryption key, basic derivation\n StrB64_Big_L0: string = '7AAA'; // String Base64 Only Big Lead Size 0\n StrB64_Big_L1: string = '8AAA'; // String Base64 Only Big Lead Size 1\n StrB64_Big_L2: string = '9AAA'; // String Base64 Only Big Lead Size 2\n}\n\nexport const MtrDex = new MatterCodex();\n\nexport class NonTransCodex extends Codex {\n Ed25519N: string = 'B'; // Ed25519 verification key non-transferable, basic derivation.\n ECDSA_256k1N: string = '1AAA'; // ECDSA secp256k1 verification key non-transferable, basic derivation.\n Ed448N: string = '1AAC'; // Ed448 non-transferable prefix public signing verification key. Basic derivation.\n ECDSA_256r1N: string = '1AAI'; // ECDSA secp256r1 verification key non-transferable, basic derivation.\n}\n\nexport const NonTransDex = new NonTransCodex();\n\nexport class DigiCodex extends Codex {\n Blake3_256: string = 'E'; // Blake3 256 bit digest self-addressing derivation.\n Blake2b_256: string = 'F'; // Blake2b 256 bit digest self-addressing derivation.\n Blake2s_256: string = 'G'; // Blake2s 256 bit digest self-addressing derivation.\n SHA3_256: string = 'H'; // SHA3 256 bit digest self-addressing derivation.\n SHA2_256: string = 'I'; // SHA2 256 bit digest self-addressing derivation.\n Blake3_512: string = '0D'; // Blake3 512 bit digest self-addressing derivation.\n Blake2b_512: string = '0E'; // Blake2b 512 bit digest self-addressing derivation.\n SHA3_512: string = '0F'; // SHA3 512 bit digest self-addressing derivation.\n SHA2_512: string = '0G'; // SHA2 512 bit digest self-addressing derivation.\n}\n\nexport const DigiDex = new DigiCodex();\n\nexport class NumCodex extends Codex {\n Short: string = 'M'; // Short 2 byte b2 number\n Long: string = '0H'; // Long 4 byte b2 number\n Big: string = 'N'; // Big 8 byte b2 number\n Huge: string = '0A'; // Huge 16 byte b2 number (same as Salt_128)\n}\n\nexport const NumDex = new NumCodex();\n\nexport class BexCodex extends Codex {\n StrB64_L0: string = '4A'; // String Base64 Only Leader Size 0\n StrB64_L1: string = '5A'; // String Base64 Only Leader Size 1\n StrB64_L2: string = '6A'; // String Base64 Only Leader Size 2\n StrB64_Big_L0: string = '7AAA'; // String Base64 Only Big Leader Size 0\n StrB64_Big_L1: string = '8AAA'; // String Base64 Only Big Leader Size 1\n StrB64_Big_L2: string = '9AAA'; // String Base64 Only Big Leader Size 2\n}\n\nexport const BexDex = new BexCodex();\n\nclass SmallVarRawSizeCodex extends Codex {\n Lead0: string = '4'; // First Selector Character for all ls == 0 codes\n Lead1: string = '5'; // First Selector Character for all ls == 1 codes\n Lead2: string = '6'; // First Selector Character for all ls == 2 codes\n}\n\nexport const SmallVrzDex = new SmallVarRawSizeCodex();\n\nclass LargeVarRawSizeCodex extends Codex {\n Lead0_Big: string = '7'; // First Selector Character for all ls == 0 codes\n Lead1_Big: string = '8'; // First Selector Character for all ls == 1 codes\n Lead2_Big: string = '9'; // First Selector Character for all ls == 2 codes\n}\n\nexport const LargeVrzDex = new LargeVarRawSizeCodex();\n\nexport class Sizage {\n public hs: number;\n public ss: number;\n public ls?: number;\n public fs?: number;\n\n constructor(hs: number, ss: number, fs?: number, ls?: number) {\n this.hs = hs;\n this.ss = ss;\n this.fs = fs;\n this.ls = ls!;\n }\n}\n\nexport interface MatterArgs {\n raw?: Uint8Array | undefined;\n code?: string;\n qb64b?: Uint8Array | undefined;\n qb64?: string;\n qb2?: Uint8Array | undefined;\n rize?: number;\n}\n\nexport class Matter {\n static Sizes = new Map(\n Object.entries({\n A: new Sizage(1, 0, 44, 0),\n B: new Sizage(1, 0, 44, 0),\n C: new Sizage(1, 0, 44, 0),\n D: new Sizage(1, 0, 44, 0),\n E: new Sizage(1, 0, 44, 0),\n F: new Sizage(1, 0, 44, 0),\n G: new Sizage(1, 0, 44, 0),\n H: new Sizage(1, 0, 44, 0),\n I: new Sizage(1, 0, 44, 0),\n J: new Sizage(1, 0, 44, 0),\n K: new Sizage(1, 0, 76, 0),\n L: new Sizage(1, 0, 76, 0),\n M: new Sizage(1, 0, 4, 0),\n N: new Sizage(1, 0, 12, 0),\n O: new Sizage(1, 0, 44, 0),\n P: new Sizage(1, 0, 124, 0),\n Q: new Sizage(1, 0, 44, 0),\n '0A': new Sizage(2, 0, 24, 0),\n '0B': new Sizage(2, 0, 88, 0),\n '0C': new Sizage(2, 0, 88, 0),\n '0D': new Sizage(2, 0, 88, 0),\n '0E': new Sizage(2, 0, 88, 0),\n '0F': new Sizage(2, 0, 88, 0),\n '0G': new Sizage(2, 0, 88, 0),\n '0H': new Sizage(2, 0, 8, 0),\n '0I': new Sizage(2, 0, 88, 0),\n '1AAA': new Sizage(4, 0, 48, 0),\n '1AAB': new Sizage(4, 0, 48, 0),\n '1AAC': new Sizage(4, 0, 80, 0),\n '1AAD': new Sizage(4, 0, 80, 0),\n '1AAE': new Sizage(4, 0, 56, 0),\n '1AAF': new Sizage(4, 0, 8, 0),\n '1AAG': new Sizage(4, 0, 36, 0),\n '1AAH': new Sizage(4, 0, 100, 0),\n '1AAI': new Sizage(4, 0, 48, 0),\n '1AAJ': new Sizage(4, 0, 48, 0),\n '2AAA': new Sizage(4, 0, 8, 1),\n '3AAA': new Sizage(4, 0, 8, 2),\n '4A': new Sizage(2, 2, undefined, 0),\n '5A': new Sizage(2, 2, undefined, 1),\n '6A': new Sizage(2, 2, undefined, 2),\n '7AAA': new Sizage(4, 4, undefined, 0),\n '8AAA': new Sizage(4, 4, undefined, 1),\n '9AAA': new Sizage(4, 4, undefined, 2),\n '4B': new Sizage(2, 2, undefined, 0),\n '5B': new Sizage(2, 2, undefined, 1),\n '6B': new Sizage(2, 2, undefined, 2),\n '7AAB': new Sizage(4, 4, undefined, 0),\n '8AAB': new Sizage(4, 4, undefined, 1),\n '9AAB': new Sizage(4, 4, undefined, 2),\n })\n );\n\n static Hards = new Map<string, number>([\n ['A', 1],\n ['B', 1],\n ['C', 1],\n ['D', 1],\n ['E', 1],\n ['F', 1],\n ['G', 1],\n ['H', 1],\n ['I', 1],\n ['J', 1],\n ['K', 1],\n ['L', 1],\n ['M', 1],\n ['N', 1],\n ['O', 1],\n ['P', 1],\n ['Q', 1],\n ['R', 1],\n ['S', 1],\n ['T', 1],\n ['U', 1],\n ['V', 1],\n ['W', 1],\n ['X', 1],\n ['Y', 1],\n ['Z', 1],\n ['a', 1],\n ['b', 1],\n ['c', 1],\n ['d', 1],\n ['e', 1],\n ['f', 1],\n ['g', 1],\n ['h', 1],\n ['i', 1],\n ['j', 1],\n ['k', 1],\n ['l', 1],\n ['m', 1],\n ['n', 1],\n ['o', 1],\n ['p', 1],\n ['q', 1],\n ['r', 1],\n ['s', 1],\n ['t', 1],\n ['u', 1],\n ['v', 1],\n ['w', 1],\n ['x', 1],\n ['y', 1],\n ['z', 1],\n ['0', 2],\n ['1', 4],\n ['2', 4],\n ['3', 4],\n ['4', 2],\n ['5', 2],\n ['6', 2],\n ['7', 4],\n ['8', 4],\n ['9', 4],\n ]);\n\n private _code: string = '';\n private _size: number = -1;\n private _raw: Uint8Array = new Uint8Array(0);\n\n constructor({\n raw,\n code = MtrDex.Ed25519N,\n qb64b,\n qb64,\n qb2,\n rize,\n }: MatterArgs) {\n let size = -1;\n if (raw != undefined) {\n if (code.length == 0) {\n throw new Error(\n 'Improper initialization need either (raw and code) or qb64b or qb64 or qb2.'\n );\n }\n\n if (SmallVrzDex.has(code[0]) || LargeVrzDex.has(code[0])) {\n if (rize !== undefined) {\n if (rize < 0)\n throw new Error(\n `missing var raw size for code=${code}`\n );\n } else {\n rize = raw.length;\n }\n\n const ls = (3 - (rize % 3)) % 3; // calc actual lead (pad) size\n size = Math.floor((rize + ls) / 3); // calculate value of size in triplets\n if (SmallVrzDex.has(code[0])) {\n if (size <= 64 ** 2 - 1) {\n const hs = 2;\n const s = Object.values(SmallVrzDex)[ls];\n code = `${s}${code.substring(1, hs)}`;\n } else if (size <= 64 ** 4 - 1) {\n const hs = 4;\n const s = Object.values(LargeVrzDex)[ls];\n code = `${s}${'AAAA'.substring(0, hs - 2)}${code[1]}`;\n } else {\n throw new Error(\n `Unsupported raw size for code=${code}`\n );\n }\n } else {\n if (size <= 64 ** 4 - 1) {\n const hs = 4;\n const s = Object.values(LargeVrzDex)[ls];\n code = `${s}${code.substring(1, hs)}`;\n } else {\n throw new Error(\n `Unsupported raw size for code=${code}`\n );\n }\n }\n } else {\n const sizage = Matter.Sizes.get(code);\n if (sizage!.fs == -1) {\n // invalid\n throw new Error(`Unsupported variable size code=${code}`);\n }\n\n rize = Matter._rawSize(code);\n }\n raw = raw.slice(0, rize); // copy only exact size from raw stream\n if (raw.length != rize) {\n // forbids shorter\n throw new Error(\n `Not enougth raw bytes for code=${code} expected ${rize} got ${raw.length}.`\n );\n }\n\n this._code = code; // hard value part of code\n this._size = size; // soft value part of code in int\n this._raw = raw; // crypto ops require bytes not bytearray\n } else if (qb64 !== undefined) {\n this._exfil(qb64);\n } else if (qb64b !== undefined) {\n const qb64 = d(qb64b);\n this._exfil(qb64);\n } else if (qb2 !== undefined) {\n this._bexfil(qb2);\n } else {\n throw new EmptyMaterialError('EmptyMaterialError');\n }\n }\n\n get code(): string {\n return this._code;\n }\n\n get size() {\n return this._size;\n }\n\n get raw(): Uint8Array {\n return this._raw;\n }\n\n get qb64() {\n return this._infil();\n }\n\n get qb64b() {\n return b(this.qb64);\n }\n\n get transferable(): boolean {\n return !NonTransDex.has(this.code);\n }\n\n get digestive(): boolean {\n return DigiDex.has(this.code);\n }\n\n static _rawSize(code: string) {\n const sizage = this.Sizes.get(code); // get sizes\n const cs = sizage!.hs + sizage!.ss; // both hard + soft code size\n if (sizage!.fs === -1) {\n throw Error(`Non-fixed raw size code ${code}.`);\n }\n\n return Math.floor(((sizage!.fs! - cs) * 3) / 4) - sizage!.ls!;\n }\n\n static _leadSize(code: string) {\n const sizage = this.Sizes.get(code);\n return sizage!.ls;\n }\n\n get both() {\n const sizage = Matter.Sizes.get(this.code);\n return `${this.code}${intToB64(this.size, sizage!.ss)}`;\n }\n\n private _infil() {\n const code = this.code;\n const size = this.size;\n const raw = this.raw;\n\n const ps = (3 - (raw.length % 3)) % 3; // pad size chars or lead size bytes\n const sizage = Matter.Sizes.get(code);\n\n if (sizage!.fs === undefined) {\n // Variable size code, NOT SUPPORTED\n const cs = sizage!.hs + sizage!.ss;\n if (cs % 4) {\n throw new Error(\n `Whole code size not multiple of 4 for variable length material. cs=${cs}`\n );\n }\n if (size < 0 || size > 64 ** sizage!.ss - 1) {\n throw new Error(`Invalid size=${size} for code=${code}.`);\n }\n\n const both = `${code}${intToB64(size, sizage!.ss)}`;\n if (both.length % 4 !== ps - sizage!.ls!) {\n throw new Error(\n `Invalid code=${both} for converted raw pad size=${ps}.`\n );\n }\n\n const bytes = new Uint8Array(sizage!.ls! + raw.length);\n for (let i = 0; i < sizage!.ls!; i++) {\n bytes[i] = 0;\n }\n for (let i = 0; i < raw.length; i++) {\n const odx = i + ps;\n bytes[odx] = raw[i];\n }\n\n return both + encodeBase64Url(Buffer.from(bytes));\n } else {\n const both = code;\n const cs = both.length;\n if (cs % 4 != ps - sizage!.ls!) {\n // adjusted pad given lead bytes\n throw new Error(\n `Invalid code=${both} for converted raw pad size=${ps}, ${raw.length}.`\n );\n }\n // prepad, convert, and replace upfront\n // when fixed and ls != 0 then cs % 4 is zero and ps==ls\n // otherwise fixed and ls == 0 then cs % 4 == ps\n const bytes = new Uint8Array(ps + raw.length);\n for (let i = 0; i < ps; i++) {\n bytes[i] = 0;\n }\n for (let i = 0; i < raw.length; i++) {\n const odx = i + ps;\n bytes[odx] = raw[i];\n }\n\n return both + encodeBase64Url(Buffer.from(bytes)).slice(cs % 4);\n }\n }\n\n private _exfil(qb64: string) {\n if (qb64.length == 0) {\n throw new Error('Empty Material');\n }\n\n const first = qb64[0];\n if (!Array.from(Matter.Hards.keys()).includes(first)) {\n throw new Error(`Unexpected code ${first}`);\n }\n\n const hs = Matter.Hards.get(first);\n if (qb64.length < hs!) {\n throw new Error(`Shortage Error`);\n }\n\n const hard = qb64.slice(0, hs);\n if (!Array.from(Matter.Sizes.keys()).includes(hard)) {\n throw new Error(`Unsupported code ${hard}`);\n }\n\n const sizage = Matter.Sizes.get(hard);\n const cs = sizage!.hs + sizage!.ss;\n let size = -1;\n if (sizage!.fs == -1) {\n // Variable size code, Not supported\n throw new Error('Variable size codes not supported yet');\n } else {\n size = sizage!.fs!;\n }\n\n if (qb64.length < sizage!.fs!) {\n throw new Error(`Need ${sizage!.fs! - qb64.length} more chars.`);\n }\n\n qb64 = qb64.slice(0, sizage!.fs);\n const ps = cs % 4;\n const pbs = 2 * (ps == 0 ? sizage!.ls! : ps);\n let raw;\n if (ps != 0) {\n const base = new Array(ps + 1).join('A') + qb64.slice(cs);\n const paw = decodeBase64Url(base); // decode base to leave prepadded raw\n const pi = readInt(paw.subarray(0, ps)); // prepad as int\n if (pi & (2 ** pbs - 1)) {\n // masked pad bits non-zero\n throw new Error(\n `Non zeroed prepad bits = {pi & (2 ** pbs - 1 ):<06b} in {qb64b[cs:cs+1]}.`\n );\n }\n raw = paw.subarray(ps); // strip off ps prepad paw bytes\n } else {\n const base = qb64.slice(cs);\n const paw = decodeBase64Url(base);\n const li = readInt(paw.subarray(0, sizage!.ls));\n if (li != 0) {\n if (li == 1) {\n throw new Error(`Non zeroed lead byte = 0x{li:02x}.`);\n } else {\n throw new Error(`Non zeroed lead bytes = 0x{li:04x}`);\n }\n }\n raw = paw.subarray(sizage!.ls);\n }\n\n this._code = hard; // hard only\n this._size = size;\n this._raw = Uint8Array.from(raw); // ensure bytes so immutable and for crypto ops\n }\n\n private _bexfil(qb2: Uint8Array) {\n throw new Error(`qb2 not yet supported: ${qb2}`);\n }\n}\n", "import { Buffer } from 'buffer';\n// base64url is supported by node Buffer, but not in buffer package for browser compatibility\n// https://github.com/feross/buffer/issues/309\n\n// Instead of using a node.js-only module and forcing us to polyfill the Buffer global,\n// we insert code from https://gitlab.com/seangenabe/safe-base64 here\n\nexport function encodeBase64Url(buffer: Buffer) {\n if (!Buffer.isBuffer(buffer)) {\n throw new TypeError('`buffer` must be a buffer.');\n }\n return buffer\n .toString('base64')\n .replace(/\\+/g, '-')\n .replace(/\\//g, '_')\n .replace(/=+/, '');\n}\n\nexport function decodeBase64Url(input: string) {\n if (!(typeof input === 'string')) {\n throw new TypeError('`input` must be a string.');\n }\n\n const n = input.length % 4;\n const padded = input + '='.repeat(n > 0 ? 4 - n : n);\n const base64String = padded.replace(/-/g, '+').replace(/_/g, '/');\n return Buffer.from(base64String, 'base64');\n}\n", "export {};\nimport libsodium from 'libsodium-wrappers-sumo';\nimport { Matter, MatterArgs, MtrDex } from './matter';\nimport secp256r1 from 'ecdsa-secp256r1';\n\n/**\n * @description Verfer :sublclass of Matter,helps to verify signature of serialization\n * using .raw as verifier key and .code as signature cypher suite\n */\nexport class Verfer extends Matter {\n private readonly _verify: (sig: any, ser: any, key: any) => boolean;\n constructor({ raw, code, qb64, qb64b, qb2 }: MatterArgs) {\n super({ raw, code, qb64, qb64b, qb2 });\n\n if (Array.from([MtrDex.Ed25519N, MtrDex.Ed25519]).includes(this.code)) {\n this._verify = this._ed25519;\n } else if (\n Array.from([MtrDex.ECDSA_256r1N, MtrDex.ECDSA_256r1]).includes(\n this.code\n )\n ) {\n this._verify = this._secp256r1;\n } else {\n throw new Error(`Unsupported code = ${this.code} for verifier.`);\n }\n }\n\n verify(sig: any, ser: any) {\n return this._verify(sig, ser, this.raw);\n }\n\n _ed25519(sig: any, ser: any, key: any) {\n try {\n return libsodium.crypto_sign_verify_detached(sig, ser, key);\n } catch (error) {\n throw new Error(error as string);\n }\n }\n _secp256r1(sig: any, ser: any, key: any) {\n try {\n const publicKey = secp256r1.fromCompressedPublicKey(key);\n return publicKey.verify(ser, sig);\n } catch (error) {\n throw new Error(error as string);\n }\n }\n}\n", "import { EmptyMaterialError } from './kering';\n\nexport {};\nimport libsodium from 'libsodium-wrappers-sumo';\nimport { Matter } from './matter';\nimport { MtrDex } from './matter';\nimport { Verfer } from './verfer';\nimport { Cigar } from './cigar';\nimport { Siger } from './siger';\nimport { IdrDex } from './indexer';\nimport { Buffer } from 'buffer';\n\n/**\n * @description Signer is Matter subclass with method to create signature of serialization\n * It will use .raw as signing (private) key seed\n * .code as cipher suite for signing and new property .verfer whose property\n * .raw is public key for signing.\n * If not provided .verfer is generated from private key seed using .code\n as cipher suite for creating key-pair.\n */\ninterface SignerArgs {\n raw?: Uint8Array | undefined;\n code?: string;\n qb64b?: Uint8Array | undefined;\n qb64?: string;\n qb2?: Uint8Array | undefined;\n transferable?: boolean;\n}\n\nexport class Signer extends Matter {\n private readonly _sign: Function;\n private readonly _verfer: Verfer;\n\n constructor({\n raw,\n code = MtrDex.Ed25519_Seed,\n qb64,\n qb64b,\n qb2,\n transferable = true,\n }: SignerArgs) {\n try {\n super({ raw, code, qb64, qb64b, qb2 });\n } catch (e) {\n if (e instanceof EmptyMaterialError) {\n if (code == MtrDex.Ed25519_Seed) {\n const raw = libsodium.randombytes_buf(\n libsodium.crypto_sign_SEEDBYTES\n );\n super({ raw, code, qb64, qb64b, qb2 });\n } else {\n throw new Error(`Unsupported signer code = ${code}.`);\n }\n } else {\n throw e;\n }\n }\n let verfer;\n if (this.code == MtrDex.Ed25519_Seed) {\n this._sign = this._ed25519;\n const keypair = libsodium.crypto_sign_seed_keypair(this.raw);\n verfer = new Verfer({\n raw: keypair.publicKey,\n code: transferable ? MtrDex.Ed25519 : MtrDex.Ed25519N,\n });\n } else {\n throw new Error(`Unsupported signer code = ${this.code}.`);\n }\n\n this._verfer = verfer;\n }\n\n /**\n * @description Property verfer:\n Returns Verfer instance\n Assumes ._verfer is correctly assigned\n */\n get verfer(): Verfer {\n return this._verfer;\n }\n\n sign(\n ser: Uint8Array,\n index: number | null = null,\n only: boolean = false,\n ondex: number | undefined = undefined\n ): Siger | Cigar {\n return this._sign(ser, this.raw, this.verfer, index, only, ondex);\n }\n\n _ed25519(\n ser: Uint8Array,\n seed: Uint8Array,\n verfer: Verfer,\n index: number | null,\n only: boolean = false,\n ondex: number | undefined\n ) {\n const sig = libsodium.crypto_sign_detached(\n ser,\n Buffer.concat([seed, verfer.raw])\n );\n\n if (index == null) {\n return new Cigar({ raw: sig, code: MtrDex.Ed25519_Sig }, verfer);\n } else {\n let code;\n if (only) {\n ondex = undefined;\n if (index <= 63) {\n code = IdrDex.Ed25519_Crt_Sig;\n } else {\n code = IdrDex.Ed25519_Big_Crt_Sig;\n }\n } else {\n if (ondex == undefined) {\n ondex = index;\n }\n\n if (ondex == index && index <= 63)\n // both same and small\n code = IdrDex.Ed25519_Sig; // use small both same\n // otherwise big or both not same so use big both\n else code = IdrDex.Ed25519_Big_Sig; // use use big both\n }\n\n return new Siger(\n { raw: sig, code: code, index: index, ondex: ondex },\n verfer\n );\n }\n }\n}\n", "import { Verfer } from './verfer';\nimport { Matter, MatterArgs } from './matter';\n\nexport class Cigar extends Matter {\n private _verfer: Verfer | undefined;\n constructor({ raw, code, qb64, qb64b, qb2 }: MatterArgs, verfer?: Verfer) {\n super({ raw, code, qb64, qb64b, qb2 });\n this._verfer = verfer;\n }\n\n get verfer(): Verfer | undefined {\n return this._verfer;\n }\n\n set verfer(verfer: Verfer | undefined) {\n this._verfer = verfer;\n }\n}\n", "import { EmptyMaterialError } from './kering';\nimport { b, b64ToInt, d, intToB64, readInt } from './core';\nimport { Buffer } from 'buffer';\nimport { decodeBase64Url, encodeBase64Url } from './base64';\n\nexport class IndexerCodex {\n Ed25519_Sig: string = 'A'; // Ed25519 sig appears same in both lists if any.\n Ed25519_Crt_Sig: string = 'B'; // Ed25519 sig appears in current list only.\n ECDSA_256k1_Sig: string = 'C'; // ECDSA secp256k1 sig appears same in both lists if any.\n ECDSA_256k1_Crt_Sig: string = 'D'; // ECDSA secp256k1 sig appears in current list.\n ECDSA_256r1_Sig: string = 'E'; // ECDSA secp256r1 sig appears same in both lists if any.\n ECDSA_256r1_Crt_Sig: string = 'F'; // ECDSA secp256r1 sig appears in current list.\n Ed448_Sig: string = '0A'; // Ed448 signature appears in both lists.\n Ed448_Crt_Sig: string = '0B'; // Ed448 signature appears in current list only.\n Ed25519_Big_Sig: string = '2A'; // Ed25519 sig appears in both lists.\n Ed25519_Big_Crt_Sig: string = '2B'; // Ed25519 sig appears in current list only.\n ECDSA_256k1_Big_Sig: string = '2C'; // ECDSA secp256k1 sig appears in both lists.\n ECDSA_256k1_Big_Crt_Sig: string = '2D'; // ECDSA secp256k1 sig appears in current list only.\n ECDSA_256r1_Big_Sig: string = '2E'; // ECDSA secp256r1 sig appears in both lists.\n ECDSA_256r1_Big_Crt_Sig: string = '2F'; // ECDSA secp256r1 sig appears in current list only.\n Ed448_Big_Sig: string = '3A'; // Ed448 signature appears in both lists.\n Ed448_Big_Crt_Sig: string = '3B'; // Ed448 signature appears in current list only.\n}\n\nexport const IdrDex = new IndexerCodex();\n\nexport class IndexedSigCodex {\n Ed25519_Sig: string = 'A'; // Ed25519 sig appears same in both lists if any.\n Ed25519_Crt_Sig: string = 'B'; // Ed25519 sig appears in current list only.\n ECDSA_256k1_Sig: string = 'C'; // ECDSA secp256k1 sig appears same in both lists if any.\n ECDSA_256k1_Crt_Sig: string = 'D'; // ECDSA secp256k1 sig appears in current list.\n ECDSA_256r1_Sig: string = 'E'; // ECDSA secp256r1 sig appears same in both lists if any.\n ECDSA_256r1_Crt_Sig: string = 'F'; // ECDSA secp256r1 sig appears in current list.\n Ed448_Sig: string = '0A'; // Ed448 signature appears in both lists.\n Ed448_Crt_Sig: string = '0B'; // Ed448 signature appears in current list only.\n Ed25519_Big_Sig: string = '2A'; // Ed25519 sig appears in both lists.\n Ed25519_Big_Crt_Sig: string = '2B'; // Ed25519 sig appears in current list only.\n ECDSA_256k1_Big_Sig: string = '2C'; // ECDSA secp256k1 sig appears in both lists.\n ECDSA_256k1_Big_Crt_Sig: string = '2D'; // ECDSA secp256k1 sig appears in current list only.\n ECDSA_256r1_Big_Sig: string = '2E'; // ECDSA secp256r1 sig appears in both lists.\n ECDSA_256r1_Big_Crt_Sig: string = '2F'; // ECDSA secp256r1 sig appears in current list only.\n Ed448_Big_Sig: string = '3A'; // Ed448 signature appears in both lists.\n Ed448_Big_Crt_Sig: string = '3B'; // Ed448 signature appears in current list only.\n\n has(prop: string): boolean {\n const m = new Map(\n Array.from(Object.entries(this), (v) => [v[1], v[0]])\n );\n return m.has(prop);\n }\n}\n\nexport const IdxSigDex = new IndexedSigCodex();\n\nexport class IndexedCurrentSigCodex {\n Ed25519_Crt_Sig: string = 'B'; // Ed25519 sig appears in current list only.\n ECDSA_256k1_Crt_Sig: string = 'D'; // ECDSA secp256k1 sig appears in current list only.\n ECDSA_256r1_Crt_Sig: string = 'F'; // ECDSA secp256r1 sig appears in current list.\n Ed448_Crt_Sig: string = '0B'; // Ed448 signature appears in current list only.\n Ed25519_Big_Crt_Sig: string = '2B'; // Ed25519 sig appears in current list only.\n ECDSA_256k1_Big_Crt_Sig: string = '2D'; // ECDSA secp256k1 sig appears in current list only.\n ECDSA_256r1_Big_Crt_Sig: string = '2F'; // ECDSA secp256r1 sig appears in current list only.\n Ed448_Big_Crt_Sig: string = '3B'; // Ed448 signature appears in current list only.\n\n has(prop: string): boolean {\n const m = new Map(\n Array.from(Object.entries(this), (v) => [v[1], v[0]])\n );\n return m.has(prop);\n }\n}\n\nexport const IdxCrtSigDex = new IndexedCurrentSigCodex();\n\nexport class IndexedBothSigCodex {\n Ed25519_Sig: string = 'A'; // Ed25519 sig appears same in both lists if any.\n ECDSA_256k1_Sig: string = 'C'; // ECDSA secp256k1 sig appears same in both lists if any.\n Ed448_Sig: string = '0A'; // Ed448 signature appears in both lists.\n Ed25519_Big_Sig: string = '2A'; // Ed25519 sig appears in both listsy.\n ECDSA_256k1_Big_Sig: string = '2C'; // ECDSA secp256k1 sig appears in both lists.\n Ed448_Big_Sig: string = '3A'; // Ed448 signature appears in both lists.\n\n has(prop: string): boolean {\n const m = new Map(\n Array.from(Object.entries(this), (v) => [v[1], v[0]])\n );\n return m.has(prop);\n }\n}\n\nexport const IdxBthSigDex = new IndexedBothSigCodex();\n\nexport class Xizage {\n public hs: number;\n public ss: number;\n public os: number;\n public fs?: number;\n public ls: number;\n\n constructor(hs: number, ss: number, os: number, fs?: number, ls?: number) {\n this.hs = hs;\n this.ss = ss;\n this.os = os;\n this.fs = fs;\n this.ls = ls!;\n }\n}\n\nexport interface IndexerArgs {\n raw?: Uint8Array | undefined;\n code?: string | undefined;\n index?: number;\n ondex?: number;\n qb64b?: Uint8Array | undefined;\n qb64?: string | undefined;\n qb2?: Uint8Array | undefined;\n}\n\nexport class Indexer {\n public Codex = IdrDex;\n\n static Hards = new Map<string, number>([\n ['A', 1],\n ['B', 1],\n ['C', 1],\n ['D', 1],\n ['E', 1],\n ['F', 1],\n ['G', 1],\n ['H', 1],\n ['I', 1],\n ['J', 1],\n ['K', 1],\n ['L', 1],\n ['M', 1],\n ['N', 1],\n ['O', 1],\n ['P', 1],\n ['Q', 1],\n ['R', 1],\n ['S', 1],\n ['T', 1],\n ['U', 1],\n ['V', 1],\n ['W', 1],\n ['X', 1],\n ['Y', 1],\n ['Z', 1],\n ['a', 1],\n ['b', 1],\n ['c', 1],\n ['d', 1],\n ['e', 1],\n ['f', 1],\n ['g', 1],\n ['h', 1],\n ['i', 1],\n ['j', 1],\n ['k', 1],\n ['l', 1],\n ['m', 1],\n ['n', 1],\n ['o', 1],\n ['p', 1],\n ['q', 1],\n ['r', 1],\n ['s', 1],\n ['t', 1],\n ['u', 1],\n ['v', 1],\n ['w', 1],\n ['x', 1],\n ['y', 1],\n ['z', 1],\n ['0', 2],\n ['1', 2],\n ['2', 2],\n ['3', 2],\n ['4', 2],\n ]);\n\n static Sizes = new Map(\n Object.entries({\n A: new Xizage(1, 1, 0, 88, 0),\n B: new Xizage(1, 1, 0, 88, 0),\n C: new Xizage(1, 1, 0, 88, 0),\n D: new Xizage(1, 1, 0, 88, 0),\n E: new Xizage(1, 1, 0, 88, 0),\n F: new Xizage(1, 1, 0, 88, 0),\n '0A': new Xizage(2, 2, 1, 156, 0),\n '0B': new Xizage(2, 2, 1, 156, 0),\n\n '2A': new Xizage(2, 4, 2, 92, 0),\n '2B': new Xizage(2, 4, 2, 92, 0),\n '2C': new Xizage(2, 4, 2, 92, 0),\n '2D': new Xizage(2, 4, 2, 92, 0),\n '2E': new Xizage(2, 4, 2, 92, 0),\n '2F': new Xizage(2, 4, 2, 92, 0),\n\n '3A': new Xizage(2, 6, 3, 160, 0),\n '3B': new Xizage(2, 6, 3, 160, 0),\n\n '0z': new Xizage(2, 2, 0, undefined, 0),\n '1z': new Xizage(2, 2, 1, 76, 1),\n '4z': new Xizage(2, 6, 3, 80, 1),\n })\n );\n\n private _code: string = '';\n private _index: number = -1;\n private _ondex: number | undefined;\n private _raw: Uint8Array = new Uint8Array(0);\n\n constructor({\n raw = undefined,\n code = IdrDex.Ed25519_Sig,\n index = 0,\n ondex = undefined,\n qb64b = undefined,\n qb64 = undefined,\n qb2 = undefined,\n }: IndexerArgs) {\n if (raw != undefined) {\n if (code == undefined) {\n throw new EmptyMaterialError(\n `Improper initialization need either (raw and code) or qb64b or qb64 or qb2.`\n );\n }\n\n if (!Indexer.Sizes.has(code)) {\n throw new Error(`Unsupported code=${code}.`);\n }\n\n const xizage = Indexer.Sizes.get(code)!;\n const os = xizage.os;\n const fs = xizage.fs;\n const cs = xizage.hs + xizage.ss;\n const ms = xizage.ss - xizage.os;\n\n if (!Number.isInteger(index) || index < 0 || index > 64 ** ms - 1) {\n throw new Error(`Invalid index=${index} for code=${code}.`);\n }\n\n if (\n ondex != undefined &&\n xizage.os != 0 &&\n !(ondex >= 0 && ondex <= 64 ** os - 1)\n ) {\n throw new Error(`Invalid ondex=${ondex} for code=${code}.`);\n }\n\n if (IdxCrtSigDex.has(code) && ondex != undefined) {\n throw new Error(`Non None ondex=${ondex} for code=${code}.`);\n }\n\n if (IdxBthSigDex.has(code)) {\n if (ondex == undefined) {\n ondex = index;\n } else {\n if (ondex != index && os == 0) {\n throw new Error(\n `Non matching ondex=${ondex} and index=${index} for code=${code}.`\n );\n }\n }\n }\n\n if (fs == undefined) {\n throw new Error('variable length unsupported');\n }\n // TODO: Don't support this code\n // if not fs: # compute fs from index\n // if cs % 4:\n // raise InvalidCodeSizeError(f\"Whole code size not multiple of 4 for \"\n // f\"variable length material. cs={cs}.\")\n // if os != 0:\n // raise InvalidCodeSizeError(f\"Non-zero other index size for \"\n // f\"variable length material. os={os}.\")\n // fs = (index * 4) + cs\n const rawsize = Math.floor(((fs - cs) * 3) / 4);\n raw = raw.slice(0, rawsize);\n\n if (raw.length != rawsize) {\n throw new Error(\n `Not enougth raw bytes for code=${code} and index=${index} ,expected ${rawsize} got ${raw.length}.`\n );\n }\n\n this._code = code;\n this._index = index;\n this._ondex = ondex;\n this._raw = raw;\n } else if (qb64b != undefined) {\n const qb64 = d(qb64b);\n this._exfil(qb64);\n } else if (qb64 != undefined) {\n this._exfil(qb64);\n } else if (qb2 != undefined) {\n this._bexfil(qb2);\n