@smartledger/keys 1.1.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/browser.d.ts +20 -0
- package/dist/cjs/browser.d.ts.map +1 -0
- package/dist/cjs/browser.js.map +1 -0
- package/dist/cjs/index.d.ts +9 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/{index.js → cjs/index.js} +2 -2
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/sdk.d.ts +69 -0
- package/dist/cjs/sdk.d.ts.map +1 -0
- package/dist/cjs/sdk.js.map +1 -0
- package/dist/cjs/types.d.ts +117 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/esm/browser.d.ts +20 -0
- package/dist/esm/browser.d.ts.map +1 -0
- package/dist/esm/browser.js +41 -0
- package/dist/esm/browser.js.map +1 -0
- package/dist/esm/index.d.ts +9 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +8 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/sdk.d.ts +69 -0
- package/dist/esm/sdk.d.ts.map +1 -0
- package/dist/esm/sdk.js +186 -0
- package/dist/esm/sdk.js.map +1 -0
- package/dist/esm/types.d.ts +117 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +8 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/lumen-keys.js +1556 -2846
- package/dist/lumen-keys.js.map +4 -4
- package/dist/lumen-keys.min.js +2 -2
- package/dist/lumen-keys.min.js.map +4 -4
- package/dist/tsconfig.esm.tsbuildinfo +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +22 -6
- package/dist/browser.d.ts.map +0 -1
- package/dist/browser.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/sdk.d.ts.map +0 -1
- package/dist/sdk.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- /package/dist/{browser.js → cjs/browser.js} +0 -0
- /package/dist/{sdk.js → cjs/sdk.js} +0 -0
- /package/dist/{types.js → cjs/types.js} +0 -0
package/dist/lumen-keys.js
CHANGED
|
@@ -83,76 +83,6 @@ var LumenKeys = (() => {
|
|
|
83
83
|
}
|
|
84
84
|
});
|
|
85
85
|
|
|
86
|
-
// ../crypto/dist/types.js
|
|
87
|
-
var require_types = __commonJS({
|
|
88
|
-
"../crypto/dist/types.js"(exports2) {
|
|
89
|
-
"use strict";
|
|
90
|
-
init_esbuild_shims();
|
|
91
|
-
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
// ../crypto/dist/registry.js
|
|
96
|
-
var require_registry = __commonJS({
|
|
97
|
-
"../crypto/dist/registry.js"(exports2) {
|
|
98
|
-
"use strict";
|
|
99
|
-
init_esbuild_shims();
|
|
100
|
-
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
101
|
-
exports2.globalRegistry = exports2.SignatureSuiteRegistry = void 0;
|
|
102
|
-
var SignatureSuiteRegistry3 = class {
|
|
103
|
-
constructor() {
|
|
104
|
-
__publicField(this, "suites", /* @__PURE__ */ new Map());
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Register a signature suite implementation
|
|
108
|
-
*/
|
|
109
|
-
register(suite) {
|
|
110
|
-
if (this.suites.has(suite.suiteId)) {
|
|
111
|
-
throw new Error(`Signature suite already registered: ${suite.suiteId}`);
|
|
112
|
-
}
|
|
113
|
-
this.suites.set(suite.suiteId, suite);
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Get a signature suite by ID
|
|
117
|
-
* @throws Error if suite is not registered
|
|
118
|
-
*/
|
|
119
|
-
getSuite(suiteId) {
|
|
120
|
-
const suite = this.suites.get(suiteId);
|
|
121
|
-
if (!suite) {
|
|
122
|
-
throw new Error(`Unknown signature suite: ${suiteId}. Available: ${this.listSuites().join(", ")}`);
|
|
123
|
-
}
|
|
124
|
-
return suite;
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Check if a suite is registered
|
|
128
|
-
*/
|
|
129
|
-
hasSuite(suiteId) {
|
|
130
|
-
return this.suites.has(suiteId);
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* List all registered suite IDs
|
|
134
|
-
*/
|
|
135
|
-
listSuites() {
|
|
136
|
-
return [...this.suites.keys()];
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Unregister a suite (primarily for testing)
|
|
140
|
-
*/
|
|
141
|
-
unregister(suiteId) {
|
|
142
|
-
return this.suites.delete(suiteId);
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Clear all registered suites (primarily for testing)
|
|
146
|
-
*/
|
|
147
|
-
clear() {
|
|
148
|
-
this.suites.clear();
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
exports2.SignatureSuiteRegistry = SignatureSuiteRegistry3;
|
|
152
|
-
exports2.globalRegistry = new SignatureSuiteRegistry3();
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
|
|
156
86
|
// node_modules/@noble/hashes/utils.js
|
|
157
87
|
function isBytes(a2) {
|
|
158
88
|
return a2 instanceof Uint8Array || ArrayBuffer.isView(a2) && a2.constructor.name === "Uint8Array";
|
|
@@ -1027,2599 +957,119 @@ var LumenKeys = (() => {
|
|
|
1027
957
|
}
|
|
1028
958
|
});
|
|
1029
959
|
|
|
1030
|
-
//
|
|
1031
|
-
var
|
|
1032
|
-
"
|
|
1033
|
-
"use strict";
|
|
1034
|
-
init_esbuild_shims();
|
|
1035
|
-
var __createBinding = exports2 && exports2.__createBinding || (Object.create ? (function(o2, m2, k2, k22) {
|
|
1036
|
-
if (k22 === void 0) k22 = k2;
|
|
1037
|
-
var desc = Object.getOwnPropertyDescriptor(m2, k2);
|
|
1038
|
-
if (!desc || ("get" in desc ? !m2.__esModule : desc.writable || desc.configurable)) {
|
|
1039
|
-
desc = { enumerable: true, get: function() {
|
|
1040
|
-
return m2[k2];
|
|
1041
|
-
} };
|
|
1042
|
-
}
|
|
1043
|
-
Object.defineProperty(o2, k22, desc);
|
|
1044
|
-
}) : (function(o2, m2, k2, k22) {
|
|
1045
|
-
if (k22 === void 0) k22 = k2;
|
|
1046
|
-
o2[k22] = m2[k2];
|
|
1047
|
-
}));
|
|
1048
|
-
var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? (function(o2, v2) {
|
|
1049
|
-
Object.defineProperty(o2, "default", { enumerable: true, value: v2 });
|
|
1050
|
-
}) : function(o2, v2) {
|
|
1051
|
-
o2["default"] = v2;
|
|
1052
|
-
});
|
|
1053
|
-
var __importStar = exports2 && exports2.__importStar || /* @__PURE__ */ (function() {
|
|
1054
|
-
var ownKeys = function(o2) {
|
|
1055
|
-
ownKeys = Object.getOwnPropertyNames || function(o3) {
|
|
1056
|
-
var ar = [];
|
|
1057
|
-
for (var k2 in o3) if (Object.prototype.hasOwnProperty.call(o3, k2)) ar[ar.length] = k2;
|
|
1058
|
-
return ar;
|
|
1059
|
-
};
|
|
1060
|
-
return ownKeys(o2);
|
|
1061
|
-
};
|
|
1062
|
-
return function(mod) {
|
|
1063
|
-
if (mod && mod.__esModule) return mod;
|
|
1064
|
-
var result = {};
|
|
1065
|
-
if (mod != null) {
|
|
1066
|
-
for (var k2 = ownKeys(mod), i2 = 0; i2 < k2.length; i2++) if (k2[i2] !== "default") __createBinding(result, mod, k2[i2]);
|
|
1067
|
-
}
|
|
1068
|
-
__setModuleDefault(result, mod);
|
|
1069
|
-
return result;
|
|
1070
|
-
};
|
|
1071
|
-
})();
|
|
1072
|
-
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
1073
|
-
exports2.canonicalizeJson = canonicalizeJson;
|
|
1074
|
-
exports2.stringToBytes = stringToBytes;
|
|
1075
|
-
exports2.bytesToString = bytesToString;
|
|
1076
|
-
exports2.bytesToHex = bytesToHex2;
|
|
1077
|
-
exports2.hexToBytes = hexToBytes2;
|
|
1078
|
-
exports2.bytesToBase64Url = bytesToBase64Url;
|
|
1079
|
-
exports2.base64UrlToBytes = base64UrlToBytes;
|
|
1080
|
-
exports2.constantTimeEqual = constantTimeEqual;
|
|
1081
|
-
exports2.zeroBytes = zeroBytes;
|
|
1082
|
-
exports2.hashBytes = hashBytes2;
|
|
1083
|
-
function canonicalizeJson(obj) {
|
|
1084
|
-
if (obj === null)
|
|
1085
|
-
return "null";
|
|
1086
|
-
if (typeof obj !== "object")
|
|
1087
|
-
return JSON.stringify(obj);
|
|
1088
|
-
if (Array.isArray(obj)) {
|
|
1089
|
-
return "[" + obj.map(canonicalizeJson).join(",") + "]";
|
|
1090
|
-
}
|
|
1091
|
-
const keys = Object.keys(obj).sort();
|
|
1092
|
-
const pairs = keys.map((key) => `"${key}":${canonicalizeJson(obj[key])}`);
|
|
1093
|
-
return "{" + pairs.join(",") + "}";
|
|
1094
|
-
}
|
|
1095
|
-
function stringToBytes(str) {
|
|
1096
|
-
return new TextEncoder().encode(str);
|
|
1097
|
-
}
|
|
1098
|
-
function bytesToString(bytes) {
|
|
1099
|
-
return new TextDecoder().decode(bytes);
|
|
1100
|
-
}
|
|
1101
|
-
function bytesToHex2(bytes) {
|
|
1102
|
-
return Array.from(bytes).map((b2) => b2.toString(16).padStart(2, "0")).join("");
|
|
1103
|
-
}
|
|
1104
|
-
function hexToBytes2(hex) {
|
|
1105
|
-
if (hex.length % 2 !== 0) {
|
|
1106
|
-
throw new Error("Hex string must have even length");
|
|
1107
|
-
}
|
|
1108
|
-
const bytes = new Uint8Array(hex.length / 2);
|
|
1109
|
-
for (let i2 = 0; i2 < hex.length; i2 += 2) {
|
|
1110
|
-
bytes[i2 / 2] = parseInt(hex.slice(i2, i2 + 2), 16);
|
|
1111
|
-
}
|
|
1112
|
-
return bytes;
|
|
1113
|
-
}
|
|
1114
|
-
function bytesToBase64Url(bytes) {
|
|
1115
|
-
const base64 = Buffer.from(bytes).toString("base64");
|
|
1116
|
-
return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
1117
|
-
}
|
|
1118
|
-
function base64UrlToBytes(base64url) {
|
|
1119
|
-
let base64 = base64url.replace(/-/g, "+").replace(/_/g, "/");
|
|
1120
|
-
const padding = base64.length % 4;
|
|
1121
|
-
if (padding) {
|
|
1122
|
-
base64 += "=".repeat(4 - padding);
|
|
1123
|
-
}
|
|
1124
|
-
return new Uint8Array(Buffer.from(base64, "base64"));
|
|
1125
|
-
}
|
|
1126
|
-
function constantTimeEqual(a2, b2) {
|
|
1127
|
-
if (a2.length !== b2.length)
|
|
1128
|
-
return false;
|
|
1129
|
-
let result = 0;
|
|
1130
|
-
for (let i2 = 0; i2 < a2.length; i2++) {
|
|
1131
|
-
result |= a2[i2] ^ b2[i2];
|
|
1132
|
-
}
|
|
1133
|
-
return result === 0;
|
|
1134
|
-
}
|
|
1135
|
-
function zeroBytes(bytes) {
|
|
1136
|
-
bytes.fill(0);
|
|
1137
|
-
}
|
|
1138
|
-
async function hashBytes2(bytes, algorithm) {
|
|
1139
|
-
if (algorithm === "sha256") {
|
|
1140
|
-
const crypto = await Promise.resolve().then(() => __importStar((init_crypto_browser_shim(), __toCommonJS(crypto_browser_shim_exports))));
|
|
1141
|
-
return new Uint8Array(crypto.createHash("sha256").update(bytes).digest());
|
|
1142
|
-
} else if (algorithm === "sha512") {
|
|
1143
|
-
const crypto = await Promise.resolve().then(() => __importStar((init_crypto_browser_shim(), __toCommonJS(crypto_browser_shim_exports))));
|
|
1144
|
-
return new Uint8Array(crypto.createHash("sha512").update(bytes).digest());
|
|
1145
|
-
} else if (algorithm === "sha3-256") {
|
|
1146
|
-
const crypto = await Promise.resolve().then(() => __importStar((init_crypto_browser_shim(), __toCommonJS(crypto_browser_shim_exports))));
|
|
1147
|
-
return new Uint8Array(crypto.createHash("sha3-256").update(bytes).digest());
|
|
1148
|
-
}
|
|
1149
|
-
throw new Error(`Unsupported hash algorithm: ${algorithm}`);
|
|
1150
|
-
}
|
|
1151
|
-
}
|
|
1152
|
-
});
|
|
1153
|
-
|
|
1154
|
-
// ../crypto/dist/signing.js
|
|
1155
|
-
var require_signing = __commonJS({
|
|
1156
|
-
"../crypto/dist/signing.js"(exports2) {
|
|
1157
|
-
"use strict";
|
|
960
|
+
// ../../node_modules/dilithium-crystals/dist/index.js
|
|
961
|
+
var require_dist = __commonJS({
|
|
962
|
+
"../../node_modules/dilithium-crystals/dist/index.js"(exports, module) {
|
|
1158
963
|
init_esbuild_shims();
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
const canonicalPayload = (0, utils_1.canonicalizeJson)(payload);
|
|
1165
|
-
const payloadBytes = (0, utils_1.stringToBytes)(canonicalPayload);
|
|
1166
|
-
const signatures = [];
|
|
1167
|
-
const primarySuite = registry.getSuite(primaryKey.suiteId);
|
|
1168
|
-
const primaryHashAlg = getHashAlgorithm(primaryKey.suiteId);
|
|
1169
|
-
const primaryHash = await (0, utils_1.hashBytes)(payloadBytes, primaryHashAlg);
|
|
1170
|
-
const primarySig = await primarySuite.sign(primaryKeyBytes, primaryHash);
|
|
1171
|
-
signatures.push({
|
|
1172
|
-
suiteId: primaryKey.suiteId,
|
|
1173
|
-
keyId: primaryKey.keyId,
|
|
1174
|
-
hashAlgorithm: primaryHashAlg,
|
|
1175
|
-
payloadHash: (0, utils_1.bytesToBase64Url)(primaryHash),
|
|
1176
|
-
signature: (0, utils_1.bytesToBase64Url)(primarySig)
|
|
1177
|
-
});
|
|
1178
|
-
if (secondaryKey && secondaryKeyBytes) {
|
|
1179
|
-
const secondarySuite = registry.getSuite(secondaryKey.suiteId);
|
|
1180
|
-
const secondaryHashAlg = getHashAlgorithm(secondaryKey.suiteId);
|
|
1181
|
-
const secondaryHash = await (0, utils_1.hashBytes)(payloadBytes, secondaryHashAlg);
|
|
1182
|
-
const secondarySig = await secondarySuite.sign(secondaryKeyBytes, secondaryHash);
|
|
1183
|
-
signatures.push({
|
|
1184
|
-
suiteId: secondaryKey.suiteId,
|
|
1185
|
-
keyId: secondaryKey.keyId,
|
|
1186
|
-
hashAlgorithm: secondaryHashAlg,
|
|
1187
|
-
payloadHash: (0, utils_1.bytesToBase64Url)(secondaryHash),
|
|
1188
|
-
signature: (0, utils_1.bytesToBase64Url)(secondarySig)
|
|
1189
|
-
});
|
|
964
|
+
var dilithium = (function() {
|
|
965
|
+
var A, I, g, C = {};
|
|
966
|
+
function B(A2, I3) {
|
|
967
|
+
if (0 === A2) return I3;
|
|
968
|
+
throw new Error("Dilithium error: " + A2);
|
|
1190
969
|
}
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
mode: signatures.length > 1 ? "hybrid" : "single",
|
|
1194
|
-
signatures
|
|
1195
|
-
};
|
|
1196
|
-
if (signatures.length > 1 && agentMeta.cryptoProfile.primarySignatureSuite) {
|
|
1197
|
-
signatureMetadata.policy = {
|
|
1198
|
-
threshold: "all",
|
|
1199
|
-
requiredSuites: [agentMeta.cryptoProfile.primarySignatureSuite]
|
|
1200
|
-
};
|
|
970
|
+
function Q(A2, I3) {
|
|
971
|
+
return new Uint8Array(new Uint8Array(C.HEAPU8.buffer, A2, I3));
|
|
1201
972
|
}
|
|
1202
|
-
|
|
1203
|
-
agent: agentMeta.agentId,
|
|
1204
|
-
version: agentMeta.version,
|
|
1205
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1206
|
-
payload,
|
|
1207
|
-
_signature: signatureMetadata
|
|
1208
|
-
};
|
|
1209
|
-
}
|
|
1210
|
-
async function verifySignedEnvelope(envelope, registry, publicKeys) {
|
|
1211
|
-
const results = [];
|
|
1212
|
-
const canonicalPayload = (0, utils_1.canonicalizeJson)(envelope.payload);
|
|
1213
|
-
const payloadBytes = (0, utils_1.stringToBytes)(canonicalPayload);
|
|
1214
|
-
for (const sigEntry of envelope._signature.signatures) {
|
|
973
|
+
function i(A2) {
|
|
1215
974
|
try {
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
keyId: sigEntry.keyId,
|
|
1222
|
-
valid: false,
|
|
1223
|
-
error: "Public key not found"
|
|
1224
|
-
});
|
|
1225
|
-
continue;
|
|
1226
|
-
}
|
|
1227
|
-
const computedHash = await (0, utils_1.hashBytes)(payloadBytes, sigEntry.hashAlgorithm);
|
|
1228
|
-
const expectedHash = (0, utils_1.base64UrlToBytes)(sigEntry.payloadHash);
|
|
1229
|
-
if (!arraysEqual(computedHash, expectedHash)) {
|
|
1230
|
-
results.push({
|
|
1231
|
-
suiteId: sigEntry.suiteId,
|
|
1232
|
-
keyId: sigEntry.keyId,
|
|
1233
|
-
valid: false,
|
|
1234
|
-
error: "Payload hash mismatch"
|
|
1235
|
-
});
|
|
1236
|
-
continue;
|
|
1237
|
-
}
|
|
1238
|
-
const signature = (0, utils_1.base64UrlToBytes)(sigEntry.signature);
|
|
1239
|
-
const valid = await suite.verify(publicKey, computedHash, signature);
|
|
1240
|
-
results.push({
|
|
1241
|
-
suiteId: sigEntry.suiteId,
|
|
1242
|
-
keyId: sigEntry.keyId,
|
|
1243
|
-
valid,
|
|
1244
|
-
error: valid ? void 0 : "Signature verification failed"
|
|
1245
|
-
});
|
|
1246
|
-
} catch (error) {
|
|
1247
|
-
results.push({
|
|
1248
|
-
suiteId: sigEntry.suiteId,
|
|
1249
|
-
keyId: sigEntry.keyId,
|
|
1250
|
-
valid: false,
|
|
1251
|
-
error: error instanceof Error ? error.message : String(error)
|
|
1252
|
-
});
|
|
1253
|
-
}
|
|
1254
|
-
}
|
|
1255
|
-
const policyMet = checkPolicy(envelope._signature, results);
|
|
1256
|
-
return {
|
|
1257
|
-
valid: policyMet && results.every((r2) => r2.valid),
|
|
1258
|
-
details: {
|
|
1259
|
-
signatureResults: results,
|
|
1260
|
-
policyMet,
|
|
1261
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
1262
|
-
}
|
|
1263
|
-
};
|
|
1264
|
-
}
|
|
1265
|
-
function checkPolicy(signature, results) {
|
|
1266
|
-
const policy = signature.policy;
|
|
1267
|
-
if (!policy) {
|
|
1268
|
-
return results.every((r2) => r2.valid);
|
|
1269
|
-
}
|
|
1270
|
-
const validResults = results.filter((r2) => r2.valid);
|
|
1271
|
-
if (policy.requiredSuites) {
|
|
1272
|
-
const requiredValid = policy.requiredSuites.every((suiteId) => validResults.some((r2) => r2.suiteId === suiteId));
|
|
1273
|
-
if (!requiredValid)
|
|
1274
|
-
return false;
|
|
1275
|
-
}
|
|
1276
|
-
switch (policy.threshold) {
|
|
1277
|
-
case "any":
|
|
1278
|
-
return validResults.length > 0;
|
|
1279
|
-
case "all":
|
|
1280
|
-
return validResults.length === results.length;
|
|
1281
|
-
case "quorum":
|
|
1282
|
-
return validResults.length >= (policy.quorumCount || 0);
|
|
1283
|
-
default:
|
|
1284
|
-
return validResults.length === results.length;
|
|
1285
|
-
}
|
|
1286
|
-
}
|
|
1287
|
-
function getHashAlgorithm(suiteId) {
|
|
1288
|
-
if (suiteId.startsWith("bsv-ecdsa"))
|
|
1289
|
-
return "sha256";
|
|
1290
|
-
if (suiteId.startsWith("ml-dsa"))
|
|
1291
|
-
return "sha3-256";
|
|
1292
|
-
if (suiteId.startsWith("fn-dsa"))
|
|
1293
|
-
return "sha3-256";
|
|
1294
|
-
if (suiteId.startsWith("slh-dsa"))
|
|
1295
|
-
return "sha256";
|
|
1296
|
-
return "sha256";
|
|
1297
|
-
}
|
|
1298
|
-
function arraysEqual(a2, b2) {
|
|
1299
|
-
if (a2.length !== b2.length)
|
|
1300
|
-
return false;
|
|
1301
|
-
for (let i2 = 0; i2 < a2.length; i2++) {
|
|
1302
|
-
if (a2[i2] !== b2[i2])
|
|
1303
|
-
return false;
|
|
1304
|
-
}
|
|
1305
|
-
return true;
|
|
1306
|
-
}
|
|
1307
|
-
}
|
|
1308
|
-
});
|
|
1309
|
-
|
|
1310
|
-
// ../crypto/dist/key-registry.js
|
|
1311
|
-
var require_key_registry = __commonJS({
|
|
1312
|
-
"../crypto/dist/key-registry.js"(exports2) {
|
|
1313
|
-
"use strict";
|
|
1314
|
-
init_esbuild_shims();
|
|
1315
|
-
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
1316
|
-
exports2.KeyRegistry = exports2.InMemoryKeyStorage = void 0;
|
|
1317
|
-
var InMemoryKeyStorage3 = class {
|
|
1318
|
-
constructor() {
|
|
1319
|
-
__publicField(this, "keys", /* @__PURE__ */ new Map());
|
|
1320
|
-
}
|
|
1321
|
-
async store(keyId, keypair, meta) {
|
|
1322
|
-
this.keys.set(keyId, { keypair, meta });
|
|
1323
|
-
}
|
|
1324
|
-
async load(keyId) {
|
|
1325
|
-
return this.keys.get(keyId) || null;
|
|
1326
|
-
}
|
|
1327
|
-
async list(filter) {
|
|
1328
|
-
const allMeta = Array.from(this.keys.values()).map((k2) => k2.meta);
|
|
1329
|
-
if (!filter) {
|
|
1330
|
-
return allMeta;
|
|
975
|
+
C._free(A2);
|
|
976
|
+
} catch (A3) {
|
|
977
|
+
setTimeout((function() {
|
|
978
|
+
throw A3;
|
|
979
|
+
}), 0);
|
|
1331
980
|
}
|
|
1332
|
-
return allMeta.filter((meta) => {
|
|
1333
|
-
return Object.entries(filter).every(([key, value]) => {
|
|
1334
|
-
if (key === "usage" && Array.isArray(value)) {
|
|
1335
|
-
return value.some((u2) => meta.usage.includes(u2));
|
|
1336
|
-
}
|
|
1337
|
-
return meta[key] === value;
|
|
1338
|
-
});
|
|
1339
|
-
});
|
|
1340
981
|
}
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
982
|
+
C.ready = new Promise((function(A, I) {
|
|
983
|
+
function g(A2) {
|
|
984
|
+
return g = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(A3) {
|
|
985
|
+
return typeof A3;
|
|
986
|
+
} : function(A3) {
|
|
987
|
+
return A3 && "function" == typeof Symbol && A3.constructor === Symbol && A3 !== Symbol.prototype ? "symbol" : typeof A3;
|
|
988
|
+
}, g(A2);
|
|
1348
989
|
}
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
* Clear all keys (testing only).
|
|
1356
|
-
*/
|
|
1357
|
-
clear() {
|
|
1358
|
-
this.keys.clear();
|
|
1359
|
-
}
|
|
1360
|
-
};
|
|
1361
|
-
exports2.InMemoryKeyStorage = InMemoryKeyStorage3;
|
|
1362
|
-
var KeyRegistry3 = class {
|
|
1363
|
-
constructor(storage = new InMemoryKeyStorage3()) {
|
|
1364
|
-
__publicField(this, "storage");
|
|
1365
|
-
this.storage = storage;
|
|
1366
|
-
}
|
|
1367
|
-
/**
|
|
1368
|
-
* Register a new keypair with metadata.
|
|
1369
|
-
*/
|
|
1370
|
-
async registerKey(keyId, keypair, suiteId, options = {}) {
|
|
1371
|
-
const meta = {
|
|
1372
|
-
keyId,
|
|
1373
|
-
suiteId,
|
|
1374
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1375
|
-
expiresAt: options.expiresAt,
|
|
1376
|
-
usage: options.usage || ["signing"],
|
|
1377
|
-
cryptoProfileVersion: options.cryptoProfileVersion || "1.0.0",
|
|
1378
|
-
status: options.status || "active"
|
|
1379
|
-
};
|
|
1380
|
-
await this.storage.store(keyId, keypair, meta);
|
|
1381
|
-
return meta;
|
|
1382
|
-
}
|
|
1383
|
-
/**
|
|
1384
|
-
* Get a keypair and its metadata.
|
|
1385
|
-
*/
|
|
1386
|
-
async getKey(keyId) {
|
|
1387
|
-
return await this.storage.load(keyId);
|
|
1388
|
-
}
|
|
1389
|
-
/**
|
|
1390
|
-
* Get only the public key (no private key).
|
|
1391
|
-
*/
|
|
1392
|
-
async getPublicKey(keyId) {
|
|
1393
|
-
const result = await this.storage.load(keyId);
|
|
1394
|
-
if (!result)
|
|
1395
|
-
return null;
|
|
1396
|
-
return {
|
|
1397
|
-
publicKey: result.keypair.publicKey,
|
|
1398
|
-
meta: result.meta
|
|
990
|
+
(Q = {}).onAbort = I, Q.onRuntimeInitialized = function() {
|
|
991
|
+
try {
|
|
992
|
+
Q._dilithiumjs_public_key_bytes(), A(Q);
|
|
993
|
+
} catch (A2) {
|
|
994
|
+
I(A2);
|
|
995
|
+
}
|
|
1399
996
|
};
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
997
|
+
var C, B, Q = void 0 !== Q ? Q : {}, i = Object.assign({}, Q), E = function(A2, I3) {
|
|
998
|
+
throw I3;
|
|
999
|
+
}, o = "object" == ("undefined" == typeof window ? "undefined" : g(window)), n = "function" == typeof importScripts, r = "object" == ("undefined" == typeof process ? "undefined" : g(process)) && "object" == g(process.versions) && "string" == typeof process.versions.node, t = "";
|
|
1000
|
+
if (r) {
|
|
1001
|
+
var a = eval("require")("fs"), e = eval("require")("path");
|
|
1002
|
+
t = n ? e.dirname(t) + "/" : __dirname + "/", C = function(A2, I3) {
|
|
1003
|
+
var g2 = x(A2);
|
|
1004
|
+
return g2 ? I3 ? g2 : g2.toString() : (A2 = q(A2) ? new URL(A2) : e.normalize(A2), a.readFileSync(A2, I3 ? void 0 : "utf8"));
|
|
1005
|
+
}, B = function(A2) {
|
|
1006
|
+
var I3 = C(A2, true);
|
|
1007
|
+
return I3.buffer || (I3 = new Uint8Array(I3)), I3;
|
|
1008
|
+
}, function(A2, I3, g2) {
|
|
1009
|
+
var C3 = !(arguments.length > 3 && void 0 !== arguments[3]) || arguments[3], B2 = x(A2);
|
|
1010
|
+
B2 && I3(B2), A2 = q(A2) ? new URL(A2) : e.normalize(A2), a.readFile(A2, C3 ? void 0 : "utf8", (function(A3, B3) {
|
|
1011
|
+
A3 ? g2(A3) : I3(C3 ? B3.buffer : B3);
|
|
1012
|
+
}));
|
|
1013
|
+
}, !Q.thisProgram && process.argv.length > 1 && process.argv[1].replace(/\\/g, "/"), process.argv.slice(2), "undefined" != typeof module && (module.exports = Q), process.on("uncaughtException", (function(A2) {
|
|
1014
|
+
if (!("unwind" === A2 || A2 instanceof p || A2.context instanceof p)) throw A2;
|
|
1015
|
+
})), E = function(A2, I3) {
|
|
1016
|
+
throw process.exitCode = A2, I3;
|
|
1017
|
+
}, Q.inspect = function() {
|
|
1018
|
+
return "[Emscripten Module object]";
|
|
1019
|
+
};
|
|
1020
|
+
} else (o || n) && (n ? t = self.location.href : "undefined" != typeof document && document.currentScript && (t = document.currentScript.src), t = 0 !== t.indexOf("blob:") ? t.substr(0, t.replace(/[?#].*/, "").lastIndexOf("/") + 1) : "", C = function(A2) {
|
|
1021
|
+
try {
|
|
1022
|
+
var I3 = new XMLHttpRequest();
|
|
1023
|
+
return I3.open("GET", A2, false), I3.send(null), I3.responseText;
|
|
1024
|
+
} catch (I4) {
|
|
1025
|
+
var g2 = x(A2);
|
|
1026
|
+
if (g2) return (function(A3) {
|
|
1027
|
+
for (var I5 = [], g3 = 0; g3 < A3.length; g3++) {
|
|
1028
|
+
var C3 = A3[g3];
|
|
1029
|
+
C3 > 255 && (C3 &= 255), I5.push(String.fromCharCode(C3));
|
|
1030
|
+
}
|
|
1031
|
+
return I5.join("");
|
|
1032
|
+
})(g2);
|
|
1033
|
+
throw I4;
|
|
1416
1034
|
}
|
|
1417
|
-
|
|
1418
|
-
|
|
1035
|
+
}, n && (B = function(A2) {
|
|
1036
|
+
try {
|
|
1037
|
+
var I3 = new XMLHttpRequest();
|
|
1038
|
+
return I3.open("GET", A2, false), I3.responseType = "arraybuffer", I3.send(null), new Uint8Array(I3.response);
|
|
1039
|
+
} catch (I4) {
|
|
1040
|
+
var g2 = x(A2);
|
|
1041
|
+
if (g2) return g2;
|
|
1042
|
+
throw I4;
|
|
1419
1043
|
}
|
|
1420
|
-
|
|
1044
|
+
}), function(A2, I3, g2) {
|
|
1045
|
+
var C3 = new XMLHttpRequest();
|
|
1046
|
+
C3.open("GET", A2, true), C3.responseType = "arraybuffer", C3.onload = function() {
|
|
1047
|
+
if (200 == C3.status || 0 == C3.status && C3.response) I3(C3.response);
|
|
1048
|
+
else {
|
|
1049
|
+
var B2 = x(A2);
|
|
1050
|
+
B2 ? I3(B2.buffer) : g2();
|
|
1051
|
+
}
|
|
1052
|
+
}, C3.onerror = g2, C3.send(null);
|
|
1053
|
+
}, function(A2) {
|
|
1054
|
+
return document.title = A2;
|
|
1421
1055
|
});
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
throw
|
|
1056
|
+
Q.print || console.log.bind(console);
|
|
1057
|
+
var f, D = Q.printErr || console.error.bind(console);
|
|
1058
|
+
Object.assign(Q, i), i = null, Q.arguments && Q.arguments, Q.thisProgram && Q.thisProgram, Q.quit && (E = Q.quit), Q.wasmBinary && (f = Q.wasmBinary);
|
|
1059
|
+
var c, G = Q.noExitRuntime || true;
|
|
1060
|
+
"object" != ("undefined" == typeof WebAssembly ? "undefined" : g(WebAssembly)) && U("no native wasm support detected");
|
|
1061
|
+
var h, y, u, s, F = false;
|
|
1062
|
+
var Y = [], N = [], w = [];
|
|
1063
|
+
var S = 0, k = null, H = null;
|
|
1064
|
+
function U(A2) {
|
|
1065
|
+
throw Q.onAbort && Q.onAbort(A2), D(A2 = "Aborted(" + A2 + ")"), F = true, 1, A2 += ". Build with -sASSERTIONS for more info.", new WebAssembly.RuntimeError(A2);
|
|
1432
1066
|
}
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
await this.registerKey(newKeyId, newKeypair, oldKey.meta.suiteId, {
|
|
1437
|
-
usage: oldKey.meta.usage,
|
|
1438
|
-
cryptoProfileVersion: oldKey.meta.cryptoProfileVersion,
|
|
1439
|
-
expiresAt: oldKey.meta.expiresAt,
|
|
1440
|
-
status: "active"
|
|
1441
|
-
});
|
|
1442
|
-
await this.storage.updateMeta(newKeyId, {
|
|
1443
|
-
rotatedFrom: oldKeyId
|
|
1444
|
-
});
|
|
1445
|
-
const result = await this.storage.load(newKeyId);
|
|
1446
|
-
return result.meta;
|
|
1447
|
-
}
|
|
1448
|
-
/**
|
|
1449
|
-
* Revoke a key (marks as unusable, but doesn't delete).
|
|
1450
|
-
*/
|
|
1451
|
-
async revokeKey(keyId, reason) {
|
|
1452
|
-
await this.storage.updateMeta(keyId, {
|
|
1453
|
-
status: "revoked",
|
|
1454
|
-
revokedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1455
|
-
});
|
|
1456
|
-
}
|
|
1457
|
-
/**
|
|
1458
|
-
* Delete a key permanently (use with caution).
|
|
1459
|
-
*/
|
|
1460
|
-
async deleteKey(keyId) {
|
|
1461
|
-
await this.storage.delete(keyId);
|
|
1462
|
-
}
|
|
1463
|
-
/**
|
|
1464
|
-
* Mark expired keys as 'expired' status.
|
|
1465
|
-
* Returns count of keys marked expired.
|
|
1466
|
-
*/
|
|
1467
|
-
async markExpiredKeys() {
|
|
1468
|
-
const allKeys = await this.storage.list();
|
|
1469
|
-
const now = /* @__PURE__ */ new Date();
|
|
1470
|
-
let count = 0;
|
|
1471
|
-
for (const meta of allKeys) {
|
|
1472
|
-
if (meta.expiresAt && new Date(meta.expiresAt) < now && meta.status === "active") {
|
|
1473
|
-
await this.storage.updateMeta(meta.keyId, {
|
|
1474
|
-
status: "expired"
|
|
1475
|
-
});
|
|
1476
|
-
count++;
|
|
1477
|
-
}
|
|
1067
|
+
var R, d, M = "data:application/octet-stream;base64,";
|
|
1068
|
+
function J(A2) {
|
|
1069
|
+
return A2.startsWith(M);
|
|
1478
1070
|
}
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
/**
|
|
1482
|
-
* Cleanup: delete keys that have been revoked/expired for longer than retention period.
|
|
1483
|
-
*
|
|
1484
|
-
* @param retentionDays How many days to keep revoked/expired keys (default: 90)
|
|
1485
|
-
*/
|
|
1486
|
-
async pruneOldKeys(retentionDays = 90) {
|
|
1487
|
-
const allKeys = await this.storage.list();
|
|
1488
|
-
const cutoffDate = /* @__PURE__ */ new Date();
|
|
1489
|
-
cutoffDate.setDate(cutoffDate.getDate() - retentionDays);
|
|
1490
|
-
let count = 0;
|
|
1491
|
-
for (const meta of allKeys) {
|
|
1492
|
-
const shouldPrune = meta.status === "revoked" && meta.revokedAt && new Date(meta.revokedAt) < cutoffDate || meta.status === "expired" && meta.expiresAt && new Date(meta.expiresAt) < cutoffDate;
|
|
1493
|
-
if (shouldPrune) {
|
|
1494
|
-
await this.storage.delete(meta.keyId);
|
|
1495
|
-
count++;
|
|
1496
|
-
}
|
|
1497
|
-
}
|
|
1498
|
-
return count;
|
|
1499
|
-
}
|
|
1500
|
-
};
|
|
1501
|
-
exports2.KeyRegistry = KeyRegistry3;
|
|
1502
|
-
}
|
|
1503
|
-
});
|
|
1504
|
-
|
|
1505
|
-
// ../crypto/dist/errors.js
|
|
1506
|
-
var require_errors = __commonJS({
|
|
1507
|
-
"../crypto/dist/errors.js"(exports2) {
|
|
1508
|
-
"use strict";
|
|
1509
|
-
init_esbuild_shims();
|
|
1510
|
-
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
1511
|
-
exports2.ComplianceViolationError = exports2.InvalidKeyParametersError = exports2.CryptoOperationError = exports2.InvalidSignatureError = exports2.SuiteNotFoundError = exports2.SuiteNotAllowedError = exports2.KeyInvalidStateError = exports2.KeyExpiredError = exports2.KeyNotFoundError = exports2.SmartLedgerCryptoError = void 0;
|
|
1512
|
-
var SmartLedgerCryptoError = class extends Error {
|
|
1513
|
-
constructor(message, code) {
|
|
1514
|
-
super(message);
|
|
1515
|
-
__publicField(this, "code");
|
|
1516
|
-
this.code = code;
|
|
1517
|
-
this.name = this.constructor.name;
|
|
1518
|
-
Error.captureStackTrace(this, this.constructor);
|
|
1519
|
-
}
|
|
1520
|
-
};
|
|
1521
|
-
exports2.SmartLedgerCryptoError = SmartLedgerCryptoError;
|
|
1522
|
-
var KeyNotFoundError = class extends SmartLedgerCryptoError {
|
|
1523
|
-
constructor(keyId) {
|
|
1524
|
-
super(`Key not found: ${keyId}`, "KEY_NOT_FOUND");
|
|
1525
|
-
__publicField(this, "keyId");
|
|
1526
|
-
this.keyId = keyId;
|
|
1527
|
-
}
|
|
1528
|
-
};
|
|
1529
|
-
exports2.KeyNotFoundError = KeyNotFoundError;
|
|
1530
|
-
var KeyExpiredError = class extends SmartLedgerCryptoError {
|
|
1531
|
-
constructor(keyId, expiresAt) {
|
|
1532
|
-
super(`Key expired: ${keyId} (expired at ${expiresAt})`, "KEY_EXPIRED");
|
|
1533
|
-
__publicField(this, "keyId");
|
|
1534
|
-
__publicField(this, "expiresAt");
|
|
1535
|
-
this.keyId = keyId;
|
|
1536
|
-
this.expiresAt = expiresAt;
|
|
1537
|
-
}
|
|
1538
|
-
};
|
|
1539
|
-
exports2.KeyExpiredError = KeyExpiredError;
|
|
1540
|
-
var KeyInvalidStateError = class extends SmartLedgerCryptoError {
|
|
1541
|
-
constructor(keyId, currentState, requiredState) {
|
|
1542
|
-
super(`Key in invalid state: ${keyId} (current: ${currentState}, required: ${requiredState})`, "KEY_INVALID_STATE");
|
|
1543
|
-
__publicField(this, "keyId");
|
|
1544
|
-
__publicField(this, "currentState");
|
|
1545
|
-
__publicField(this, "requiredState");
|
|
1546
|
-
this.keyId = keyId;
|
|
1547
|
-
this.currentState = currentState;
|
|
1548
|
-
this.requiredState = requiredState;
|
|
1549
|
-
}
|
|
1550
|
-
};
|
|
1551
|
-
exports2.KeyInvalidStateError = KeyInvalidStateError;
|
|
1552
|
-
var SuiteNotAllowedError = class extends SmartLedgerCryptoError {
|
|
1553
|
-
constructor(suiteId, profileName) {
|
|
1554
|
-
const profileMsg = profileName ? ` in profile ${profileName}` : "";
|
|
1555
|
-
super(`Suite not allowed: ${suiteId}${profileMsg}`, "SUITE_NOT_ALLOWED");
|
|
1556
|
-
__publicField(this, "suiteId");
|
|
1557
|
-
__publicField(this, "profileName");
|
|
1558
|
-
this.suiteId = suiteId;
|
|
1559
|
-
this.profileName = profileName;
|
|
1560
|
-
}
|
|
1561
|
-
};
|
|
1562
|
-
exports2.SuiteNotAllowedError = SuiteNotAllowedError;
|
|
1563
|
-
var SuiteNotFoundError = class extends SmartLedgerCryptoError {
|
|
1564
|
-
constructor(suiteId) {
|
|
1565
|
-
super(`Suite not found: ${suiteId}`, "SUITE_NOT_FOUND");
|
|
1566
|
-
__publicField(this, "suiteId");
|
|
1567
|
-
this.suiteId = suiteId;
|
|
1568
|
-
}
|
|
1569
|
-
};
|
|
1570
|
-
exports2.SuiteNotFoundError = SuiteNotFoundError;
|
|
1571
|
-
var InvalidSignatureError = class extends SmartLedgerCryptoError {
|
|
1572
|
-
constructor(keyId, message = "Signature verification failed") {
|
|
1573
|
-
super(message, "INVALID_SIGNATURE");
|
|
1574
|
-
__publicField(this, "keyId");
|
|
1575
|
-
this.keyId = keyId;
|
|
1576
|
-
}
|
|
1577
|
-
};
|
|
1578
|
-
exports2.InvalidSignatureError = InvalidSignatureError;
|
|
1579
|
-
var CryptoOperationError = class extends SmartLedgerCryptoError {
|
|
1580
|
-
constructor(operation, message, cause) {
|
|
1581
|
-
super(`Cryptographic operation failed (${operation}): ${message}`, "CRYPTO_OPERATION_FAILED");
|
|
1582
|
-
__publicField(this, "operation");
|
|
1583
|
-
__publicField(this, "cause");
|
|
1584
|
-
this.operation = operation;
|
|
1585
|
-
this.cause = cause;
|
|
1586
|
-
}
|
|
1587
|
-
};
|
|
1588
|
-
exports2.CryptoOperationError = CryptoOperationError;
|
|
1589
|
-
var InvalidKeyParametersError = class extends SmartLedgerCryptoError {
|
|
1590
|
-
constructor(message) {
|
|
1591
|
-
super(`Invalid key parameters: ${message}`, "INVALID_KEY_PARAMETERS");
|
|
1592
|
-
}
|
|
1593
|
-
};
|
|
1594
|
-
exports2.InvalidKeyParametersError = InvalidKeyParametersError;
|
|
1595
|
-
var ComplianceViolationError = class extends SmartLedgerCryptoError {
|
|
1596
|
-
constructor(profileName, violation) {
|
|
1597
|
-
super(`Compliance violation in profile ${profileName}: ${violation}`, "COMPLIANCE_VIOLATION");
|
|
1598
|
-
__publicField(this, "profileName");
|
|
1599
|
-
__publicField(this, "violation");
|
|
1600
|
-
this.profileName = profileName;
|
|
1601
|
-
this.violation = violation;
|
|
1602
|
-
}
|
|
1603
|
-
};
|
|
1604
|
-
exports2.ComplianceViolationError = ComplianceViolationError;
|
|
1605
|
-
}
|
|
1606
|
-
});
|
|
1607
|
-
|
|
1608
|
-
// ../crypto/dist/stateless.js
|
|
1609
|
-
var require_stateless = __commonJS({
|
|
1610
|
-
"../crypto/dist/stateless.js"(exports2) {
|
|
1611
|
-
"use strict";
|
|
1612
|
-
init_esbuild_shims();
|
|
1613
|
-
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
1614
|
-
exports2.setGlobalRegistry = setGlobalRegistry;
|
|
1615
|
-
exports2.signUsingSuite = signUsingSuite;
|
|
1616
|
-
exports2.verifyUsingSuite = verifyUsingSuite;
|
|
1617
|
-
exports2.generateKeypairUsingSuite = generateKeypairUsingSuite;
|
|
1618
|
-
exports2.listAvailableSuites = listAvailableSuites;
|
|
1619
|
-
var registry_js_1 = require_registry();
|
|
1620
|
-
var errors_js_1 = require_errors();
|
|
1621
|
-
var globalRegistry = null;
|
|
1622
|
-
function setGlobalRegistry(registry) {
|
|
1623
|
-
globalRegistry = registry;
|
|
1624
|
-
}
|
|
1625
|
-
function getRegistry() {
|
|
1626
|
-
if (!globalRegistry) {
|
|
1627
|
-
globalRegistry = new registry_js_1.SignatureSuiteRegistry();
|
|
1628
|
-
}
|
|
1629
|
-
return globalRegistry;
|
|
1630
|
-
}
|
|
1631
|
-
async function signUsingSuite(suiteId, privateKey, message) {
|
|
1632
|
-
const registry = getRegistry();
|
|
1633
|
-
if (!registry.hasSuite(suiteId)) {
|
|
1634
|
-
throw new errors_js_1.SuiteNotFoundError(suiteId);
|
|
1635
|
-
}
|
|
1636
|
-
try {
|
|
1637
|
-
const suite = registry.getSuite(suiteId);
|
|
1638
|
-
return await suite.sign(privateKey, message);
|
|
1639
|
-
} catch (error) {
|
|
1640
|
-
throw new errors_js_1.CryptoOperationError("sign", error instanceof Error ? error.message : "Unknown error", error instanceof Error ? error : void 0);
|
|
1641
|
-
}
|
|
1642
|
-
}
|
|
1643
|
-
async function verifyUsingSuite(suiteId, publicKey, message, signature) {
|
|
1644
|
-
const registry = getRegistry();
|
|
1645
|
-
if (!registry.hasSuite(suiteId)) {
|
|
1646
|
-
throw new errors_js_1.SuiteNotFoundError(suiteId);
|
|
1647
|
-
}
|
|
1648
|
-
try {
|
|
1649
|
-
const suite = registry.getSuite(suiteId);
|
|
1650
|
-
return await suite.verify(publicKey, message, signature);
|
|
1651
|
-
} catch (error) {
|
|
1652
|
-
throw new errors_js_1.CryptoOperationError("verify", error instanceof Error ? error.message : "Unknown error", error instanceof Error ? error : void 0);
|
|
1653
|
-
}
|
|
1654
|
-
}
|
|
1655
|
-
async function generateKeypairUsingSuite(suiteId) {
|
|
1656
|
-
const registry = getRegistry();
|
|
1657
|
-
if (!registry.hasSuite(suiteId)) {
|
|
1658
|
-
throw new errors_js_1.SuiteNotFoundError(suiteId);
|
|
1659
|
-
}
|
|
1660
|
-
try {
|
|
1661
|
-
const suite = registry.getSuite(suiteId);
|
|
1662
|
-
return await suite.generateKeypair();
|
|
1663
|
-
} catch (error) {
|
|
1664
|
-
throw new errors_js_1.CryptoOperationError("generateKeypair", error instanceof Error ? error.message : "Unknown error", error instanceof Error ? error : void 0);
|
|
1665
|
-
}
|
|
1666
|
-
}
|
|
1667
|
-
function listAvailableSuites() {
|
|
1668
|
-
const registry = getRegistry();
|
|
1669
|
-
return registry.listSuites();
|
|
1670
|
-
}
|
|
1671
|
-
}
|
|
1672
|
-
});
|
|
1673
|
-
|
|
1674
|
-
// ../../node_modules/@noble/secp256k1/index.js
|
|
1675
|
-
var secp256k1_exports = {};
|
|
1676
|
-
__export(secp256k1_exports, {
|
|
1677
|
-
CURVE: () => secp256k1_CURVE,
|
|
1678
|
-
Point: () => Point,
|
|
1679
|
-
ProjectivePoint: () => Point,
|
|
1680
|
-
Signature: () => Signature,
|
|
1681
|
-
etc: () => etc,
|
|
1682
|
-
getPublicKey: () => getPublicKey,
|
|
1683
|
-
getSharedSecret: () => getSharedSecret,
|
|
1684
|
-
sign: () => sign,
|
|
1685
|
-
signAsync: () => signAsync,
|
|
1686
|
-
utils: () => utils,
|
|
1687
|
-
verify: () => verify
|
|
1688
|
-
});
|
|
1689
|
-
var secp256k1_CURVE, P2, N2, Gx, Gy, _b, L2, L22, err, isBig, isStr, isBytes2, abytes2, u8n, u8fr, padh, bytesToHex, C2, _ch, hexToBytes, toU8, cr, subtle, concatBytes, randomBytes, big, arange, M2, modN, invert, callHash, apoint, koblitz, afield0, afield, agroup, isEven, u8of, getPrefix, lift_x, _Point, Point, G2, I2, doubleScalarMulUns, bytesToNumBE, sliceBytesNumBE, B256, numTo32b, toPrivScalar, highS, getPublicKey, Signature, bits2int, bits2int_modN, signOpts, veriOpts, prepSig, hmacDrbg, signAsync, sign, verify, recoverPublicKey, getSharedSecret, hashToPrivateKey, randomPrivateKey, _sha, etc, utils, W2, scalarBits, pwindows, pwindowSize, precompute, Gpows, ctneg, wNAF;
|
|
1690
|
-
var init_secp256k1 = __esm({
|
|
1691
|
-
"../../node_modules/@noble/secp256k1/index.js"() {
|
|
1692
|
-
init_esbuild_shims();
|
|
1693
|
-
secp256k1_CURVE = {
|
|
1694
|
-
p: 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2fn,
|
|
1695
|
-
n: 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n,
|
|
1696
|
-
h: 1n,
|
|
1697
|
-
a: 0n,
|
|
1698
|
-
b: 7n,
|
|
1699
|
-
Gx: 0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n,
|
|
1700
|
-
Gy: 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n
|
|
1701
|
-
};
|
|
1702
|
-
({ p: P2, n: N2, Gx, Gy, b: _b } = secp256k1_CURVE);
|
|
1703
|
-
L2 = 32;
|
|
1704
|
-
L22 = 64;
|
|
1705
|
-
err = (m2 = "") => {
|
|
1706
|
-
throw new Error(m2);
|
|
1707
|
-
};
|
|
1708
|
-
isBig = (n2) => typeof n2 === "bigint";
|
|
1709
|
-
isStr = (s2) => typeof s2 === "string";
|
|
1710
|
-
isBytes2 = (a2) => a2 instanceof Uint8Array || ArrayBuffer.isView(a2) && a2.constructor.name === "Uint8Array";
|
|
1711
|
-
abytes2 = (a2, l2) => !isBytes2(a2) || typeof l2 === "number" && l2 > 0 && a2.length !== l2 ? err("Uint8Array expected") : a2;
|
|
1712
|
-
u8n = (len) => new Uint8Array(len);
|
|
1713
|
-
u8fr = (buf) => Uint8Array.from(buf);
|
|
1714
|
-
padh = (n2, pad) => n2.toString(16).padStart(pad, "0");
|
|
1715
|
-
bytesToHex = (b2) => Array.from(abytes2(b2)).map((e2) => padh(e2, 2)).join("");
|
|
1716
|
-
C2 = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
|
|
1717
|
-
_ch = (ch) => {
|
|
1718
|
-
if (ch >= C2._0 && ch <= C2._9)
|
|
1719
|
-
return ch - C2._0;
|
|
1720
|
-
if (ch >= C2.A && ch <= C2.F)
|
|
1721
|
-
return ch - (C2.A - 10);
|
|
1722
|
-
if (ch >= C2.a && ch <= C2.f)
|
|
1723
|
-
return ch - (C2.a - 10);
|
|
1724
|
-
return;
|
|
1725
|
-
};
|
|
1726
|
-
hexToBytes = (hex) => {
|
|
1727
|
-
const e2 = "hex invalid";
|
|
1728
|
-
if (!isStr(hex))
|
|
1729
|
-
return err(e2);
|
|
1730
|
-
const hl = hex.length;
|
|
1731
|
-
const al = hl / 2;
|
|
1732
|
-
if (hl % 2)
|
|
1733
|
-
return err(e2);
|
|
1734
|
-
const array = u8n(al);
|
|
1735
|
-
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
1736
|
-
const n1 = _ch(hex.charCodeAt(hi));
|
|
1737
|
-
const n2 = _ch(hex.charCodeAt(hi + 1));
|
|
1738
|
-
if (n1 === void 0 || n2 === void 0)
|
|
1739
|
-
return err(e2);
|
|
1740
|
-
array[ai] = n1 * 16 + n2;
|
|
1741
|
-
}
|
|
1742
|
-
return array;
|
|
1743
|
-
};
|
|
1744
|
-
toU8 = (a2, len) => abytes2(isStr(a2) ? hexToBytes(a2) : u8fr(abytes2(a2)), len);
|
|
1745
|
-
cr = () => globalThis?.crypto;
|
|
1746
|
-
subtle = () => cr()?.subtle ?? err("crypto.subtle must be defined");
|
|
1747
|
-
concatBytes = (...arrs) => {
|
|
1748
|
-
const r2 = u8n(arrs.reduce((sum, a2) => sum + abytes2(a2).length, 0));
|
|
1749
|
-
let pad = 0;
|
|
1750
|
-
arrs.forEach((a2) => {
|
|
1751
|
-
r2.set(a2, pad);
|
|
1752
|
-
pad += a2.length;
|
|
1753
|
-
});
|
|
1754
|
-
return r2;
|
|
1755
|
-
};
|
|
1756
|
-
randomBytes = (len = L2) => {
|
|
1757
|
-
const c2 = cr();
|
|
1758
|
-
return c2.getRandomValues(u8n(len));
|
|
1759
|
-
};
|
|
1760
|
-
big = BigInt;
|
|
1761
|
-
arange = (n2, min, max, msg = "bad number: out of range") => isBig(n2) && min <= n2 && n2 < max ? n2 : err(msg);
|
|
1762
|
-
M2 = (a2, b2 = P2) => {
|
|
1763
|
-
const r2 = a2 % b2;
|
|
1764
|
-
return r2 >= 0n ? r2 : b2 + r2;
|
|
1765
|
-
};
|
|
1766
|
-
modN = (a2) => M2(a2, N2);
|
|
1767
|
-
invert = (num, md) => {
|
|
1768
|
-
if (num === 0n || md <= 0n)
|
|
1769
|
-
err("no inverse n=" + num + " mod=" + md);
|
|
1770
|
-
let a2 = M2(num, md), b2 = md, x2 = 0n, y2 = 1n, u2 = 1n, v2 = 0n;
|
|
1771
|
-
while (a2 !== 0n) {
|
|
1772
|
-
const q2 = b2 / a2, r2 = b2 % a2;
|
|
1773
|
-
const m2 = x2 - u2 * q2, n2 = y2 - v2 * q2;
|
|
1774
|
-
b2 = a2, a2 = r2, x2 = u2, y2 = v2, u2 = m2, v2 = n2;
|
|
1775
|
-
}
|
|
1776
|
-
return b2 === 1n ? M2(x2, md) : err("no inverse");
|
|
1777
|
-
};
|
|
1778
|
-
callHash = (name) => {
|
|
1779
|
-
const fn = etc[name];
|
|
1780
|
-
if (typeof fn !== "function")
|
|
1781
|
-
err("hashes." + name + " not set");
|
|
1782
|
-
return fn;
|
|
1783
|
-
};
|
|
1784
|
-
apoint = (p2) => p2 instanceof Point ? p2 : err("Point expected");
|
|
1785
|
-
koblitz = (x2) => M2(M2(x2 * x2) * x2 + _b);
|
|
1786
|
-
afield0 = (n2) => arange(n2, 0n, P2);
|
|
1787
|
-
afield = (n2) => arange(n2, 1n, P2);
|
|
1788
|
-
agroup = (n2) => arange(n2, 1n, N2);
|
|
1789
|
-
isEven = (y2) => (y2 & 1n) === 0n;
|
|
1790
|
-
u8of = (n2) => Uint8Array.of(n2);
|
|
1791
|
-
getPrefix = (y2) => u8of(isEven(y2) ? 2 : 3);
|
|
1792
|
-
lift_x = (x2) => {
|
|
1793
|
-
const c2 = koblitz(afield(x2));
|
|
1794
|
-
let r2 = 1n;
|
|
1795
|
-
for (let num = c2, e2 = (P2 + 1n) / 4n; e2 > 0n; e2 >>= 1n) {
|
|
1796
|
-
if (e2 & 1n)
|
|
1797
|
-
r2 = r2 * num % P2;
|
|
1798
|
-
num = num * num % P2;
|
|
1799
|
-
}
|
|
1800
|
-
return M2(r2 * r2) === c2 ? r2 : err("sqrt invalid");
|
|
1801
|
-
};
|
|
1802
|
-
_Point = class _Point {
|
|
1803
|
-
constructor(px, py, pz) {
|
|
1804
|
-
__publicField(this, "px");
|
|
1805
|
-
__publicField(this, "py");
|
|
1806
|
-
__publicField(this, "pz");
|
|
1807
|
-
this.px = afield0(px);
|
|
1808
|
-
this.py = afield(py);
|
|
1809
|
-
this.pz = afield0(pz);
|
|
1810
|
-
Object.freeze(this);
|
|
1811
|
-
}
|
|
1812
|
-
/** Convert Uint8Array or hex string to Point. */
|
|
1813
|
-
static fromBytes(bytes) {
|
|
1814
|
-
abytes2(bytes);
|
|
1815
|
-
let p2 = void 0;
|
|
1816
|
-
const head = bytes[0];
|
|
1817
|
-
const tail = bytes.subarray(1);
|
|
1818
|
-
const x2 = sliceBytesNumBE(tail, 0, L2);
|
|
1819
|
-
const len = bytes.length;
|
|
1820
|
-
if (len === L2 + 1 && [2, 3].includes(head)) {
|
|
1821
|
-
let y2 = lift_x(x2);
|
|
1822
|
-
const evenY = isEven(y2);
|
|
1823
|
-
const evenH = isEven(big(head));
|
|
1824
|
-
if (evenH !== evenY)
|
|
1825
|
-
y2 = M2(-y2);
|
|
1826
|
-
p2 = new _Point(x2, y2, 1n);
|
|
1827
|
-
}
|
|
1828
|
-
if (len === L22 + 1 && head === 4)
|
|
1829
|
-
p2 = new _Point(x2, sliceBytesNumBE(tail, L2, L22), 1n);
|
|
1830
|
-
return p2 ? p2.assertValidity() : err("bad point: not on curve");
|
|
1831
|
-
}
|
|
1832
|
-
/** Equality check: compare points P&Q. */
|
|
1833
|
-
equals(other) {
|
|
1834
|
-
const { px: X1, py: Y1, pz: Z1 } = this;
|
|
1835
|
-
const { px: X2, py: Y2, pz: Z2 } = apoint(other);
|
|
1836
|
-
const X1Z2 = M2(X1 * Z2);
|
|
1837
|
-
const X2Z1 = M2(X2 * Z1);
|
|
1838
|
-
const Y1Z2 = M2(Y1 * Z2);
|
|
1839
|
-
const Y2Z1 = M2(Y2 * Z1);
|
|
1840
|
-
return X1Z2 === X2Z1 && Y1Z2 === Y2Z1;
|
|
1841
|
-
}
|
|
1842
|
-
is0() {
|
|
1843
|
-
return this.equals(I2);
|
|
1844
|
-
}
|
|
1845
|
-
/** Flip point over y coordinate. */
|
|
1846
|
-
negate() {
|
|
1847
|
-
return new _Point(this.px, M2(-this.py), this.pz);
|
|
1848
|
-
}
|
|
1849
|
-
/** Point doubling: P+P, complete formula. */
|
|
1850
|
-
double() {
|
|
1851
|
-
return this.add(this);
|
|
1852
|
-
}
|
|
1853
|
-
/**
|
|
1854
|
-
* Point addition: P+Q, complete, exception-free formula
|
|
1855
|
-
* (Renes-Costello-Batina, algo 1 of [2015/1060](https://eprint.iacr.org/2015/1060)).
|
|
1856
|
-
* Cost: `12M + 0S + 3*a + 3*b3 + 23add`.
|
|
1857
|
-
*/
|
|
1858
|
-
// prettier-ignore
|
|
1859
|
-
add(other) {
|
|
1860
|
-
const { px: X1, py: Y1, pz: Z1 } = this;
|
|
1861
|
-
const { px: X2, py: Y2, pz: Z2 } = apoint(other);
|
|
1862
|
-
const a2 = 0n;
|
|
1863
|
-
const b2 = _b;
|
|
1864
|
-
let X3 = 0n, Y3 = 0n, Z3 = 0n;
|
|
1865
|
-
const b3 = M2(b2 * 3n);
|
|
1866
|
-
let t0 = M2(X1 * X2), t1 = M2(Y1 * Y2), t2 = M2(Z1 * Z2), t3 = M2(X1 + Y1);
|
|
1867
|
-
let t4 = M2(X2 + Y2);
|
|
1868
|
-
t3 = M2(t3 * t4);
|
|
1869
|
-
t4 = M2(t0 + t1);
|
|
1870
|
-
t3 = M2(t3 - t4);
|
|
1871
|
-
t4 = M2(X1 + Z1);
|
|
1872
|
-
let t5 = M2(X2 + Z2);
|
|
1873
|
-
t4 = M2(t4 * t5);
|
|
1874
|
-
t5 = M2(t0 + t2);
|
|
1875
|
-
t4 = M2(t4 - t5);
|
|
1876
|
-
t5 = M2(Y1 + Z1);
|
|
1877
|
-
X3 = M2(Y2 + Z2);
|
|
1878
|
-
t5 = M2(t5 * X3);
|
|
1879
|
-
X3 = M2(t1 + t2);
|
|
1880
|
-
t5 = M2(t5 - X3);
|
|
1881
|
-
Z3 = M2(a2 * t4);
|
|
1882
|
-
X3 = M2(b3 * t2);
|
|
1883
|
-
Z3 = M2(X3 + Z3);
|
|
1884
|
-
X3 = M2(t1 - Z3);
|
|
1885
|
-
Z3 = M2(t1 + Z3);
|
|
1886
|
-
Y3 = M2(X3 * Z3);
|
|
1887
|
-
t1 = M2(t0 + t0);
|
|
1888
|
-
t1 = M2(t1 + t0);
|
|
1889
|
-
t2 = M2(a2 * t2);
|
|
1890
|
-
t4 = M2(b3 * t4);
|
|
1891
|
-
t1 = M2(t1 + t2);
|
|
1892
|
-
t2 = M2(t0 - t2);
|
|
1893
|
-
t2 = M2(a2 * t2);
|
|
1894
|
-
t4 = M2(t4 + t2);
|
|
1895
|
-
t0 = M2(t1 * t4);
|
|
1896
|
-
Y3 = M2(Y3 + t0);
|
|
1897
|
-
t0 = M2(t5 * t4);
|
|
1898
|
-
X3 = M2(t3 * X3);
|
|
1899
|
-
X3 = M2(X3 - t0);
|
|
1900
|
-
t0 = M2(t3 * t1);
|
|
1901
|
-
Z3 = M2(t5 * Z3);
|
|
1902
|
-
Z3 = M2(Z3 + t0);
|
|
1903
|
-
return new _Point(X3, Y3, Z3);
|
|
1904
|
-
}
|
|
1905
|
-
/**
|
|
1906
|
-
* Point-by-scalar multiplication. Scalar must be in range 1 <= n < CURVE.n.
|
|
1907
|
-
* Uses {@link wNAF} for base point.
|
|
1908
|
-
* Uses fake point to mitigate side-channel leakage.
|
|
1909
|
-
* @param n scalar by which point is multiplied
|
|
1910
|
-
* @param safe safe mode guards against timing attacks; unsafe mode is faster
|
|
1911
|
-
*/
|
|
1912
|
-
multiply(n2, safe = true) {
|
|
1913
|
-
if (!safe && n2 === 0n)
|
|
1914
|
-
return I2;
|
|
1915
|
-
agroup(n2);
|
|
1916
|
-
if (n2 === 1n)
|
|
1917
|
-
return this;
|
|
1918
|
-
if (this.equals(G2))
|
|
1919
|
-
return wNAF(n2).p;
|
|
1920
|
-
let p2 = I2;
|
|
1921
|
-
let f2 = G2;
|
|
1922
|
-
for (let d2 = this; n2 > 0n; d2 = d2.double(), n2 >>= 1n) {
|
|
1923
|
-
if (n2 & 1n)
|
|
1924
|
-
p2 = p2.add(d2);
|
|
1925
|
-
else if (safe)
|
|
1926
|
-
f2 = f2.add(d2);
|
|
1927
|
-
}
|
|
1928
|
-
return p2;
|
|
1929
|
-
}
|
|
1930
|
-
/** Convert point to 2d xy affine point. (X, Y, Z) ∋ (x=X/Z, y=Y/Z) */
|
|
1931
|
-
toAffine() {
|
|
1932
|
-
const { px: x2, py: y2, pz: z } = this;
|
|
1933
|
-
if (this.equals(I2))
|
|
1934
|
-
return { x: 0n, y: 0n };
|
|
1935
|
-
if (z === 1n)
|
|
1936
|
-
return { x: x2, y: y2 };
|
|
1937
|
-
const iz = invert(z, P2);
|
|
1938
|
-
if (M2(z * iz) !== 1n)
|
|
1939
|
-
err("inverse invalid");
|
|
1940
|
-
return { x: M2(x2 * iz), y: M2(y2 * iz) };
|
|
1941
|
-
}
|
|
1942
|
-
/** Checks if the point is valid and on-curve. */
|
|
1943
|
-
assertValidity() {
|
|
1944
|
-
const { x: x2, y: y2 } = this.toAffine();
|
|
1945
|
-
afield(x2);
|
|
1946
|
-
afield(y2);
|
|
1947
|
-
return M2(y2 * y2) === koblitz(x2) ? this : err("bad point: not on curve");
|
|
1948
|
-
}
|
|
1949
|
-
/** Converts point to 33/65-byte Uint8Array. */
|
|
1950
|
-
toBytes(isCompressed = true) {
|
|
1951
|
-
const { x: x2, y: y2 } = this.assertValidity().toAffine();
|
|
1952
|
-
const x32b = numTo32b(x2);
|
|
1953
|
-
if (isCompressed)
|
|
1954
|
-
return concatBytes(getPrefix(y2), x32b);
|
|
1955
|
-
return concatBytes(u8of(4), x32b, numTo32b(y2));
|
|
1956
|
-
}
|
|
1957
|
-
/** Create 3d xyz point from 2d xy. (0, 0) => (0, 1, 0), not (0, 0, 1) */
|
|
1958
|
-
static fromAffine(ap) {
|
|
1959
|
-
const { x: x2, y: y2 } = ap;
|
|
1960
|
-
return x2 === 0n && y2 === 0n ? I2 : new _Point(x2, y2, 1n);
|
|
1961
|
-
}
|
|
1962
|
-
toHex(isCompressed) {
|
|
1963
|
-
return bytesToHex(this.toBytes(isCompressed));
|
|
1964
|
-
}
|
|
1965
|
-
static fromPrivateKey(k2) {
|
|
1966
|
-
return G2.multiply(toPrivScalar(k2));
|
|
1967
|
-
}
|
|
1968
|
-
static fromHex(hex) {
|
|
1969
|
-
return _Point.fromBytes(toU8(hex));
|
|
1970
|
-
}
|
|
1971
|
-
get x() {
|
|
1972
|
-
return this.toAffine().x;
|
|
1973
|
-
}
|
|
1974
|
-
get y() {
|
|
1975
|
-
return this.toAffine().y;
|
|
1976
|
-
}
|
|
1977
|
-
toRawBytes(isCompressed) {
|
|
1978
|
-
return this.toBytes(isCompressed);
|
|
1979
|
-
}
|
|
1980
|
-
};
|
|
1981
|
-
__publicField(_Point, "BASE");
|
|
1982
|
-
__publicField(_Point, "ZERO");
|
|
1983
|
-
Point = _Point;
|
|
1984
|
-
G2 = new Point(Gx, Gy, 1n);
|
|
1985
|
-
I2 = new Point(0n, 1n, 0n);
|
|
1986
|
-
Point.BASE = G2;
|
|
1987
|
-
Point.ZERO = I2;
|
|
1988
|
-
doubleScalarMulUns = (R2, u1, u2) => {
|
|
1989
|
-
return G2.multiply(u1, false).add(R2.multiply(u2, false)).assertValidity();
|
|
1990
|
-
};
|
|
1991
|
-
bytesToNumBE = (b2) => big("0x" + (bytesToHex(b2) || "0"));
|
|
1992
|
-
sliceBytesNumBE = (b2, from, to) => bytesToNumBE(b2.subarray(from, to));
|
|
1993
|
-
B256 = 2n ** 256n;
|
|
1994
|
-
numTo32b = (num) => hexToBytes(padh(arange(num, 0n, B256), L22));
|
|
1995
|
-
toPrivScalar = (pr) => {
|
|
1996
|
-
const num = isBig(pr) ? pr : bytesToNumBE(toU8(pr, L2));
|
|
1997
|
-
return arange(num, 1n, N2, "private key invalid 3");
|
|
1998
|
-
};
|
|
1999
|
-
highS = (n2) => n2 > N2 >> 1n;
|
|
2000
|
-
getPublicKey = (privKey, isCompressed = true) => {
|
|
2001
|
-
return G2.multiply(toPrivScalar(privKey)).toBytes(isCompressed);
|
|
2002
|
-
};
|
|
2003
|
-
Signature = class _Signature {
|
|
2004
|
-
constructor(r2, s2, recovery) {
|
|
2005
|
-
__publicField(this, "r");
|
|
2006
|
-
__publicField(this, "s");
|
|
2007
|
-
__publicField(this, "recovery");
|
|
2008
|
-
this.r = agroup(r2);
|
|
2009
|
-
this.s = agroup(s2);
|
|
2010
|
-
if (recovery != null)
|
|
2011
|
-
this.recovery = recovery;
|
|
2012
|
-
Object.freeze(this);
|
|
2013
|
-
}
|
|
2014
|
-
/** Create signature from 64b compact (r || s) representation. */
|
|
2015
|
-
static fromBytes(b2) {
|
|
2016
|
-
abytes2(b2, L22);
|
|
2017
|
-
const r2 = sliceBytesNumBE(b2, 0, L2);
|
|
2018
|
-
const s2 = sliceBytesNumBE(b2, L2, L22);
|
|
2019
|
-
return new _Signature(r2, s2);
|
|
2020
|
-
}
|
|
2021
|
-
toBytes() {
|
|
2022
|
-
const { r: r2, s: s2 } = this;
|
|
2023
|
-
return concatBytes(numTo32b(r2), numTo32b(s2));
|
|
2024
|
-
}
|
|
2025
|
-
/** Copy signature, with newly added recovery bit. */
|
|
2026
|
-
addRecoveryBit(bit) {
|
|
2027
|
-
return new _Signature(this.r, this.s, bit);
|
|
2028
|
-
}
|
|
2029
|
-
hasHighS() {
|
|
2030
|
-
return highS(this.s);
|
|
2031
|
-
}
|
|
2032
|
-
toCompactRawBytes() {
|
|
2033
|
-
return this.toBytes();
|
|
2034
|
-
}
|
|
2035
|
-
toCompactHex() {
|
|
2036
|
-
return bytesToHex(this.toBytes());
|
|
2037
|
-
}
|
|
2038
|
-
recoverPublicKey(msg) {
|
|
2039
|
-
return recoverPublicKey(this, msg);
|
|
2040
|
-
}
|
|
2041
|
-
static fromCompact(hex) {
|
|
2042
|
-
return _Signature.fromBytes(toU8(hex, L22));
|
|
2043
|
-
}
|
|
2044
|
-
assertValidity() {
|
|
2045
|
-
return this;
|
|
2046
|
-
}
|
|
2047
|
-
normalizeS() {
|
|
2048
|
-
const { r: r2, s: s2, recovery } = this;
|
|
2049
|
-
return highS(s2) ? new _Signature(r2, modN(-s2), recovery) : this;
|
|
2050
|
-
}
|
|
2051
|
-
};
|
|
2052
|
-
bits2int = (bytes) => {
|
|
2053
|
-
const delta = bytes.length * 8 - 256;
|
|
2054
|
-
if (delta > 1024)
|
|
2055
|
-
err("msg invalid");
|
|
2056
|
-
const num = bytesToNumBE(bytes);
|
|
2057
|
-
return delta > 0 ? num >> big(delta) : num;
|
|
2058
|
-
};
|
|
2059
|
-
bits2int_modN = (bytes) => modN(bits2int(abytes2(bytes)));
|
|
2060
|
-
signOpts = { lowS: true };
|
|
2061
|
-
veriOpts = { lowS: true };
|
|
2062
|
-
prepSig = (msgh, priv, opts = signOpts) => {
|
|
2063
|
-
if (["der", "recovered", "canonical"].some((k2) => k2 in opts))
|
|
2064
|
-
err("option not supported");
|
|
2065
|
-
let { lowS, extraEntropy } = opts;
|
|
2066
|
-
if (lowS == null)
|
|
2067
|
-
lowS = true;
|
|
2068
|
-
const i2o = numTo32b;
|
|
2069
|
-
const h1i = bits2int_modN(toU8(msgh));
|
|
2070
|
-
const h1o = i2o(h1i);
|
|
2071
|
-
const d2 = toPrivScalar(priv);
|
|
2072
|
-
const seed = [i2o(d2), h1o];
|
|
2073
|
-
if (extraEntropy)
|
|
2074
|
-
seed.push(extraEntropy === true ? randomBytes(L2) : toU8(extraEntropy));
|
|
2075
|
-
const m2 = h1i;
|
|
2076
|
-
const k2sig = (kBytes) => {
|
|
2077
|
-
const k2 = bits2int(kBytes);
|
|
2078
|
-
if (!(1n <= k2 && k2 < N2))
|
|
2079
|
-
return;
|
|
2080
|
-
const q2 = G2.multiply(k2).toAffine();
|
|
2081
|
-
const r2 = modN(q2.x);
|
|
2082
|
-
if (r2 === 0n)
|
|
2083
|
-
return;
|
|
2084
|
-
const ik = invert(k2, N2);
|
|
2085
|
-
const s2 = modN(ik * modN(m2 + modN(d2 * r2)));
|
|
2086
|
-
if (s2 === 0n)
|
|
2087
|
-
return;
|
|
2088
|
-
let normS = s2;
|
|
2089
|
-
let recovery = (q2.x === r2 ? 0 : 2) | Number(q2.y & 1n);
|
|
2090
|
-
if (lowS && highS(s2)) {
|
|
2091
|
-
normS = modN(-s2);
|
|
2092
|
-
recovery ^= 1;
|
|
2093
|
-
}
|
|
2094
|
-
return new Signature(r2, normS, recovery);
|
|
2095
|
-
};
|
|
2096
|
-
return { seed: concatBytes(...seed), k2sig };
|
|
2097
|
-
};
|
|
2098
|
-
hmacDrbg = (asynchronous) => {
|
|
2099
|
-
let v2 = u8n(L2);
|
|
2100
|
-
let k2 = u8n(L2);
|
|
2101
|
-
let i2 = 0;
|
|
2102
|
-
const NULL = u8n(0);
|
|
2103
|
-
const reset = () => {
|
|
2104
|
-
v2.fill(1);
|
|
2105
|
-
k2.fill(0);
|
|
2106
|
-
i2 = 0;
|
|
2107
|
-
};
|
|
2108
|
-
const max = 1e3;
|
|
2109
|
-
const _e = "drbg: tried 1000 values";
|
|
2110
|
-
if (asynchronous) {
|
|
2111
|
-
const h2 = (...b2) => etc.hmacSha256Async(k2, v2, ...b2);
|
|
2112
|
-
const reseed = async (seed = NULL) => {
|
|
2113
|
-
k2 = await h2(u8of(0), seed);
|
|
2114
|
-
v2 = await h2();
|
|
2115
|
-
if (seed.length === 0)
|
|
2116
|
-
return;
|
|
2117
|
-
k2 = await h2(u8of(1), seed);
|
|
2118
|
-
v2 = await h2();
|
|
2119
|
-
};
|
|
2120
|
-
const gen = async () => {
|
|
2121
|
-
if (i2++ >= max)
|
|
2122
|
-
err(_e);
|
|
2123
|
-
v2 = await h2();
|
|
2124
|
-
return v2;
|
|
2125
|
-
};
|
|
2126
|
-
return async (seed, pred) => {
|
|
2127
|
-
reset();
|
|
2128
|
-
await reseed(seed);
|
|
2129
|
-
let res = void 0;
|
|
2130
|
-
while (!(res = pred(await gen())))
|
|
2131
|
-
await reseed();
|
|
2132
|
-
reset();
|
|
2133
|
-
return res;
|
|
2134
|
-
};
|
|
2135
|
-
} else {
|
|
2136
|
-
const h2 = (...b2) => callHash("hmacSha256Sync")(k2, v2, ...b2);
|
|
2137
|
-
const reseed = (seed = NULL) => {
|
|
2138
|
-
k2 = h2(u8of(0), seed);
|
|
2139
|
-
v2 = h2();
|
|
2140
|
-
if (seed.length === 0)
|
|
2141
|
-
return;
|
|
2142
|
-
k2 = h2(u8of(1), seed);
|
|
2143
|
-
v2 = h2();
|
|
2144
|
-
};
|
|
2145
|
-
const gen = () => {
|
|
2146
|
-
if (i2++ >= max)
|
|
2147
|
-
err(_e);
|
|
2148
|
-
v2 = h2();
|
|
2149
|
-
return v2;
|
|
2150
|
-
};
|
|
2151
|
-
return (seed, pred) => {
|
|
2152
|
-
reset();
|
|
2153
|
-
reseed(seed);
|
|
2154
|
-
let res = void 0;
|
|
2155
|
-
while (!(res = pred(gen())))
|
|
2156
|
-
reseed();
|
|
2157
|
-
reset();
|
|
2158
|
-
return res;
|
|
2159
|
-
};
|
|
2160
|
-
}
|
|
2161
|
-
};
|
|
2162
|
-
signAsync = async (msgh, priv, opts = signOpts) => {
|
|
2163
|
-
const { seed, k2sig } = prepSig(msgh, priv, opts);
|
|
2164
|
-
const sig = await hmacDrbg(true)(seed, k2sig);
|
|
2165
|
-
return sig;
|
|
2166
|
-
};
|
|
2167
|
-
sign = (msgh, priv, opts = signOpts) => {
|
|
2168
|
-
const { seed, k2sig } = prepSig(msgh, priv, opts);
|
|
2169
|
-
const sig = hmacDrbg(false)(seed, k2sig);
|
|
2170
|
-
return sig;
|
|
2171
|
-
};
|
|
2172
|
-
verify = (sig, msgh, pub, opts = veriOpts) => {
|
|
2173
|
-
let { lowS } = opts;
|
|
2174
|
-
if (lowS == null)
|
|
2175
|
-
lowS = true;
|
|
2176
|
-
if ("strict" in opts)
|
|
2177
|
-
err("option not supported");
|
|
2178
|
-
let sigg;
|
|
2179
|
-
const rs = sig && typeof sig === "object" && "r" in sig;
|
|
2180
|
-
if (!rs && toU8(sig).length !== L22)
|
|
2181
|
-
err("signature must be 64 bytes");
|
|
2182
|
-
try {
|
|
2183
|
-
sigg = rs ? new Signature(sig.r, sig.s) : Signature.fromCompact(sig);
|
|
2184
|
-
const h2 = bits2int_modN(toU8(msgh));
|
|
2185
|
-
const P3 = Point.fromBytes(toU8(pub));
|
|
2186
|
-
const { r: r2, s: s2 } = sigg;
|
|
2187
|
-
if (lowS && highS(s2))
|
|
2188
|
-
return false;
|
|
2189
|
-
const is = invert(s2, N2);
|
|
2190
|
-
const u1 = modN(h2 * is);
|
|
2191
|
-
const u2 = modN(r2 * is);
|
|
2192
|
-
const R2 = doubleScalarMulUns(P3, u1, u2).toAffine();
|
|
2193
|
-
const v2 = modN(R2.x);
|
|
2194
|
-
return v2 === r2;
|
|
2195
|
-
} catch (error) {
|
|
2196
|
-
return false;
|
|
2197
|
-
}
|
|
2198
|
-
};
|
|
2199
|
-
recoverPublicKey = (sig, msgh) => {
|
|
2200
|
-
const { r: r2, s: s2, recovery } = sig;
|
|
2201
|
-
if (![0, 1, 2, 3].includes(recovery))
|
|
2202
|
-
err("recovery id invalid");
|
|
2203
|
-
const h2 = bits2int_modN(toU8(msgh, L2));
|
|
2204
|
-
const radj = recovery === 2 || recovery === 3 ? r2 + N2 : r2;
|
|
2205
|
-
afield(radj);
|
|
2206
|
-
const head = getPrefix(big(recovery));
|
|
2207
|
-
const Rb = concatBytes(head, numTo32b(radj));
|
|
2208
|
-
const R2 = Point.fromBytes(Rb);
|
|
2209
|
-
const ir = invert(radj, N2);
|
|
2210
|
-
const u1 = modN(-h2 * ir);
|
|
2211
|
-
const u2 = modN(s2 * ir);
|
|
2212
|
-
return doubleScalarMulUns(R2, u1, u2);
|
|
2213
|
-
};
|
|
2214
|
-
getSharedSecret = (privA, pubB, isCompressed = true) => {
|
|
2215
|
-
return Point.fromBytes(toU8(pubB)).multiply(toPrivScalar(privA)).toBytes(isCompressed);
|
|
2216
|
-
};
|
|
2217
|
-
hashToPrivateKey = (hash) => {
|
|
2218
|
-
hash = toU8(hash);
|
|
2219
|
-
if (hash.length < L2 + 8 || hash.length > 1024)
|
|
2220
|
-
err("expected 40-1024b");
|
|
2221
|
-
const num = M2(bytesToNumBE(hash), N2 - 1n);
|
|
2222
|
-
return numTo32b(num + 1n);
|
|
2223
|
-
};
|
|
2224
|
-
randomPrivateKey = () => hashToPrivateKey(randomBytes(L2 + 16));
|
|
2225
|
-
_sha = "SHA-256";
|
|
2226
|
-
etc = {
|
|
2227
|
-
hexToBytes,
|
|
2228
|
-
bytesToHex,
|
|
2229
|
-
concatBytes,
|
|
2230
|
-
bytesToNumberBE: bytesToNumBE,
|
|
2231
|
-
numberToBytesBE: numTo32b,
|
|
2232
|
-
mod: M2,
|
|
2233
|
-
invert,
|
|
2234
|
-
// math utilities
|
|
2235
|
-
hmacSha256Async: async (key, ...msgs) => {
|
|
2236
|
-
const s2 = subtle();
|
|
2237
|
-
const name = "HMAC";
|
|
2238
|
-
const k2 = await s2.importKey("raw", key, { name, hash: { name: _sha } }, false, ["sign"]);
|
|
2239
|
-
return u8n(await s2.sign(name, k2, concatBytes(...msgs)));
|
|
2240
|
-
},
|
|
2241
|
-
hmacSha256Sync: void 0,
|
|
2242
|
-
// For TypeScript. Actual logic is below
|
|
2243
|
-
hashToPrivateKey,
|
|
2244
|
-
randomBytes
|
|
2245
|
-
};
|
|
2246
|
-
utils = {
|
|
2247
|
-
normPrivateKeyToScalar: toPrivScalar,
|
|
2248
|
-
isValidPrivateKey: (key) => {
|
|
2249
|
-
try {
|
|
2250
|
-
return !!toPrivScalar(key);
|
|
2251
|
-
} catch (e2) {
|
|
2252
|
-
return false;
|
|
2253
|
-
}
|
|
2254
|
-
},
|
|
2255
|
-
randomPrivateKey,
|
|
2256
|
-
precompute: (w2 = 8, p2 = G2) => {
|
|
2257
|
-
p2.multiply(3n);
|
|
2258
|
-
w2;
|
|
2259
|
-
return p2;
|
|
2260
|
-
}
|
|
2261
|
-
};
|
|
2262
|
-
W2 = 8;
|
|
2263
|
-
scalarBits = 256;
|
|
2264
|
-
pwindows = Math.ceil(scalarBits / W2) + 1;
|
|
2265
|
-
pwindowSize = 2 ** (W2 - 1);
|
|
2266
|
-
precompute = () => {
|
|
2267
|
-
const points = [];
|
|
2268
|
-
let p2 = G2;
|
|
2269
|
-
let b2 = p2;
|
|
2270
|
-
for (let w2 = 0; w2 < pwindows; w2++) {
|
|
2271
|
-
b2 = p2;
|
|
2272
|
-
points.push(b2);
|
|
2273
|
-
for (let i2 = 1; i2 < pwindowSize; i2++) {
|
|
2274
|
-
b2 = b2.add(p2);
|
|
2275
|
-
points.push(b2);
|
|
2276
|
-
}
|
|
2277
|
-
p2 = b2.double();
|
|
2278
|
-
}
|
|
2279
|
-
return points;
|
|
2280
|
-
};
|
|
2281
|
-
Gpows = void 0;
|
|
2282
|
-
ctneg = (cnd, p2) => {
|
|
2283
|
-
const n2 = p2.negate();
|
|
2284
|
-
return cnd ? n2 : p2;
|
|
2285
|
-
};
|
|
2286
|
-
wNAF = (n2) => {
|
|
2287
|
-
const comp = Gpows || (Gpows = precompute());
|
|
2288
|
-
let p2 = I2;
|
|
2289
|
-
let f2 = G2;
|
|
2290
|
-
const pow_2_w = 2 ** W2;
|
|
2291
|
-
const maxNum = pow_2_w;
|
|
2292
|
-
const mask = big(pow_2_w - 1);
|
|
2293
|
-
const shiftBy = big(W2);
|
|
2294
|
-
for (let w2 = 0; w2 < pwindows; w2++) {
|
|
2295
|
-
let wbits = Number(n2 & mask);
|
|
2296
|
-
n2 >>= shiftBy;
|
|
2297
|
-
if (wbits > pwindowSize) {
|
|
2298
|
-
wbits -= maxNum;
|
|
2299
|
-
n2 += 1n;
|
|
2300
|
-
}
|
|
2301
|
-
const off = w2 * pwindowSize;
|
|
2302
|
-
const offF = off;
|
|
2303
|
-
const offP = off + Math.abs(wbits) - 1;
|
|
2304
|
-
const isEven2 = w2 % 2 !== 0;
|
|
2305
|
-
const isNeg = wbits < 0;
|
|
2306
|
-
if (wbits === 0) {
|
|
2307
|
-
f2 = f2.add(ctneg(isEven2, comp[offF]));
|
|
2308
|
-
} else {
|
|
2309
|
-
p2 = p2.add(ctneg(isNeg, comp[offP]));
|
|
2310
|
-
}
|
|
2311
|
-
}
|
|
2312
|
-
return { p: p2, f: f2 };
|
|
2313
|
-
};
|
|
2314
|
-
}
|
|
2315
|
-
});
|
|
2316
|
-
|
|
2317
|
-
// ../../node_modules/@noble/hashes/crypto.js
|
|
2318
|
-
var require_crypto = __commonJS({
|
|
2319
|
-
"../../node_modules/@noble/hashes/crypto.js"(exports2) {
|
|
2320
|
-
"use strict";
|
|
2321
|
-
init_esbuild_shims();
|
|
2322
|
-
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
2323
|
-
exports2.crypto = void 0;
|
|
2324
|
-
exports2.crypto = typeof globalThis === "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
|
|
2325
|
-
}
|
|
2326
|
-
});
|
|
2327
|
-
|
|
2328
|
-
// ../../node_modules/@noble/hashes/utils.js
|
|
2329
|
-
var require_utils2 = __commonJS({
|
|
2330
|
-
"../../node_modules/@noble/hashes/utils.js"(exports2) {
|
|
2331
|
-
"use strict";
|
|
2332
|
-
init_esbuild_shims();
|
|
2333
|
-
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
2334
|
-
exports2.wrapXOFConstructorWithOpts = exports2.wrapConstructorWithOpts = exports2.wrapConstructor = exports2.Hash = exports2.nextTick = exports2.swap32IfBE = exports2.byteSwapIfBE = exports2.swap8IfBE = exports2.isLE = void 0;
|
|
2335
|
-
exports2.isBytes = isBytes3;
|
|
2336
|
-
exports2.anumber = anumber2;
|
|
2337
|
-
exports2.abytes = abytes3;
|
|
2338
|
-
exports2.ahash = ahash;
|
|
2339
|
-
exports2.aexists = aexists2;
|
|
2340
|
-
exports2.aoutput = aoutput2;
|
|
2341
|
-
exports2.u8 = u8;
|
|
2342
|
-
exports2.u32 = u322;
|
|
2343
|
-
exports2.clean = clean2;
|
|
2344
|
-
exports2.createView = createView2;
|
|
2345
|
-
exports2.rotr = rotr2;
|
|
2346
|
-
exports2.rotl = rotl;
|
|
2347
|
-
exports2.byteSwap = byteSwap2;
|
|
2348
|
-
exports2.byteSwap32 = byteSwap322;
|
|
2349
|
-
exports2.bytesToHex = bytesToHex2;
|
|
2350
|
-
exports2.hexToBytes = hexToBytes2;
|
|
2351
|
-
exports2.asyncLoop = asyncLoop;
|
|
2352
|
-
exports2.utf8ToBytes = utf8ToBytes;
|
|
2353
|
-
exports2.bytesToUtf8 = bytesToUtf8;
|
|
2354
|
-
exports2.toBytes = toBytes;
|
|
2355
|
-
exports2.kdfInputToBytes = kdfInputToBytes;
|
|
2356
|
-
exports2.concatBytes = concatBytes2;
|
|
2357
|
-
exports2.checkOpts = checkOpts;
|
|
2358
|
-
exports2.createHasher = createHasher2;
|
|
2359
|
-
exports2.createOptHasher = createOptHasher;
|
|
2360
|
-
exports2.createXOFer = createXOFer;
|
|
2361
|
-
exports2.randomBytes = randomBytes2;
|
|
2362
|
-
var crypto_1 = require_crypto();
|
|
2363
|
-
function isBytes3(a2) {
|
|
2364
|
-
return a2 instanceof Uint8Array || ArrayBuffer.isView(a2) && a2.constructor.name === "Uint8Array";
|
|
2365
|
-
}
|
|
2366
|
-
function anumber2(n2) {
|
|
2367
|
-
if (!Number.isSafeInteger(n2) || n2 < 0)
|
|
2368
|
-
throw new Error("positive integer expected, got " + n2);
|
|
2369
|
-
}
|
|
2370
|
-
function abytes3(b2, ...lengths) {
|
|
2371
|
-
if (!isBytes3(b2))
|
|
2372
|
-
throw new Error("Uint8Array expected");
|
|
2373
|
-
if (lengths.length > 0 && !lengths.includes(b2.length))
|
|
2374
|
-
throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b2.length);
|
|
2375
|
-
}
|
|
2376
|
-
function ahash(h2) {
|
|
2377
|
-
if (typeof h2 !== "function" || typeof h2.create !== "function")
|
|
2378
|
-
throw new Error("Hash should be wrapped by utils.createHasher");
|
|
2379
|
-
anumber2(h2.outputLen);
|
|
2380
|
-
anumber2(h2.blockLen);
|
|
2381
|
-
}
|
|
2382
|
-
function aexists2(instance, checkFinished = true) {
|
|
2383
|
-
if (instance.destroyed)
|
|
2384
|
-
throw new Error("Hash instance has been destroyed");
|
|
2385
|
-
if (checkFinished && instance.finished)
|
|
2386
|
-
throw new Error("Hash#digest() has already been called");
|
|
2387
|
-
}
|
|
2388
|
-
function aoutput2(out, instance) {
|
|
2389
|
-
abytes3(out);
|
|
2390
|
-
const min = instance.outputLen;
|
|
2391
|
-
if (out.length < min) {
|
|
2392
|
-
throw new Error("digestInto() expects output buffer of length at least " + min);
|
|
2393
|
-
}
|
|
2394
|
-
}
|
|
2395
|
-
function u8(arr) {
|
|
2396
|
-
return new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
2397
|
-
}
|
|
2398
|
-
function u322(arr) {
|
|
2399
|
-
return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
2400
|
-
}
|
|
2401
|
-
function clean2(...arrays) {
|
|
2402
|
-
for (let i2 = 0; i2 < arrays.length; i2++) {
|
|
2403
|
-
arrays[i2].fill(0);
|
|
2404
|
-
}
|
|
2405
|
-
}
|
|
2406
|
-
function createView2(arr) {
|
|
2407
|
-
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
2408
|
-
}
|
|
2409
|
-
function rotr2(word, shift) {
|
|
2410
|
-
return word << 32 - shift | word >>> shift;
|
|
2411
|
-
}
|
|
2412
|
-
function rotl(word, shift) {
|
|
2413
|
-
return word << shift | word >>> 32 - shift >>> 0;
|
|
2414
|
-
}
|
|
2415
|
-
exports2.isLE = (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
|
|
2416
|
-
function byteSwap2(word) {
|
|
2417
|
-
return word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
|
|
2418
|
-
}
|
|
2419
|
-
exports2.swap8IfBE = exports2.isLE ? (n2) => n2 : (n2) => byteSwap2(n2);
|
|
2420
|
-
exports2.byteSwapIfBE = exports2.swap8IfBE;
|
|
2421
|
-
function byteSwap322(arr) {
|
|
2422
|
-
for (let i2 = 0; i2 < arr.length; i2++) {
|
|
2423
|
-
arr[i2] = byteSwap2(arr[i2]);
|
|
2424
|
-
}
|
|
2425
|
-
return arr;
|
|
2426
|
-
}
|
|
2427
|
-
exports2.swap32IfBE = exports2.isLE ? (u2) => u2 : byteSwap322;
|
|
2428
|
-
var hasHexBuiltin = /* @__PURE__ */ (() => (
|
|
2429
|
-
// @ts-ignore
|
|
2430
|
-
typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function"
|
|
2431
|
-
))();
|
|
2432
|
-
var hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i2) => i2.toString(16).padStart(2, "0"));
|
|
2433
|
-
function bytesToHex2(bytes) {
|
|
2434
|
-
abytes3(bytes);
|
|
2435
|
-
if (hasHexBuiltin)
|
|
2436
|
-
return bytes.toHex();
|
|
2437
|
-
let hex = "";
|
|
2438
|
-
for (let i2 = 0; i2 < bytes.length; i2++) {
|
|
2439
|
-
hex += hexes[bytes[i2]];
|
|
2440
|
-
}
|
|
2441
|
-
return hex;
|
|
2442
|
-
}
|
|
2443
|
-
var asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
|
|
2444
|
-
function asciiToBase16(ch) {
|
|
2445
|
-
if (ch >= asciis._0 && ch <= asciis._9)
|
|
2446
|
-
return ch - asciis._0;
|
|
2447
|
-
if (ch >= asciis.A && ch <= asciis.F)
|
|
2448
|
-
return ch - (asciis.A - 10);
|
|
2449
|
-
if (ch >= asciis.a && ch <= asciis.f)
|
|
2450
|
-
return ch - (asciis.a - 10);
|
|
2451
|
-
return;
|
|
2452
|
-
}
|
|
2453
|
-
function hexToBytes2(hex) {
|
|
2454
|
-
if (typeof hex !== "string")
|
|
2455
|
-
throw new Error("hex string expected, got " + typeof hex);
|
|
2456
|
-
if (hasHexBuiltin)
|
|
2457
|
-
return Uint8Array.fromHex(hex);
|
|
2458
|
-
const hl = hex.length;
|
|
2459
|
-
const al = hl / 2;
|
|
2460
|
-
if (hl % 2)
|
|
2461
|
-
throw new Error("hex string expected, got unpadded hex of length " + hl);
|
|
2462
|
-
const array = new Uint8Array(al);
|
|
2463
|
-
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
2464
|
-
const n1 = asciiToBase16(hex.charCodeAt(hi));
|
|
2465
|
-
const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
|
|
2466
|
-
if (n1 === void 0 || n2 === void 0) {
|
|
2467
|
-
const char = hex[hi] + hex[hi + 1];
|
|
2468
|
-
throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
|
|
2469
|
-
}
|
|
2470
|
-
array[ai] = n1 * 16 + n2;
|
|
2471
|
-
}
|
|
2472
|
-
return array;
|
|
2473
|
-
}
|
|
2474
|
-
var nextTick = async () => {
|
|
2475
|
-
};
|
|
2476
|
-
exports2.nextTick = nextTick;
|
|
2477
|
-
async function asyncLoop(iters, tick, cb) {
|
|
2478
|
-
let ts = Date.now();
|
|
2479
|
-
for (let i2 = 0; i2 < iters; i2++) {
|
|
2480
|
-
cb(i2);
|
|
2481
|
-
const diff = Date.now() - ts;
|
|
2482
|
-
if (diff >= 0 && diff < tick)
|
|
2483
|
-
continue;
|
|
2484
|
-
await (0, exports2.nextTick)();
|
|
2485
|
-
ts += diff;
|
|
2486
|
-
}
|
|
2487
|
-
}
|
|
2488
|
-
function utf8ToBytes(str) {
|
|
2489
|
-
if (typeof str !== "string")
|
|
2490
|
-
throw new Error("string expected");
|
|
2491
|
-
return new Uint8Array(new TextEncoder().encode(str));
|
|
2492
|
-
}
|
|
2493
|
-
function bytesToUtf8(bytes) {
|
|
2494
|
-
return new TextDecoder().decode(bytes);
|
|
2495
|
-
}
|
|
2496
|
-
function toBytes(data) {
|
|
2497
|
-
if (typeof data === "string")
|
|
2498
|
-
data = utf8ToBytes(data);
|
|
2499
|
-
abytes3(data);
|
|
2500
|
-
return data;
|
|
2501
|
-
}
|
|
2502
|
-
function kdfInputToBytes(data) {
|
|
2503
|
-
if (typeof data === "string")
|
|
2504
|
-
data = utf8ToBytes(data);
|
|
2505
|
-
abytes3(data);
|
|
2506
|
-
return data;
|
|
2507
|
-
}
|
|
2508
|
-
function concatBytes2(...arrays) {
|
|
2509
|
-
let sum = 0;
|
|
2510
|
-
for (let i2 = 0; i2 < arrays.length; i2++) {
|
|
2511
|
-
const a2 = arrays[i2];
|
|
2512
|
-
abytes3(a2);
|
|
2513
|
-
sum += a2.length;
|
|
2514
|
-
}
|
|
2515
|
-
const res = new Uint8Array(sum);
|
|
2516
|
-
for (let i2 = 0, pad = 0; i2 < arrays.length; i2++) {
|
|
2517
|
-
const a2 = arrays[i2];
|
|
2518
|
-
res.set(a2, pad);
|
|
2519
|
-
pad += a2.length;
|
|
2520
|
-
}
|
|
2521
|
-
return res;
|
|
2522
|
-
}
|
|
2523
|
-
function checkOpts(defaults, opts) {
|
|
2524
|
-
if (opts !== void 0 && {}.toString.call(opts) !== "[object Object]")
|
|
2525
|
-
throw new Error("options should be object or undefined");
|
|
2526
|
-
const merged = Object.assign(defaults, opts);
|
|
2527
|
-
return merged;
|
|
2528
|
-
}
|
|
2529
|
-
var Hash = class {
|
|
2530
|
-
};
|
|
2531
|
-
exports2.Hash = Hash;
|
|
2532
|
-
function createHasher2(hashCons) {
|
|
2533
|
-
const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
|
|
2534
|
-
const tmp = hashCons();
|
|
2535
|
-
hashC.outputLen = tmp.outputLen;
|
|
2536
|
-
hashC.blockLen = tmp.blockLen;
|
|
2537
|
-
hashC.create = () => hashCons();
|
|
2538
|
-
return hashC;
|
|
2539
|
-
}
|
|
2540
|
-
function createOptHasher(hashCons) {
|
|
2541
|
-
const hashC = (msg, opts) => hashCons(opts).update(toBytes(msg)).digest();
|
|
2542
|
-
const tmp = hashCons({});
|
|
2543
|
-
hashC.outputLen = tmp.outputLen;
|
|
2544
|
-
hashC.blockLen = tmp.blockLen;
|
|
2545
|
-
hashC.create = (opts) => hashCons(opts);
|
|
2546
|
-
return hashC;
|
|
2547
|
-
}
|
|
2548
|
-
function createXOFer(hashCons) {
|
|
2549
|
-
const hashC = (msg, opts) => hashCons(opts).update(toBytes(msg)).digest();
|
|
2550
|
-
const tmp = hashCons({});
|
|
2551
|
-
hashC.outputLen = tmp.outputLen;
|
|
2552
|
-
hashC.blockLen = tmp.blockLen;
|
|
2553
|
-
hashC.create = (opts) => hashCons(opts);
|
|
2554
|
-
return hashC;
|
|
2555
|
-
}
|
|
2556
|
-
exports2.wrapConstructor = createHasher2;
|
|
2557
|
-
exports2.wrapConstructorWithOpts = createOptHasher;
|
|
2558
|
-
exports2.wrapXOFConstructorWithOpts = createXOFer;
|
|
2559
|
-
function randomBytes2(bytesLength = 32) {
|
|
2560
|
-
if (crypto_1.crypto && typeof crypto_1.crypto.getRandomValues === "function") {
|
|
2561
|
-
return crypto_1.crypto.getRandomValues(new Uint8Array(bytesLength));
|
|
2562
|
-
}
|
|
2563
|
-
if (crypto_1.crypto && typeof crypto_1.crypto.randomBytes === "function") {
|
|
2564
|
-
return Uint8Array.from(crypto_1.crypto.randomBytes(bytesLength));
|
|
2565
|
-
}
|
|
2566
|
-
throw new Error("crypto.getRandomValues must be defined");
|
|
2567
|
-
}
|
|
2568
|
-
}
|
|
2569
|
-
});
|
|
2570
|
-
|
|
2571
|
-
// ../../node_modules/@noble/hashes/hmac.js
|
|
2572
|
-
var require_hmac = __commonJS({
|
|
2573
|
-
"../../node_modules/@noble/hashes/hmac.js"(exports2) {
|
|
2574
|
-
"use strict";
|
|
2575
|
-
init_esbuild_shims();
|
|
2576
|
-
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
2577
|
-
exports2.hmac = exports2.HMAC = void 0;
|
|
2578
|
-
var utils_ts_1 = require_utils2();
|
|
2579
|
-
var HMAC = class extends utils_ts_1.Hash {
|
|
2580
|
-
constructor(hash, _key) {
|
|
2581
|
-
super();
|
|
2582
|
-
this.finished = false;
|
|
2583
|
-
this.destroyed = false;
|
|
2584
|
-
(0, utils_ts_1.ahash)(hash);
|
|
2585
|
-
const key = (0, utils_ts_1.toBytes)(_key);
|
|
2586
|
-
this.iHash = hash.create();
|
|
2587
|
-
if (typeof this.iHash.update !== "function")
|
|
2588
|
-
throw new Error("Expected instance of class which extends utils.Hash");
|
|
2589
|
-
this.blockLen = this.iHash.blockLen;
|
|
2590
|
-
this.outputLen = this.iHash.outputLen;
|
|
2591
|
-
const blockLen = this.blockLen;
|
|
2592
|
-
const pad = new Uint8Array(blockLen);
|
|
2593
|
-
pad.set(key.length > blockLen ? hash.create().update(key).digest() : key);
|
|
2594
|
-
for (let i2 = 0; i2 < pad.length; i2++)
|
|
2595
|
-
pad[i2] ^= 54;
|
|
2596
|
-
this.iHash.update(pad);
|
|
2597
|
-
this.oHash = hash.create();
|
|
2598
|
-
for (let i2 = 0; i2 < pad.length; i2++)
|
|
2599
|
-
pad[i2] ^= 54 ^ 92;
|
|
2600
|
-
this.oHash.update(pad);
|
|
2601
|
-
(0, utils_ts_1.clean)(pad);
|
|
2602
|
-
}
|
|
2603
|
-
update(buf) {
|
|
2604
|
-
(0, utils_ts_1.aexists)(this);
|
|
2605
|
-
this.iHash.update(buf);
|
|
2606
|
-
return this;
|
|
2607
|
-
}
|
|
2608
|
-
digestInto(out) {
|
|
2609
|
-
(0, utils_ts_1.aexists)(this);
|
|
2610
|
-
(0, utils_ts_1.abytes)(out, this.outputLen);
|
|
2611
|
-
this.finished = true;
|
|
2612
|
-
this.iHash.digestInto(out);
|
|
2613
|
-
this.oHash.update(out);
|
|
2614
|
-
this.oHash.digestInto(out);
|
|
2615
|
-
this.destroy();
|
|
2616
|
-
}
|
|
2617
|
-
digest() {
|
|
2618
|
-
const out = new Uint8Array(this.oHash.outputLen);
|
|
2619
|
-
this.digestInto(out);
|
|
2620
|
-
return out;
|
|
2621
|
-
}
|
|
2622
|
-
_cloneInto(to) {
|
|
2623
|
-
to || (to = Object.create(Object.getPrototypeOf(this), {}));
|
|
2624
|
-
const { oHash, iHash, finished, destroyed, blockLen, outputLen } = this;
|
|
2625
|
-
to = to;
|
|
2626
|
-
to.finished = finished;
|
|
2627
|
-
to.destroyed = destroyed;
|
|
2628
|
-
to.blockLen = blockLen;
|
|
2629
|
-
to.outputLen = outputLen;
|
|
2630
|
-
to.oHash = oHash._cloneInto(to.oHash);
|
|
2631
|
-
to.iHash = iHash._cloneInto(to.iHash);
|
|
2632
|
-
return to;
|
|
2633
|
-
}
|
|
2634
|
-
clone() {
|
|
2635
|
-
return this._cloneInto();
|
|
2636
|
-
}
|
|
2637
|
-
destroy() {
|
|
2638
|
-
this.destroyed = true;
|
|
2639
|
-
this.oHash.destroy();
|
|
2640
|
-
this.iHash.destroy();
|
|
2641
|
-
}
|
|
2642
|
-
};
|
|
2643
|
-
exports2.HMAC = HMAC;
|
|
2644
|
-
var hmac = (hash, key, message) => new HMAC(hash, key).update(message).digest();
|
|
2645
|
-
exports2.hmac = hmac;
|
|
2646
|
-
exports2.hmac.create = (hash, key) => new HMAC(hash, key);
|
|
2647
|
-
}
|
|
2648
|
-
});
|
|
2649
|
-
|
|
2650
|
-
// ../../node_modules/@noble/hashes/_md.js
|
|
2651
|
-
var require_md = __commonJS({
|
|
2652
|
-
"../../node_modules/@noble/hashes/_md.js"(exports2) {
|
|
2653
|
-
"use strict";
|
|
2654
|
-
init_esbuild_shims();
|
|
2655
|
-
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
2656
|
-
exports2.SHA512_IV = exports2.SHA384_IV = exports2.SHA224_IV = exports2.SHA256_IV = exports2.HashMD = void 0;
|
|
2657
|
-
exports2.setBigUint64 = setBigUint64;
|
|
2658
|
-
exports2.Chi = Chi2;
|
|
2659
|
-
exports2.Maj = Maj2;
|
|
2660
|
-
var utils_ts_1 = require_utils2();
|
|
2661
|
-
function setBigUint64(view, byteOffset, value, isLE2) {
|
|
2662
|
-
if (typeof view.setBigUint64 === "function")
|
|
2663
|
-
return view.setBigUint64(byteOffset, value, isLE2);
|
|
2664
|
-
const _32n2 = BigInt(32);
|
|
2665
|
-
const _u32_max = BigInt(4294967295);
|
|
2666
|
-
const wh = Number(value >> _32n2 & _u32_max);
|
|
2667
|
-
const wl = Number(value & _u32_max);
|
|
2668
|
-
const h2 = isLE2 ? 4 : 0;
|
|
2669
|
-
const l2 = isLE2 ? 0 : 4;
|
|
2670
|
-
view.setUint32(byteOffset + h2, wh, isLE2);
|
|
2671
|
-
view.setUint32(byteOffset + l2, wl, isLE2);
|
|
2672
|
-
}
|
|
2673
|
-
function Chi2(a2, b2, c2) {
|
|
2674
|
-
return a2 & b2 ^ ~a2 & c2;
|
|
2675
|
-
}
|
|
2676
|
-
function Maj2(a2, b2, c2) {
|
|
2677
|
-
return a2 & b2 ^ a2 & c2 ^ b2 & c2;
|
|
2678
|
-
}
|
|
2679
|
-
var HashMD2 = class extends utils_ts_1.Hash {
|
|
2680
|
-
constructor(blockLen, outputLen, padOffset, isLE2) {
|
|
2681
|
-
super();
|
|
2682
|
-
this.finished = false;
|
|
2683
|
-
this.length = 0;
|
|
2684
|
-
this.pos = 0;
|
|
2685
|
-
this.destroyed = false;
|
|
2686
|
-
this.blockLen = blockLen;
|
|
2687
|
-
this.outputLen = outputLen;
|
|
2688
|
-
this.padOffset = padOffset;
|
|
2689
|
-
this.isLE = isLE2;
|
|
2690
|
-
this.buffer = new Uint8Array(blockLen);
|
|
2691
|
-
this.view = (0, utils_ts_1.createView)(this.buffer);
|
|
2692
|
-
}
|
|
2693
|
-
update(data) {
|
|
2694
|
-
(0, utils_ts_1.aexists)(this);
|
|
2695
|
-
data = (0, utils_ts_1.toBytes)(data);
|
|
2696
|
-
(0, utils_ts_1.abytes)(data);
|
|
2697
|
-
const { view, buffer, blockLen } = this;
|
|
2698
|
-
const len = data.length;
|
|
2699
|
-
for (let pos = 0; pos < len; ) {
|
|
2700
|
-
const take = Math.min(blockLen - this.pos, len - pos);
|
|
2701
|
-
if (take === blockLen) {
|
|
2702
|
-
const dataView = (0, utils_ts_1.createView)(data);
|
|
2703
|
-
for (; blockLen <= len - pos; pos += blockLen)
|
|
2704
|
-
this.process(dataView, pos);
|
|
2705
|
-
continue;
|
|
2706
|
-
}
|
|
2707
|
-
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
2708
|
-
this.pos += take;
|
|
2709
|
-
pos += take;
|
|
2710
|
-
if (this.pos === blockLen) {
|
|
2711
|
-
this.process(view, 0);
|
|
2712
|
-
this.pos = 0;
|
|
2713
|
-
}
|
|
2714
|
-
}
|
|
2715
|
-
this.length += data.length;
|
|
2716
|
-
this.roundClean();
|
|
2717
|
-
return this;
|
|
2718
|
-
}
|
|
2719
|
-
digestInto(out) {
|
|
2720
|
-
(0, utils_ts_1.aexists)(this);
|
|
2721
|
-
(0, utils_ts_1.aoutput)(out, this);
|
|
2722
|
-
this.finished = true;
|
|
2723
|
-
const { buffer, view, blockLen, isLE: isLE2 } = this;
|
|
2724
|
-
let { pos } = this;
|
|
2725
|
-
buffer[pos++] = 128;
|
|
2726
|
-
(0, utils_ts_1.clean)(this.buffer.subarray(pos));
|
|
2727
|
-
if (this.padOffset > blockLen - pos) {
|
|
2728
|
-
this.process(view, 0);
|
|
2729
|
-
pos = 0;
|
|
2730
|
-
}
|
|
2731
|
-
for (let i2 = pos; i2 < blockLen; i2++)
|
|
2732
|
-
buffer[i2] = 0;
|
|
2733
|
-
setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE2);
|
|
2734
|
-
this.process(view, 0);
|
|
2735
|
-
const oview = (0, utils_ts_1.createView)(out);
|
|
2736
|
-
const len = this.outputLen;
|
|
2737
|
-
if (len % 4)
|
|
2738
|
-
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
2739
|
-
const outLen = len / 4;
|
|
2740
|
-
const state = this.get();
|
|
2741
|
-
if (outLen > state.length)
|
|
2742
|
-
throw new Error("_sha2: outputLen bigger than state");
|
|
2743
|
-
for (let i2 = 0; i2 < outLen; i2++)
|
|
2744
|
-
oview.setUint32(4 * i2, state[i2], isLE2);
|
|
2745
|
-
}
|
|
2746
|
-
digest() {
|
|
2747
|
-
const { buffer, outputLen } = this;
|
|
2748
|
-
this.digestInto(buffer);
|
|
2749
|
-
const res = buffer.slice(0, outputLen);
|
|
2750
|
-
this.destroy();
|
|
2751
|
-
return res;
|
|
2752
|
-
}
|
|
2753
|
-
_cloneInto(to) {
|
|
2754
|
-
to || (to = new this.constructor());
|
|
2755
|
-
to.set(...this.get());
|
|
2756
|
-
const { blockLen, buffer, length, finished, destroyed, pos } = this;
|
|
2757
|
-
to.destroyed = destroyed;
|
|
2758
|
-
to.finished = finished;
|
|
2759
|
-
to.length = length;
|
|
2760
|
-
to.pos = pos;
|
|
2761
|
-
if (length % blockLen)
|
|
2762
|
-
to.buffer.set(buffer);
|
|
2763
|
-
return to;
|
|
2764
|
-
}
|
|
2765
|
-
clone() {
|
|
2766
|
-
return this._cloneInto();
|
|
2767
|
-
}
|
|
2768
|
-
};
|
|
2769
|
-
exports2.HashMD = HashMD2;
|
|
2770
|
-
exports2.SHA256_IV = Uint32Array.from([
|
|
2771
|
-
1779033703,
|
|
2772
|
-
3144134277,
|
|
2773
|
-
1013904242,
|
|
2774
|
-
2773480762,
|
|
2775
|
-
1359893119,
|
|
2776
|
-
2600822924,
|
|
2777
|
-
528734635,
|
|
2778
|
-
1541459225
|
|
2779
|
-
]);
|
|
2780
|
-
exports2.SHA224_IV = Uint32Array.from([
|
|
2781
|
-
3238371032,
|
|
2782
|
-
914150663,
|
|
2783
|
-
812702999,
|
|
2784
|
-
4144912697,
|
|
2785
|
-
4290775857,
|
|
2786
|
-
1750603025,
|
|
2787
|
-
1694076839,
|
|
2788
|
-
3204075428
|
|
2789
|
-
]);
|
|
2790
|
-
exports2.SHA384_IV = Uint32Array.from([
|
|
2791
|
-
3418070365,
|
|
2792
|
-
3238371032,
|
|
2793
|
-
1654270250,
|
|
2794
|
-
914150663,
|
|
2795
|
-
2438529370,
|
|
2796
|
-
812702999,
|
|
2797
|
-
355462360,
|
|
2798
|
-
4144912697,
|
|
2799
|
-
1731405415,
|
|
2800
|
-
4290775857,
|
|
2801
|
-
2394180231,
|
|
2802
|
-
1750603025,
|
|
2803
|
-
3675008525,
|
|
2804
|
-
1694076839,
|
|
2805
|
-
1203062813,
|
|
2806
|
-
3204075428
|
|
2807
|
-
]);
|
|
2808
|
-
exports2.SHA512_IV = Uint32Array.from([
|
|
2809
|
-
1779033703,
|
|
2810
|
-
4089235720,
|
|
2811
|
-
3144134277,
|
|
2812
|
-
2227873595,
|
|
2813
|
-
1013904242,
|
|
2814
|
-
4271175723,
|
|
2815
|
-
2773480762,
|
|
2816
|
-
1595750129,
|
|
2817
|
-
1359893119,
|
|
2818
|
-
2917565137,
|
|
2819
|
-
2600822924,
|
|
2820
|
-
725511199,
|
|
2821
|
-
528734635,
|
|
2822
|
-
4215389547,
|
|
2823
|
-
1541459225,
|
|
2824
|
-
327033209
|
|
2825
|
-
]);
|
|
2826
|
-
}
|
|
2827
|
-
});
|
|
2828
|
-
|
|
2829
|
-
// ../../node_modules/@noble/hashes/_u64.js
|
|
2830
|
-
var require_u64 = __commonJS({
|
|
2831
|
-
"../../node_modules/@noble/hashes/_u64.js"(exports2) {
|
|
2832
|
-
"use strict";
|
|
2833
|
-
init_esbuild_shims();
|
|
2834
|
-
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
2835
|
-
exports2.toBig = exports2.shrSL = exports2.shrSH = exports2.rotrSL = exports2.rotrSH = exports2.rotrBL = exports2.rotrBH = exports2.rotr32L = exports2.rotr32H = exports2.rotlSL = exports2.rotlSH = exports2.rotlBL = exports2.rotlBH = exports2.add5L = exports2.add5H = exports2.add4L = exports2.add4H = exports2.add3L = exports2.add3H = void 0;
|
|
2836
|
-
exports2.add = add2;
|
|
2837
|
-
exports2.fromBig = fromBig2;
|
|
2838
|
-
exports2.split = split2;
|
|
2839
|
-
var U32_MASK642 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
2840
|
-
var _32n2 = /* @__PURE__ */ BigInt(32);
|
|
2841
|
-
function fromBig2(n2, le = false) {
|
|
2842
|
-
if (le)
|
|
2843
|
-
return { h: Number(n2 & U32_MASK642), l: Number(n2 >> _32n2 & U32_MASK642) };
|
|
2844
|
-
return { h: Number(n2 >> _32n2 & U32_MASK642) | 0, l: Number(n2 & U32_MASK642) | 0 };
|
|
2845
|
-
}
|
|
2846
|
-
function split2(lst, le = false) {
|
|
2847
|
-
const len = lst.length;
|
|
2848
|
-
let Ah = new Uint32Array(len);
|
|
2849
|
-
let Al = new Uint32Array(len);
|
|
2850
|
-
for (let i2 = 0; i2 < len; i2++) {
|
|
2851
|
-
const { h: h2, l: l2 } = fromBig2(lst[i2], le);
|
|
2852
|
-
[Ah[i2], Al[i2]] = [h2, l2];
|
|
2853
|
-
}
|
|
2854
|
-
return [Ah, Al];
|
|
2855
|
-
}
|
|
2856
|
-
var toBig = (h2, l2) => BigInt(h2 >>> 0) << _32n2 | BigInt(l2 >>> 0);
|
|
2857
|
-
exports2.toBig = toBig;
|
|
2858
|
-
var shrSH2 = (h2, _l, s2) => h2 >>> s2;
|
|
2859
|
-
exports2.shrSH = shrSH2;
|
|
2860
|
-
var shrSL2 = (h2, l2, s2) => h2 << 32 - s2 | l2 >>> s2;
|
|
2861
|
-
exports2.shrSL = shrSL2;
|
|
2862
|
-
var rotrSH2 = (h2, l2, s2) => h2 >>> s2 | l2 << 32 - s2;
|
|
2863
|
-
exports2.rotrSH = rotrSH2;
|
|
2864
|
-
var rotrSL2 = (h2, l2, s2) => h2 << 32 - s2 | l2 >>> s2;
|
|
2865
|
-
exports2.rotrSL = rotrSL2;
|
|
2866
|
-
var rotrBH2 = (h2, l2, s2) => h2 << 64 - s2 | l2 >>> s2 - 32;
|
|
2867
|
-
exports2.rotrBH = rotrBH2;
|
|
2868
|
-
var rotrBL2 = (h2, l2, s2) => h2 >>> s2 - 32 | l2 << 64 - s2;
|
|
2869
|
-
exports2.rotrBL = rotrBL2;
|
|
2870
|
-
var rotr32H = (_h, l2) => l2;
|
|
2871
|
-
exports2.rotr32H = rotr32H;
|
|
2872
|
-
var rotr32L = (h2, _l) => h2;
|
|
2873
|
-
exports2.rotr32L = rotr32L;
|
|
2874
|
-
var rotlSH2 = (h2, l2, s2) => h2 << s2 | l2 >>> 32 - s2;
|
|
2875
|
-
exports2.rotlSH = rotlSH2;
|
|
2876
|
-
var rotlSL2 = (h2, l2, s2) => l2 << s2 | h2 >>> 32 - s2;
|
|
2877
|
-
exports2.rotlSL = rotlSL2;
|
|
2878
|
-
var rotlBH2 = (h2, l2, s2) => l2 << s2 - 32 | h2 >>> 64 - s2;
|
|
2879
|
-
exports2.rotlBH = rotlBH2;
|
|
2880
|
-
var rotlBL2 = (h2, l2, s2) => h2 << s2 - 32 | l2 >>> 64 - s2;
|
|
2881
|
-
exports2.rotlBL = rotlBL2;
|
|
2882
|
-
function add2(Ah, Al, Bh, Bl) {
|
|
2883
|
-
const l2 = (Al >>> 0) + (Bl >>> 0);
|
|
2884
|
-
return { h: Ah + Bh + (l2 / 2 ** 32 | 0) | 0, l: l2 | 0 };
|
|
2885
|
-
}
|
|
2886
|
-
var add3L2 = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
|
|
2887
|
-
exports2.add3L = add3L2;
|
|
2888
|
-
var add3H2 = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
|
|
2889
|
-
exports2.add3H = add3H2;
|
|
2890
|
-
var add4L2 = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
|
|
2891
|
-
exports2.add4L = add4L2;
|
|
2892
|
-
var add4H2 = (low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0;
|
|
2893
|
-
exports2.add4H = add4H2;
|
|
2894
|
-
var add5L2 = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
|
|
2895
|
-
exports2.add5L = add5L2;
|
|
2896
|
-
var add5H2 = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
|
|
2897
|
-
exports2.add5H = add5H2;
|
|
2898
|
-
var u64 = {
|
|
2899
|
-
fromBig: fromBig2,
|
|
2900
|
-
split: split2,
|
|
2901
|
-
toBig,
|
|
2902
|
-
shrSH: shrSH2,
|
|
2903
|
-
shrSL: shrSL2,
|
|
2904
|
-
rotrSH: rotrSH2,
|
|
2905
|
-
rotrSL: rotrSL2,
|
|
2906
|
-
rotrBH: rotrBH2,
|
|
2907
|
-
rotrBL: rotrBL2,
|
|
2908
|
-
rotr32H,
|
|
2909
|
-
rotr32L,
|
|
2910
|
-
rotlSH: rotlSH2,
|
|
2911
|
-
rotlSL: rotlSL2,
|
|
2912
|
-
rotlBH: rotlBH2,
|
|
2913
|
-
rotlBL: rotlBL2,
|
|
2914
|
-
add: add2,
|
|
2915
|
-
add3L: add3L2,
|
|
2916
|
-
add3H: add3H2,
|
|
2917
|
-
add4L: add4L2,
|
|
2918
|
-
add4H: add4H2,
|
|
2919
|
-
add5H: add5H2,
|
|
2920
|
-
add5L: add5L2
|
|
2921
|
-
};
|
|
2922
|
-
exports2.default = u64;
|
|
2923
|
-
}
|
|
2924
|
-
});
|
|
2925
|
-
|
|
2926
|
-
// ../../node_modules/@noble/hashes/sha2.js
|
|
2927
|
-
var require_sha2 = __commonJS({
|
|
2928
|
-
"../../node_modules/@noble/hashes/sha2.js"(exports2) {
|
|
2929
|
-
"use strict";
|
|
2930
|
-
init_esbuild_shims();
|
|
2931
|
-
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
2932
|
-
exports2.sha512_224 = exports2.sha512_256 = exports2.sha384 = exports2.sha512 = exports2.sha224 = exports2.sha256 = exports2.SHA512_256 = exports2.SHA512_224 = exports2.SHA384 = exports2.SHA512 = exports2.SHA224 = exports2.SHA256 = void 0;
|
|
2933
|
-
var _md_ts_1 = require_md();
|
|
2934
|
-
var u64 = require_u64();
|
|
2935
|
-
var utils_ts_1 = require_utils2();
|
|
2936
|
-
var SHA256_K2 = /* @__PURE__ */ Uint32Array.from([
|
|
2937
|
-
1116352408,
|
|
2938
|
-
1899447441,
|
|
2939
|
-
3049323471,
|
|
2940
|
-
3921009573,
|
|
2941
|
-
961987163,
|
|
2942
|
-
1508970993,
|
|
2943
|
-
2453635748,
|
|
2944
|
-
2870763221,
|
|
2945
|
-
3624381080,
|
|
2946
|
-
310598401,
|
|
2947
|
-
607225278,
|
|
2948
|
-
1426881987,
|
|
2949
|
-
1925078388,
|
|
2950
|
-
2162078206,
|
|
2951
|
-
2614888103,
|
|
2952
|
-
3248222580,
|
|
2953
|
-
3835390401,
|
|
2954
|
-
4022224774,
|
|
2955
|
-
264347078,
|
|
2956
|
-
604807628,
|
|
2957
|
-
770255983,
|
|
2958
|
-
1249150122,
|
|
2959
|
-
1555081692,
|
|
2960
|
-
1996064986,
|
|
2961
|
-
2554220882,
|
|
2962
|
-
2821834349,
|
|
2963
|
-
2952996808,
|
|
2964
|
-
3210313671,
|
|
2965
|
-
3336571891,
|
|
2966
|
-
3584528711,
|
|
2967
|
-
113926993,
|
|
2968
|
-
338241895,
|
|
2969
|
-
666307205,
|
|
2970
|
-
773529912,
|
|
2971
|
-
1294757372,
|
|
2972
|
-
1396182291,
|
|
2973
|
-
1695183700,
|
|
2974
|
-
1986661051,
|
|
2975
|
-
2177026350,
|
|
2976
|
-
2456956037,
|
|
2977
|
-
2730485921,
|
|
2978
|
-
2820302411,
|
|
2979
|
-
3259730800,
|
|
2980
|
-
3345764771,
|
|
2981
|
-
3516065817,
|
|
2982
|
-
3600352804,
|
|
2983
|
-
4094571909,
|
|
2984
|
-
275423344,
|
|
2985
|
-
430227734,
|
|
2986
|
-
506948616,
|
|
2987
|
-
659060556,
|
|
2988
|
-
883997877,
|
|
2989
|
-
958139571,
|
|
2990
|
-
1322822218,
|
|
2991
|
-
1537002063,
|
|
2992
|
-
1747873779,
|
|
2993
|
-
1955562222,
|
|
2994
|
-
2024104815,
|
|
2995
|
-
2227730452,
|
|
2996
|
-
2361852424,
|
|
2997
|
-
2428436474,
|
|
2998
|
-
2756734187,
|
|
2999
|
-
3204031479,
|
|
3000
|
-
3329325298
|
|
3001
|
-
]);
|
|
3002
|
-
var SHA256_W2 = /* @__PURE__ */ new Uint32Array(64);
|
|
3003
|
-
var SHA256 = class extends _md_ts_1.HashMD {
|
|
3004
|
-
constructor(outputLen = 32) {
|
|
3005
|
-
super(64, outputLen, 8, false);
|
|
3006
|
-
this.A = _md_ts_1.SHA256_IV[0] | 0;
|
|
3007
|
-
this.B = _md_ts_1.SHA256_IV[1] | 0;
|
|
3008
|
-
this.C = _md_ts_1.SHA256_IV[2] | 0;
|
|
3009
|
-
this.D = _md_ts_1.SHA256_IV[3] | 0;
|
|
3010
|
-
this.E = _md_ts_1.SHA256_IV[4] | 0;
|
|
3011
|
-
this.F = _md_ts_1.SHA256_IV[5] | 0;
|
|
3012
|
-
this.G = _md_ts_1.SHA256_IV[6] | 0;
|
|
3013
|
-
this.H = _md_ts_1.SHA256_IV[7] | 0;
|
|
3014
|
-
}
|
|
3015
|
-
get() {
|
|
3016
|
-
const { A: A2, B: B2, C: C3, D: D2, E: E2, F: F2, G: G3, H: H2 } = this;
|
|
3017
|
-
return [A2, B2, C3, D2, E2, F2, G3, H2];
|
|
3018
|
-
}
|
|
3019
|
-
// prettier-ignore
|
|
3020
|
-
set(A2, B2, C3, D2, E2, F2, G3, H2) {
|
|
3021
|
-
this.A = A2 | 0;
|
|
3022
|
-
this.B = B2 | 0;
|
|
3023
|
-
this.C = C3 | 0;
|
|
3024
|
-
this.D = D2 | 0;
|
|
3025
|
-
this.E = E2 | 0;
|
|
3026
|
-
this.F = F2 | 0;
|
|
3027
|
-
this.G = G3 | 0;
|
|
3028
|
-
this.H = H2 | 0;
|
|
3029
|
-
}
|
|
3030
|
-
process(view, offset) {
|
|
3031
|
-
for (let i2 = 0; i2 < 16; i2++, offset += 4)
|
|
3032
|
-
SHA256_W2[i2] = view.getUint32(offset, false);
|
|
3033
|
-
for (let i2 = 16; i2 < 64; i2++) {
|
|
3034
|
-
const W15 = SHA256_W2[i2 - 15];
|
|
3035
|
-
const W22 = SHA256_W2[i2 - 2];
|
|
3036
|
-
const s0 = (0, utils_ts_1.rotr)(W15, 7) ^ (0, utils_ts_1.rotr)(W15, 18) ^ W15 >>> 3;
|
|
3037
|
-
const s1 = (0, utils_ts_1.rotr)(W22, 17) ^ (0, utils_ts_1.rotr)(W22, 19) ^ W22 >>> 10;
|
|
3038
|
-
SHA256_W2[i2] = s1 + SHA256_W2[i2 - 7] + s0 + SHA256_W2[i2 - 16] | 0;
|
|
3039
|
-
}
|
|
3040
|
-
let { A: A2, B: B2, C: C3, D: D2, E: E2, F: F2, G: G3, H: H2 } = this;
|
|
3041
|
-
for (let i2 = 0; i2 < 64; i2++) {
|
|
3042
|
-
const sigma1 = (0, utils_ts_1.rotr)(E2, 6) ^ (0, utils_ts_1.rotr)(E2, 11) ^ (0, utils_ts_1.rotr)(E2, 25);
|
|
3043
|
-
const T1 = H2 + sigma1 + (0, _md_ts_1.Chi)(E2, F2, G3) + SHA256_K2[i2] + SHA256_W2[i2] | 0;
|
|
3044
|
-
const sigma0 = (0, utils_ts_1.rotr)(A2, 2) ^ (0, utils_ts_1.rotr)(A2, 13) ^ (0, utils_ts_1.rotr)(A2, 22);
|
|
3045
|
-
const T2 = sigma0 + (0, _md_ts_1.Maj)(A2, B2, C3) | 0;
|
|
3046
|
-
H2 = G3;
|
|
3047
|
-
G3 = F2;
|
|
3048
|
-
F2 = E2;
|
|
3049
|
-
E2 = D2 + T1 | 0;
|
|
3050
|
-
D2 = C3;
|
|
3051
|
-
C3 = B2;
|
|
3052
|
-
B2 = A2;
|
|
3053
|
-
A2 = T1 + T2 | 0;
|
|
3054
|
-
}
|
|
3055
|
-
A2 = A2 + this.A | 0;
|
|
3056
|
-
B2 = B2 + this.B | 0;
|
|
3057
|
-
C3 = C3 + this.C | 0;
|
|
3058
|
-
D2 = D2 + this.D | 0;
|
|
3059
|
-
E2 = E2 + this.E | 0;
|
|
3060
|
-
F2 = F2 + this.F | 0;
|
|
3061
|
-
G3 = G3 + this.G | 0;
|
|
3062
|
-
H2 = H2 + this.H | 0;
|
|
3063
|
-
this.set(A2, B2, C3, D2, E2, F2, G3, H2);
|
|
3064
|
-
}
|
|
3065
|
-
roundClean() {
|
|
3066
|
-
(0, utils_ts_1.clean)(SHA256_W2);
|
|
3067
|
-
}
|
|
3068
|
-
destroy() {
|
|
3069
|
-
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
3070
|
-
(0, utils_ts_1.clean)(this.buffer);
|
|
3071
|
-
}
|
|
3072
|
-
};
|
|
3073
|
-
exports2.SHA256 = SHA256;
|
|
3074
|
-
var SHA224 = class extends SHA256 {
|
|
3075
|
-
constructor() {
|
|
3076
|
-
super(28);
|
|
3077
|
-
this.A = _md_ts_1.SHA224_IV[0] | 0;
|
|
3078
|
-
this.B = _md_ts_1.SHA224_IV[1] | 0;
|
|
3079
|
-
this.C = _md_ts_1.SHA224_IV[2] | 0;
|
|
3080
|
-
this.D = _md_ts_1.SHA224_IV[3] | 0;
|
|
3081
|
-
this.E = _md_ts_1.SHA224_IV[4] | 0;
|
|
3082
|
-
this.F = _md_ts_1.SHA224_IV[5] | 0;
|
|
3083
|
-
this.G = _md_ts_1.SHA224_IV[6] | 0;
|
|
3084
|
-
this.H = _md_ts_1.SHA224_IV[7] | 0;
|
|
3085
|
-
}
|
|
3086
|
-
};
|
|
3087
|
-
exports2.SHA224 = SHA224;
|
|
3088
|
-
var K5122 = /* @__PURE__ */ (() => u64.split([
|
|
3089
|
-
"0x428a2f98d728ae22",
|
|
3090
|
-
"0x7137449123ef65cd",
|
|
3091
|
-
"0xb5c0fbcfec4d3b2f",
|
|
3092
|
-
"0xe9b5dba58189dbbc",
|
|
3093
|
-
"0x3956c25bf348b538",
|
|
3094
|
-
"0x59f111f1b605d019",
|
|
3095
|
-
"0x923f82a4af194f9b",
|
|
3096
|
-
"0xab1c5ed5da6d8118",
|
|
3097
|
-
"0xd807aa98a3030242",
|
|
3098
|
-
"0x12835b0145706fbe",
|
|
3099
|
-
"0x243185be4ee4b28c",
|
|
3100
|
-
"0x550c7dc3d5ffb4e2",
|
|
3101
|
-
"0x72be5d74f27b896f",
|
|
3102
|
-
"0x80deb1fe3b1696b1",
|
|
3103
|
-
"0x9bdc06a725c71235",
|
|
3104
|
-
"0xc19bf174cf692694",
|
|
3105
|
-
"0xe49b69c19ef14ad2",
|
|
3106
|
-
"0xefbe4786384f25e3",
|
|
3107
|
-
"0x0fc19dc68b8cd5b5",
|
|
3108
|
-
"0x240ca1cc77ac9c65",
|
|
3109
|
-
"0x2de92c6f592b0275",
|
|
3110
|
-
"0x4a7484aa6ea6e483",
|
|
3111
|
-
"0x5cb0a9dcbd41fbd4",
|
|
3112
|
-
"0x76f988da831153b5",
|
|
3113
|
-
"0x983e5152ee66dfab",
|
|
3114
|
-
"0xa831c66d2db43210",
|
|
3115
|
-
"0xb00327c898fb213f",
|
|
3116
|
-
"0xbf597fc7beef0ee4",
|
|
3117
|
-
"0xc6e00bf33da88fc2",
|
|
3118
|
-
"0xd5a79147930aa725",
|
|
3119
|
-
"0x06ca6351e003826f",
|
|
3120
|
-
"0x142929670a0e6e70",
|
|
3121
|
-
"0x27b70a8546d22ffc",
|
|
3122
|
-
"0x2e1b21385c26c926",
|
|
3123
|
-
"0x4d2c6dfc5ac42aed",
|
|
3124
|
-
"0x53380d139d95b3df",
|
|
3125
|
-
"0x650a73548baf63de",
|
|
3126
|
-
"0x766a0abb3c77b2a8",
|
|
3127
|
-
"0x81c2c92e47edaee6",
|
|
3128
|
-
"0x92722c851482353b",
|
|
3129
|
-
"0xa2bfe8a14cf10364",
|
|
3130
|
-
"0xa81a664bbc423001",
|
|
3131
|
-
"0xc24b8b70d0f89791",
|
|
3132
|
-
"0xc76c51a30654be30",
|
|
3133
|
-
"0xd192e819d6ef5218",
|
|
3134
|
-
"0xd69906245565a910",
|
|
3135
|
-
"0xf40e35855771202a",
|
|
3136
|
-
"0x106aa07032bbd1b8",
|
|
3137
|
-
"0x19a4c116b8d2d0c8",
|
|
3138
|
-
"0x1e376c085141ab53",
|
|
3139
|
-
"0x2748774cdf8eeb99",
|
|
3140
|
-
"0x34b0bcb5e19b48a8",
|
|
3141
|
-
"0x391c0cb3c5c95a63",
|
|
3142
|
-
"0x4ed8aa4ae3418acb",
|
|
3143
|
-
"0x5b9cca4f7763e373",
|
|
3144
|
-
"0x682e6ff3d6b2b8a3",
|
|
3145
|
-
"0x748f82ee5defb2fc",
|
|
3146
|
-
"0x78a5636f43172f60",
|
|
3147
|
-
"0x84c87814a1f0ab72",
|
|
3148
|
-
"0x8cc702081a6439ec",
|
|
3149
|
-
"0x90befffa23631e28",
|
|
3150
|
-
"0xa4506cebde82bde9",
|
|
3151
|
-
"0xbef9a3f7b2c67915",
|
|
3152
|
-
"0xc67178f2e372532b",
|
|
3153
|
-
"0xca273eceea26619c",
|
|
3154
|
-
"0xd186b8c721c0c207",
|
|
3155
|
-
"0xeada7dd6cde0eb1e",
|
|
3156
|
-
"0xf57d4f7fee6ed178",
|
|
3157
|
-
"0x06f067aa72176fba",
|
|
3158
|
-
"0x0a637dc5a2c898a6",
|
|
3159
|
-
"0x113f9804bef90dae",
|
|
3160
|
-
"0x1b710b35131c471b",
|
|
3161
|
-
"0x28db77f523047d84",
|
|
3162
|
-
"0x32caab7b40c72493",
|
|
3163
|
-
"0x3c9ebe0a15c9bebc",
|
|
3164
|
-
"0x431d67c49c100d4c",
|
|
3165
|
-
"0x4cc5d4becb3e42b6",
|
|
3166
|
-
"0x597f299cfc657e2a",
|
|
3167
|
-
"0x5fcb6fab3ad6faec",
|
|
3168
|
-
"0x6c44198c4a475817"
|
|
3169
|
-
].map((n2) => BigInt(n2))))();
|
|
3170
|
-
var SHA512_Kh2 = /* @__PURE__ */ (() => K5122[0])();
|
|
3171
|
-
var SHA512_Kl2 = /* @__PURE__ */ (() => K5122[1])();
|
|
3172
|
-
var SHA512_W_H2 = /* @__PURE__ */ new Uint32Array(80);
|
|
3173
|
-
var SHA512_W_L2 = /* @__PURE__ */ new Uint32Array(80);
|
|
3174
|
-
var SHA512 = class extends _md_ts_1.HashMD {
|
|
3175
|
-
constructor(outputLen = 64) {
|
|
3176
|
-
super(128, outputLen, 16, false);
|
|
3177
|
-
this.Ah = _md_ts_1.SHA512_IV[0] | 0;
|
|
3178
|
-
this.Al = _md_ts_1.SHA512_IV[1] | 0;
|
|
3179
|
-
this.Bh = _md_ts_1.SHA512_IV[2] | 0;
|
|
3180
|
-
this.Bl = _md_ts_1.SHA512_IV[3] | 0;
|
|
3181
|
-
this.Ch = _md_ts_1.SHA512_IV[4] | 0;
|
|
3182
|
-
this.Cl = _md_ts_1.SHA512_IV[5] | 0;
|
|
3183
|
-
this.Dh = _md_ts_1.SHA512_IV[6] | 0;
|
|
3184
|
-
this.Dl = _md_ts_1.SHA512_IV[7] | 0;
|
|
3185
|
-
this.Eh = _md_ts_1.SHA512_IV[8] | 0;
|
|
3186
|
-
this.El = _md_ts_1.SHA512_IV[9] | 0;
|
|
3187
|
-
this.Fh = _md_ts_1.SHA512_IV[10] | 0;
|
|
3188
|
-
this.Fl = _md_ts_1.SHA512_IV[11] | 0;
|
|
3189
|
-
this.Gh = _md_ts_1.SHA512_IV[12] | 0;
|
|
3190
|
-
this.Gl = _md_ts_1.SHA512_IV[13] | 0;
|
|
3191
|
-
this.Hh = _md_ts_1.SHA512_IV[14] | 0;
|
|
3192
|
-
this.Hl = _md_ts_1.SHA512_IV[15] | 0;
|
|
3193
|
-
}
|
|
3194
|
-
// prettier-ignore
|
|
3195
|
-
get() {
|
|
3196
|
-
const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
|
3197
|
-
return [Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl];
|
|
3198
|
-
}
|
|
3199
|
-
// prettier-ignore
|
|
3200
|
-
set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
|
|
3201
|
-
this.Ah = Ah | 0;
|
|
3202
|
-
this.Al = Al | 0;
|
|
3203
|
-
this.Bh = Bh | 0;
|
|
3204
|
-
this.Bl = Bl | 0;
|
|
3205
|
-
this.Ch = Ch | 0;
|
|
3206
|
-
this.Cl = Cl | 0;
|
|
3207
|
-
this.Dh = Dh | 0;
|
|
3208
|
-
this.Dl = Dl | 0;
|
|
3209
|
-
this.Eh = Eh | 0;
|
|
3210
|
-
this.El = El | 0;
|
|
3211
|
-
this.Fh = Fh | 0;
|
|
3212
|
-
this.Fl = Fl | 0;
|
|
3213
|
-
this.Gh = Gh | 0;
|
|
3214
|
-
this.Gl = Gl | 0;
|
|
3215
|
-
this.Hh = Hh | 0;
|
|
3216
|
-
this.Hl = Hl | 0;
|
|
3217
|
-
}
|
|
3218
|
-
process(view, offset) {
|
|
3219
|
-
for (let i2 = 0; i2 < 16; i2++, offset += 4) {
|
|
3220
|
-
SHA512_W_H2[i2] = view.getUint32(offset);
|
|
3221
|
-
SHA512_W_L2[i2] = view.getUint32(offset += 4);
|
|
3222
|
-
}
|
|
3223
|
-
for (let i2 = 16; i2 < 80; i2++) {
|
|
3224
|
-
const W15h = SHA512_W_H2[i2 - 15] | 0;
|
|
3225
|
-
const W15l = SHA512_W_L2[i2 - 15] | 0;
|
|
3226
|
-
const s0h = u64.rotrSH(W15h, W15l, 1) ^ u64.rotrSH(W15h, W15l, 8) ^ u64.shrSH(W15h, W15l, 7);
|
|
3227
|
-
const s0l = u64.rotrSL(W15h, W15l, 1) ^ u64.rotrSL(W15h, W15l, 8) ^ u64.shrSL(W15h, W15l, 7);
|
|
3228
|
-
const W2h = SHA512_W_H2[i2 - 2] | 0;
|
|
3229
|
-
const W2l = SHA512_W_L2[i2 - 2] | 0;
|
|
3230
|
-
const s1h = u64.rotrSH(W2h, W2l, 19) ^ u64.rotrBH(W2h, W2l, 61) ^ u64.shrSH(W2h, W2l, 6);
|
|
3231
|
-
const s1l = u64.rotrSL(W2h, W2l, 19) ^ u64.rotrBL(W2h, W2l, 61) ^ u64.shrSL(W2h, W2l, 6);
|
|
3232
|
-
const SUMl = u64.add4L(s0l, s1l, SHA512_W_L2[i2 - 7], SHA512_W_L2[i2 - 16]);
|
|
3233
|
-
const SUMh = u64.add4H(SUMl, s0h, s1h, SHA512_W_H2[i2 - 7], SHA512_W_H2[i2 - 16]);
|
|
3234
|
-
SHA512_W_H2[i2] = SUMh | 0;
|
|
3235
|
-
SHA512_W_L2[i2] = SUMl | 0;
|
|
3236
|
-
}
|
|
3237
|
-
let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
|
3238
|
-
for (let i2 = 0; i2 < 80; i2++) {
|
|
3239
|
-
const sigma1h = u64.rotrSH(Eh, El, 14) ^ u64.rotrSH(Eh, El, 18) ^ u64.rotrBH(Eh, El, 41);
|
|
3240
|
-
const sigma1l = u64.rotrSL(Eh, El, 14) ^ u64.rotrSL(Eh, El, 18) ^ u64.rotrBL(Eh, El, 41);
|
|
3241
|
-
const CHIh = Eh & Fh ^ ~Eh & Gh;
|
|
3242
|
-
const CHIl = El & Fl ^ ~El & Gl;
|
|
3243
|
-
const T1ll = u64.add5L(Hl, sigma1l, CHIl, SHA512_Kl2[i2], SHA512_W_L2[i2]);
|
|
3244
|
-
const T1h = u64.add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh2[i2], SHA512_W_H2[i2]);
|
|
3245
|
-
const T1l = T1ll | 0;
|
|
3246
|
-
const sigma0h = u64.rotrSH(Ah, Al, 28) ^ u64.rotrBH(Ah, Al, 34) ^ u64.rotrBH(Ah, Al, 39);
|
|
3247
|
-
const sigma0l = u64.rotrSL(Ah, Al, 28) ^ u64.rotrBL(Ah, Al, 34) ^ u64.rotrBL(Ah, Al, 39);
|
|
3248
|
-
const MAJh = Ah & Bh ^ Ah & Ch ^ Bh & Ch;
|
|
3249
|
-
const MAJl = Al & Bl ^ Al & Cl ^ Bl & Cl;
|
|
3250
|
-
Hh = Gh | 0;
|
|
3251
|
-
Hl = Gl | 0;
|
|
3252
|
-
Gh = Fh | 0;
|
|
3253
|
-
Gl = Fl | 0;
|
|
3254
|
-
Fh = Eh | 0;
|
|
3255
|
-
Fl = El | 0;
|
|
3256
|
-
({ h: Eh, l: El } = u64.add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
|
|
3257
|
-
Dh = Ch | 0;
|
|
3258
|
-
Dl = Cl | 0;
|
|
3259
|
-
Ch = Bh | 0;
|
|
3260
|
-
Cl = Bl | 0;
|
|
3261
|
-
Bh = Ah | 0;
|
|
3262
|
-
Bl = Al | 0;
|
|
3263
|
-
const All = u64.add3L(T1l, sigma0l, MAJl);
|
|
3264
|
-
Ah = u64.add3H(All, T1h, sigma0h, MAJh);
|
|
3265
|
-
Al = All | 0;
|
|
3266
|
-
}
|
|
3267
|
-
({ h: Ah, l: Al } = u64.add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
|
|
3268
|
-
({ h: Bh, l: Bl } = u64.add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
|
|
3269
|
-
({ h: Ch, l: Cl } = u64.add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
|
|
3270
|
-
({ h: Dh, l: Dl } = u64.add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
|
|
3271
|
-
({ h: Eh, l: El } = u64.add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
|
|
3272
|
-
({ h: Fh, l: Fl } = u64.add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
|
|
3273
|
-
({ h: Gh, l: Gl } = u64.add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
|
|
3274
|
-
({ h: Hh, l: Hl } = u64.add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
|
|
3275
|
-
this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
|
|
3276
|
-
}
|
|
3277
|
-
roundClean() {
|
|
3278
|
-
(0, utils_ts_1.clean)(SHA512_W_H2, SHA512_W_L2);
|
|
3279
|
-
}
|
|
3280
|
-
destroy() {
|
|
3281
|
-
(0, utils_ts_1.clean)(this.buffer);
|
|
3282
|
-
this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
3283
|
-
}
|
|
3284
|
-
};
|
|
3285
|
-
exports2.SHA512 = SHA512;
|
|
3286
|
-
var SHA384 = class extends SHA512 {
|
|
3287
|
-
constructor() {
|
|
3288
|
-
super(48);
|
|
3289
|
-
this.Ah = _md_ts_1.SHA384_IV[0] | 0;
|
|
3290
|
-
this.Al = _md_ts_1.SHA384_IV[1] | 0;
|
|
3291
|
-
this.Bh = _md_ts_1.SHA384_IV[2] | 0;
|
|
3292
|
-
this.Bl = _md_ts_1.SHA384_IV[3] | 0;
|
|
3293
|
-
this.Ch = _md_ts_1.SHA384_IV[4] | 0;
|
|
3294
|
-
this.Cl = _md_ts_1.SHA384_IV[5] | 0;
|
|
3295
|
-
this.Dh = _md_ts_1.SHA384_IV[6] | 0;
|
|
3296
|
-
this.Dl = _md_ts_1.SHA384_IV[7] | 0;
|
|
3297
|
-
this.Eh = _md_ts_1.SHA384_IV[8] | 0;
|
|
3298
|
-
this.El = _md_ts_1.SHA384_IV[9] | 0;
|
|
3299
|
-
this.Fh = _md_ts_1.SHA384_IV[10] | 0;
|
|
3300
|
-
this.Fl = _md_ts_1.SHA384_IV[11] | 0;
|
|
3301
|
-
this.Gh = _md_ts_1.SHA384_IV[12] | 0;
|
|
3302
|
-
this.Gl = _md_ts_1.SHA384_IV[13] | 0;
|
|
3303
|
-
this.Hh = _md_ts_1.SHA384_IV[14] | 0;
|
|
3304
|
-
this.Hl = _md_ts_1.SHA384_IV[15] | 0;
|
|
3305
|
-
}
|
|
3306
|
-
};
|
|
3307
|
-
exports2.SHA384 = SHA384;
|
|
3308
|
-
var T224_IV = /* @__PURE__ */ Uint32Array.from([
|
|
3309
|
-
2352822216,
|
|
3310
|
-
424955298,
|
|
3311
|
-
1944164710,
|
|
3312
|
-
2312950998,
|
|
3313
|
-
502970286,
|
|
3314
|
-
855612546,
|
|
3315
|
-
1738396948,
|
|
3316
|
-
1479516111,
|
|
3317
|
-
258812777,
|
|
3318
|
-
2077511080,
|
|
3319
|
-
2011393907,
|
|
3320
|
-
79989058,
|
|
3321
|
-
1067287976,
|
|
3322
|
-
1780299464,
|
|
3323
|
-
286451373,
|
|
3324
|
-
2446758561
|
|
3325
|
-
]);
|
|
3326
|
-
var T256_IV = /* @__PURE__ */ Uint32Array.from([
|
|
3327
|
-
573645204,
|
|
3328
|
-
4230739756,
|
|
3329
|
-
2673172387,
|
|
3330
|
-
3360449730,
|
|
3331
|
-
596883563,
|
|
3332
|
-
1867755857,
|
|
3333
|
-
2520282905,
|
|
3334
|
-
1497426621,
|
|
3335
|
-
2519219938,
|
|
3336
|
-
2827943907,
|
|
3337
|
-
3193839141,
|
|
3338
|
-
1401305490,
|
|
3339
|
-
721525244,
|
|
3340
|
-
746961066,
|
|
3341
|
-
246885852,
|
|
3342
|
-
2177182882
|
|
3343
|
-
]);
|
|
3344
|
-
var SHA512_224 = class extends SHA512 {
|
|
3345
|
-
constructor() {
|
|
3346
|
-
super(28);
|
|
3347
|
-
this.Ah = T224_IV[0] | 0;
|
|
3348
|
-
this.Al = T224_IV[1] | 0;
|
|
3349
|
-
this.Bh = T224_IV[2] | 0;
|
|
3350
|
-
this.Bl = T224_IV[3] | 0;
|
|
3351
|
-
this.Ch = T224_IV[4] | 0;
|
|
3352
|
-
this.Cl = T224_IV[5] | 0;
|
|
3353
|
-
this.Dh = T224_IV[6] | 0;
|
|
3354
|
-
this.Dl = T224_IV[7] | 0;
|
|
3355
|
-
this.Eh = T224_IV[8] | 0;
|
|
3356
|
-
this.El = T224_IV[9] | 0;
|
|
3357
|
-
this.Fh = T224_IV[10] | 0;
|
|
3358
|
-
this.Fl = T224_IV[11] | 0;
|
|
3359
|
-
this.Gh = T224_IV[12] | 0;
|
|
3360
|
-
this.Gl = T224_IV[13] | 0;
|
|
3361
|
-
this.Hh = T224_IV[14] | 0;
|
|
3362
|
-
this.Hl = T224_IV[15] | 0;
|
|
3363
|
-
}
|
|
3364
|
-
};
|
|
3365
|
-
exports2.SHA512_224 = SHA512_224;
|
|
3366
|
-
var SHA512_256 = class extends SHA512 {
|
|
3367
|
-
constructor() {
|
|
3368
|
-
super(32);
|
|
3369
|
-
this.Ah = T256_IV[0] | 0;
|
|
3370
|
-
this.Al = T256_IV[1] | 0;
|
|
3371
|
-
this.Bh = T256_IV[2] | 0;
|
|
3372
|
-
this.Bl = T256_IV[3] | 0;
|
|
3373
|
-
this.Ch = T256_IV[4] | 0;
|
|
3374
|
-
this.Cl = T256_IV[5] | 0;
|
|
3375
|
-
this.Dh = T256_IV[6] | 0;
|
|
3376
|
-
this.Dl = T256_IV[7] | 0;
|
|
3377
|
-
this.Eh = T256_IV[8] | 0;
|
|
3378
|
-
this.El = T256_IV[9] | 0;
|
|
3379
|
-
this.Fh = T256_IV[10] | 0;
|
|
3380
|
-
this.Fl = T256_IV[11] | 0;
|
|
3381
|
-
this.Gh = T256_IV[12] | 0;
|
|
3382
|
-
this.Gl = T256_IV[13] | 0;
|
|
3383
|
-
this.Hh = T256_IV[14] | 0;
|
|
3384
|
-
this.Hl = T256_IV[15] | 0;
|
|
3385
|
-
}
|
|
3386
|
-
};
|
|
3387
|
-
exports2.SHA512_256 = SHA512_256;
|
|
3388
|
-
exports2.sha256 = (0, utils_ts_1.createHasher)(() => new SHA256());
|
|
3389
|
-
exports2.sha224 = (0, utils_ts_1.createHasher)(() => new SHA224());
|
|
3390
|
-
exports2.sha512 = (0, utils_ts_1.createHasher)(() => new SHA512());
|
|
3391
|
-
exports2.sha384 = (0, utils_ts_1.createHasher)(() => new SHA384());
|
|
3392
|
-
exports2.sha512_256 = (0, utils_ts_1.createHasher)(() => new SHA512_256());
|
|
3393
|
-
exports2.sha512_224 = (0, utils_ts_1.createHasher)(() => new SHA512_224());
|
|
3394
|
-
}
|
|
3395
|
-
});
|
|
3396
|
-
|
|
3397
|
-
// ../../node_modules/@noble/hashes/sha256.js
|
|
3398
|
-
var require_sha256 = __commonJS({
|
|
3399
|
-
"../../node_modules/@noble/hashes/sha256.js"(exports2) {
|
|
3400
|
-
"use strict";
|
|
3401
|
-
init_esbuild_shims();
|
|
3402
|
-
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
3403
|
-
exports2.sha224 = exports2.SHA224 = exports2.sha256 = exports2.SHA256 = void 0;
|
|
3404
|
-
var sha2_ts_1 = require_sha2();
|
|
3405
|
-
exports2.SHA256 = sha2_ts_1.SHA256;
|
|
3406
|
-
exports2.sha256 = sha2_ts_1.sha256;
|
|
3407
|
-
exports2.SHA224 = sha2_ts_1.SHA224;
|
|
3408
|
-
exports2.sha224 = sha2_ts_1.sha224;
|
|
3409
|
-
}
|
|
3410
|
-
});
|
|
3411
|
-
|
|
3412
|
-
// ../crypto/dist/suites/bsv-ecdsa.js
|
|
3413
|
-
var require_bsv_ecdsa = __commonJS({
|
|
3414
|
-
"../crypto/dist/suites/bsv-ecdsa.js"(exports2) {
|
|
3415
|
-
"use strict";
|
|
3416
|
-
init_esbuild_shims();
|
|
3417
|
-
var __createBinding = exports2 && exports2.__createBinding || (Object.create ? (function(o2, m2, k2, k22) {
|
|
3418
|
-
if (k22 === void 0) k22 = k2;
|
|
3419
|
-
var desc = Object.getOwnPropertyDescriptor(m2, k2);
|
|
3420
|
-
if (!desc || ("get" in desc ? !m2.__esModule : desc.writable || desc.configurable)) {
|
|
3421
|
-
desc = { enumerable: true, get: function() {
|
|
3422
|
-
return m2[k2];
|
|
3423
|
-
} };
|
|
3424
|
-
}
|
|
3425
|
-
Object.defineProperty(o2, k22, desc);
|
|
3426
|
-
}) : (function(o2, m2, k2, k22) {
|
|
3427
|
-
if (k22 === void 0) k22 = k2;
|
|
3428
|
-
o2[k22] = m2[k2];
|
|
3429
|
-
}));
|
|
3430
|
-
var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? (function(o2, v2) {
|
|
3431
|
-
Object.defineProperty(o2, "default", { enumerable: true, value: v2 });
|
|
3432
|
-
}) : function(o2, v2) {
|
|
3433
|
-
o2["default"] = v2;
|
|
3434
|
-
});
|
|
3435
|
-
var __importStar = exports2 && exports2.__importStar || /* @__PURE__ */ (function() {
|
|
3436
|
-
var ownKeys = function(o2) {
|
|
3437
|
-
ownKeys = Object.getOwnPropertyNames || function(o3) {
|
|
3438
|
-
var ar = [];
|
|
3439
|
-
for (var k2 in o3) if (Object.prototype.hasOwnProperty.call(o3, k2)) ar[ar.length] = k2;
|
|
3440
|
-
return ar;
|
|
3441
|
-
};
|
|
3442
|
-
return ownKeys(o2);
|
|
3443
|
-
};
|
|
3444
|
-
return function(mod) {
|
|
3445
|
-
if (mod && mod.__esModule) return mod;
|
|
3446
|
-
var result = {};
|
|
3447
|
-
if (mod != null) {
|
|
3448
|
-
for (var k2 = ownKeys(mod), i2 = 0; i2 < k2.length; i2++) if (k2[i2] !== "default") __createBinding(result, mod, k2[i2]);
|
|
3449
|
-
}
|
|
3450
|
-
__setModuleDefault(result, mod);
|
|
3451
|
-
return result;
|
|
3452
|
-
};
|
|
3453
|
-
})();
|
|
3454
|
-
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
3455
|
-
exports2.BsvEcdsaSuite = void 0;
|
|
3456
|
-
var secp256k1 = __importStar((init_secp256k1(), __toCommonJS(secp256k1_exports)));
|
|
3457
|
-
var hmac_1 = require_hmac();
|
|
3458
|
-
var sha256_1 = require_sha256();
|
|
3459
|
-
var utils_1 = require_utils();
|
|
3460
|
-
secp256k1.etc.hmacSha256Sync = (key, ...msgs) => (0, hmac_1.hmac)(sha256_1.sha256, key, secp256k1.etc.concatBytes(...msgs));
|
|
3461
|
-
var BsvEcdsaSuite2 = class {
|
|
3462
|
-
constructor() {
|
|
3463
|
-
__publicField(this, "suiteId", "bsv-ecdsa-secp256k1");
|
|
3464
|
-
__publicField(this, "version", "1.0.0");
|
|
3465
|
-
}
|
|
3466
|
-
async generateKeypair() {
|
|
3467
|
-
const privateKey = secp256k1.utils.randomPrivateKey();
|
|
3468
|
-
const publicKey = secp256k1.getPublicKey(privateKey, true);
|
|
3469
|
-
return {
|
|
3470
|
-
privateKey,
|
|
3471
|
-
publicKey
|
|
3472
|
-
};
|
|
3473
|
-
}
|
|
3474
|
-
async sign(privateKey, message) {
|
|
3475
|
-
try {
|
|
3476
|
-
const signature = await secp256k1.sign(message, privateKey);
|
|
3477
|
-
return signature.toCompactRawBytes();
|
|
3478
|
-
} catch (error) {
|
|
3479
|
-
throw new Error(`BsvEcdsaSuite signing failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
3480
|
-
}
|
|
3481
|
-
}
|
|
3482
|
-
async verify(publicKey, message, signature) {
|
|
3483
|
-
try {
|
|
3484
|
-
return secp256k1.verify(signature, message, publicKey);
|
|
3485
|
-
} catch (error) {
|
|
3486
|
-
return false;
|
|
3487
|
-
}
|
|
3488
|
-
}
|
|
3489
|
-
exportPublicKey(pub) {
|
|
3490
|
-
return (0, utils_1.bytesToHex)(pub);
|
|
3491
|
-
}
|
|
3492
|
-
importPublicKey(encoded) {
|
|
3493
|
-
return (0, utils_1.hexToBytes)(encoded);
|
|
3494
|
-
}
|
|
3495
|
-
exportPrivateKey(priv) {
|
|
3496
|
-
return (0, utils_1.bytesToHex)(priv);
|
|
3497
|
-
}
|
|
3498
|
-
importPrivateKey(encoded) {
|
|
3499
|
-
const bytes = (0, utils_1.hexToBytes)(encoded);
|
|
3500
|
-
if (bytes.length !== 32) {
|
|
3501
|
-
throw new Error("Private key must be 32 bytes");
|
|
3502
|
-
}
|
|
3503
|
-
return bytes;
|
|
3504
|
-
}
|
|
3505
|
-
};
|
|
3506
|
-
exports2.BsvEcdsaSuite = BsvEcdsaSuite2;
|
|
3507
|
-
}
|
|
3508
|
-
});
|
|
3509
|
-
|
|
3510
|
-
// ../../node_modules/dilithium-crystals/dist/index.js
|
|
3511
|
-
var require_dist = __commonJS({
|
|
3512
|
-
"../../node_modules/dilithium-crystals/dist/index.js"(exports, module) {
|
|
3513
|
-
init_esbuild_shims();
|
|
3514
|
-
var dilithium = (function() {
|
|
3515
|
-
var A, I, g, C = {};
|
|
3516
|
-
function B(A2, I3) {
|
|
3517
|
-
if (0 === A2) return I3;
|
|
3518
|
-
throw new Error("Dilithium error: " + A2);
|
|
3519
|
-
}
|
|
3520
|
-
function Q(A2, I3) {
|
|
3521
|
-
return new Uint8Array(new Uint8Array(C.HEAPU8.buffer, A2, I3));
|
|
3522
|
-
}
|
|
3523
|
-
function i(A2) {
|
|
3524
|
-
try {
|
|
3525
|
-
C._free(A2);
|
|
3526
|
-
} catch (A3) {
|
|
3527
|
-
setTimeout((function() {
|
|
3528
|
-
throw A3;
|
|
3529
|
-
}), 0);
|
|
3530
|
-
}
|
|
3531
|
-
}
|
|
3532
|
-
C.ready = new Promise((function(A, I) {
|
|
3533
|
-
function g(A2) {
|
|
3534
|
-
return g = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(A3) {
|
|
3535
|
-
return typeof A3;
|
|
3536
|
-
} : function(A3) {
|
|
3537
|
-
return A3 && "function" == typeof Symbol && A3.constructor === Symbol && A3 !== Symbol.prototype ? "symbol" : typeof A3;
|
|
3538
|
-
}, g(A2);
|
|
3539
|
-
}
|
|
3540
|
-
(Q = {}).onAbort = I, Q.onRuntimeInitialized = function() {
|
|
3541
|
-
try {
|
|
3542
|
-
Q._dilithiumjs_public_key_bytes(), A(Q);
|
|
3543
|
-
} catch (A2) {
|
|
3544
|
-
I(A2);
|
|
3545
|
-
}
|
|
3546
|
-
};
|
|
3547
|
-
var C, B, Q = void 0 !== Q ? Q : {}, i = Object.assign({}, Q), E = function(A2, I3) {
|
|
3548
|
-
throw I3;
|
|
3549
|
-
}, o = "object" == ("undefined" == typeof window ? "undefined" : g(window)), n = "function" == typeof importScripts, r = "object" == ("undefined" == typeof process ? "undefined" : g(process)) && "object" == g(process.versions) && "string" == typeof process.versions.node, t = "";
|
|
3550
|
-
if (r) {
|
|
3551
|
-
var a = eval("require")("fs"), e = eval("require")("path");
|
|
3552
|
-
t = n ? e.dirname(t) + "/" : __dirname + "/", C = function(A2, I3) {
|
|
3553
|
-
var g2 = x(A2);
|
|
3554
|
-
return g2 ? I3 ? g2 : g2.toString() : (A2 = q(A2) ? new URL(A2) : e.normalize(A2), a.readFileSync(A2, I3 ? void 0 : "utf8"));
|
|
3555
|
-
}, B = function(A2) {
|
|
3556
|
-
var I3 = C(A2, true);
|
|
3557
|
-
return I3.buffer || (I3 = new Uint8Array(I3)), I3;
|
|
3558
|
-
}, function(A2, I3, g2) {
|
|
3559
|
-
var C3 = !(arguments.length > 3 && void 0 !== arguments[3]) || arguments[3], B2 = x(A2);
|
|
3560
|
-
B2 && I3(B2), A2 = q(A2) ? new URL(A2) : e.normalize(A2), a.readFile(A2, C3 ? void 0 : "utf8", (function(A3, B3) {
|
|
3561
|
-
A3 ? g2(A3) : I3(C3 ? B3.buffer : B3);
|
|
3562
|
-
}));
|
|
3563
|
-
}, !Q.thisProgram && process.argv.length > 1 && process.argv[1].replace(/\\/g, "/"), process.argv.slice(2), "undefined" != typeof module && (module.exports = Q), process.on("uncaughtException", (function(A2) {
|
|
3564
|
-
if (!("unwind" === A2 || A2 instanceof p || A2.context instanceof p)) throw A2;
|
|
3565
|
-
})), E = function(A2, I3) {
|
|
3566
|
-
throw process.exitCode = A2, I3;
|
|
3567
|
-
}, Q.inspect = function() {
|
|
3568
|
-
return "[Emscripten Module object]";
|
|
3569
|
-
};
|
|
3570
|
-
} else (o || n) && (n ? t = self.location.href : "undefined" != typeof document && document.currentScript && (t = document.currentScript.src), t = 0 !== t.indexOf("blob:") ? t.substr(0, t.replace(/[?#].*/, "").lastIndexOf("/") + 1) : "", C = function(A2) {
|
|
3571
|
-
try {
|
|
3572
|
-
var I3 = new XMLHttpRequest();
|
|
3573
|
-
return I3.open("GET", A2, false), I3.send(null), I3.responseText;
|
|
3574
|
-
} catch (I4) {
|
|
3575
|
-
var g2 = x(A2);
|
|
3576
|
-
if (g2) return (function(A3) {
|
|
3577
|
-
for (var I5 = [], g3 = 0; g3 < A3.length; g3++) {
|
|
3578
|
-
var C3 = A3[g3];
|
|
3579
|
-
C3 > 255 && (C3 &= 255), I5.push(String.fromCharCode(C3));
|
|
3580
|
-
}
|
|
3581
|
-
return I5.join("");
|
|
3582
|
-
})(g2);
|
|
3583
|
-
throw I4;
|
|
3584
|
-
}
|
|
3585
|
-
}, n && (B = function(A2) {
|
|
3586
|
-
try {
|
|
3587
|
-
var I3 = new XMLHttpRequest();
|
|
3588
|
-
return I3.open("GET", A2, false), I3.responseType = "arraybuffer", I3.send(null), new Uint8Array(I3.response);
|
|
3589
|
-
} catch (I4) {
|
|
3590
|
-
var g2 = x(A2);
|
|
3591
|
-
if (g2) return g2;
|
|
3592
|
-
throw I4;
|
|
3593
|
-
}
|
|
3594
|
-
}), function(A2, I3, g2) {
|
|
3595
|
-
var C3 = new XMLHttpRequest();
|
|
3596
|
-
C3.open("GET", A2, true), C3.responseType = "arraybuffer", C3.onload = function() {
|
|
3597
|
-
if (200 == C3.status || 0 == C3.status && C3.response) I3(C3.response);
|
|
3598
|
-
else {
|
|
3599
|
-
var B2 = x(A2);
|
|
3600
|
-
B2 ? I3(B2.buffer) : g2();
|
|
3601
|
-
}
|
|
3602
|
-
}, C3.onerror = g2, C3.send(null);
|
|
3603
|
-
}, function(A2) {
|
|
3604
|
-
return document.title = A2;
|
|
3605
|
-
});
|
|
3606
|
-
Q.print || console.log.bind(console);
|
|
3607
|
-
var f, D = Q.printErr || console.error.bind(console);
|
|
3608
|
-
Object.assign(Q, i), i = null, Q.arguments && Q.arguments, Q.thisProgram && Q.thisProgram, Q.quit && (E = Q.quit), Q.wasmBinary && (f = Q.wasmBinary);
|
|
3609
|
-
var c, G = Q.noExitRuntime || true;
|
|
3610
|
-
"object" != ("undefined" == typeof WebAssembly ? "undefined" : g(WebAssembly)) && U("no native wasm support detected");
|
|
3611
|
-
var h, y, u, s, F = false;
|
|
3612
|
-
var Y = [], N = [], w = [];
|
|
3613
|
-
var S = 0, k = null, H = null;
|
|
3614
|
-
function U(A2) {
|
|
3615
|
-
throw Q.onAbort && Q.onAbort(A2), D(A2 = "Aborted(" + A2 + ")"), F = true, 1, A2 += ". Build with -sASSERTIONS for more info.", new WebAssembly.RuntimeError(A2);
|
|
3616
|
-
}
|
|
3617
|
-
var R, d, M = "data:application/octet-stream;base64,";
|
|
3618
|
-
function J(A2) {
|
|
3619
|
-
return A2.startsWith(M);
|
|
3620
|
-
}
|
|
3621
|
-
function q(A2) {
|
|
3622
|
-
return A2.startsWith("file://");
|
|
1071
|
+
function q(A2) {
|
|
1072
|
+
return A2.startsWith("file://");
|
|
3623
1073
|
}
|
|
3624
1074
|
function l(A2) {
|
|
3625
1075
|
return Promise.resolve().then((function() {
|
|
@@ -4965,206 +2415,1470 @@ var LumenKeys = (() => {
|
|
|
4965
2415
|
}
|
|
4966
2416
|
});
|
|
4967
2417
|
|
|
4968
|
-
//
|
|
4969
|
-
var
|
|
4970
|
-
|
|
4971
|
-
|
|
4972
|
-
|
|
4973
|
-
|
|
4974
|
-
|
|
4975
|
-
|
|
4976
|
-
|
|
4977
|
-
|
|
4978
|
-
|
|
4979
|
-
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
|
|
4984
|
-
|
|
4985
|
-
|
|
4986
|
-
|
|
4987
|
-
|
|
4988
|
-
|
|
4989
|
-
|
|
4990
|
-
|
|
4991
|
-
|
|
4992
|
-
|
|
4993
|
-
|
|
4994
|
-
|
|
4995
|
-
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
return ownKeys(o2);
|
|
4999
|
-
};
|
|
5000
|
-
return function(mod) {
|
|
5001
|
-
if (mod && mod.__esModule) return mod;
|
|
5002
|
-
var result = {};
|
|
5003
|
-
if (mod != null) {
|
|
5004
|
-
for (var k2 = ownKeys(mod), i2 = 0; i2 < k2.length; i2++) if (k2[i2] !== "default") __createBinding(result, mod, k2[i2]);
|
|
5005
|
-
}
|
|
5006
|
-
__setModuleDefault(result, mod);
|
|
5007
|
-
return result;
|
|
5008
|
-
};
|
|
5009
|
-
})();
|
|
5010
|
-
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
5011
|
-
exports2.MlDsaSuite = exports2.MlDsa87Suite = void 0;
|
|
5012
|
-
var utils_1 = require_utils();
|
|
5013
|
-
var dilithiumLib = null;
|
|
5014
|
-
async function getDilithium() {
|
|
5015
|
-
if (!dilithiumLib) {
|
|
5016
|
-
dilithiumLib = await Promise.resolve().then(() => __importStar(require_dist()));
|
|
5017
|
-
}
|
|
5018
|
-
return dilithiumLib;
|
|
2418
|
+
// src/browser.ts
|
|
2419
|
+
var browser_exports = {};
|
|
2420
|
+
__export(browser_exports, {
|
|
2421
|
+
InMemoryKeyStorage: () => InMemoryKeyStorage,
|
|
2422
|
+
createKeySDK: () => createKeySDK,
|
|
2423
|
+
default: () => browser_default
|
|
2424
|
+
});
|
|
2425
|
+
init_esbuild_shims();
|
|
2426
|
+
|
|
2427
|
+
// src/sdk.ts
|
|
2428
|
+
init_esbuild_shims();
|
|
2429
|
+
|
|
2430
|
+
// ../crypto/dist/esm/index.js
|
|
2431
|
+
init_esbuild_shims();
|
|
2432
|
+
|
|
2433
|
+
// ../crypto/dist/esm/types.js
|
|
2434
|
+
init_esbuild_shims();
|
|
2435
|
+
|
|
2436
|
+
// ../crypto/dist/esm/registry.js
|
|
2437
|
+
init_esbuild_shims();
|
|
2438
|
+
var SignatureSuiteRegistry = class {
|
|
2439
|
+
constructor() {
|
|
2440
|
+
__publicField(this, "suites", /* @__PURE__ */ new Map());
|
|
2441
|
+
}
|
|
2442
|
+
/**
|
|
2443
|
+
* Register a signature suite implementation
|
|
2444
|
+
*/
|
|
2445
|
+
register(suite) {
|
|
2446
|
+
if (this.suites.has(suite.suiteId)) {
|
|
2447
|
+
throw new Error(`Signature suite already registered: ${suite.suiteId}`);
|
|
5019
2448
|
}
|
|
5020
|
-
|
|
5021
|
-
|
|
5022
|
-
|
|
5023
|
-
|
|
5024
|
-
|
|
5025
|
-
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
|
|
5036
|
-
|
|
5037
|
-
|
|
5038
|
-
|
|
5039
|
-
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
|
|
5044
|
-
|
|
5045
|
-
|
|
5046
|
-
|
|
5047
|
-
|
|
5048
|
-
|
|
5049
|
-
|
|
5050
|
-
|
|
5051
|
-
|
|
5052
|
-
|
|
5053
|
-
|
|
5054
|
-
|
|
5055
|
-
|
|
5056
|
-
|
|
5057
|
-
|
|
5058
|
-
|
|
5059
|
-
|
|
5060
|
-
|
|
5061
|
-
|
|
5062
|
-
|
|
5063
|
-
|
|
5064
|
-
|
|
5065
|
-
|
|
5066
|
-
|
|
5067
|
-
|
|
5068
|
-
|
|
5069
|
-
|
|
5070
|
-
|
|
2449
|
+
this.suites.set(suite.suiteId, suite);
|
|
2450
|
+
}
|
|
2451
|
+
/**
|
|
2452
|
+
* Get a signature suite by ID
|
|
2453
|
+
* @throws Error if suite is not registered
|
|
2454
|
+
*/
|
|
2455
|
+
getSuite(suiteId) {
|
|
2456
|
+
const suite = this.suites.get(suiteId);
|
|
2457
|
+
if (!suite) {
|
|
2458
|
+
throw new Error(`Unknown signature suite: ${suiteId}. Available: ${this.listSuites().join(", ")}`);
|
|
2459
|
+
}
|
|
2460
|
+
return suite;
|
|
2461
|
+
}
|
|
2462
|
+
/**
|
|
2463
|
+
* Check if a suite is registered
|
|
2464
|
+
*/
|
|
2465
|
+
hasSuite(suiteId) {
|
|
2466
|
+
return this.suites.has(suiteId);
|
|
2467
|
+
}
|
|
2468
|
+
/**
|
|
2469
|
+
* List all registered suite IDs
|
|
2470
|
+
*/
|
|
2471
|
+
listSuites() {
|
|
2472
|
+
return [...this.suites.keys()];
|
|
2473
|
+
}
|
|
2474
|
+
/**
|
|
2475
|
+
* Unregister a suite (primarily for testing)
|
|
2476
|
+
*/
|
|
2477
|
+
unregister(suiteId) {
|
|
2478
|
+
return this.suites.delete(suiteId);
|
|
2479
|
+
}
|
|
2480
|
+
/**
|
|
2481
|
+
* Clear all registered suites (primarily for testing)
|
|
2482
|
+
*/
|
|
2483
|
+
clear() {
|
|
2484
|
+
this.suites.clear();
|
|
2485
|
+
}
|
|
2486
|
+
};
|
|
2487
|
+
var globalRegistry = new SignatureSuiteRegistry();
|
|
2488
|
+
|
|
2489
|
+
// ../crypto/dist/esm/utils.js
|
|
2490
|
+
init_esbuild_shims();
|
|
2491
|
+
function bytesToHex(bytes) {
|
|
2492
|
+
return Array.from(bytes).map((b2) => b2.toString(16).padStart(2, "0")).join("");
|
|
2493
|
+
}
|
|
2494
|
+
function hexToBytes(hex) {
|
|
2495
|
+
if (hex.length % 2 !== 0) {
|
|
2496
|
+
throw new Error("Hex string must have even length");
|
|
2497
|
+
}
|
|
2498
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
2499
|
+
for (let i2 = 0; i2 < hex.length; i2 += 2) {
|
|
2500
|
+
bytes[i2 / 2] = parseInt(hex.slice(i2, i2 + 2), 16);
|
|
2501
|
+
}
|
|
2502
|
+
return bytes;
|
|
2503
|
+
}
|
|
2504
|
+
async function hashBytes(bytes, algorithm) {
|
|
2505
|
+
if (algorithm === "sha256") {
|
|
2506
|
+
const crypto = await Promise.resolve().then(() => (init_crypto_browser_shim(), crypto_browser_shim_exports));
|
|
2507
|
+
return new Uint8Array(crypto.createHash("sha256").update(bytes).digest());
|
|
2508
|
+
} else if (algorithm === "sha512") {
|
|
2509
|
+
const crypto = await Promise.resolve().then(() => (init_crypto_browser_shim(), crypto_browser_shim_exports));
|
|
2510
|
+
return new Uint8Array(crypto.createHash("sha512").update(bytes).digest());
|
|
2511
|
+
} else if (algorithm === "sha3-256") {
|
|
2512
|
+
const crypto = await Promise.resolve().then(() => (init_crypto_browser_shim(), crypto_browser_shim_exports));
|
|
2513
|
+
return new Uint8Array(crypto.createHash("sha3-256").update(bytes).digest());
|
|
2514
|
+
}
|
|
2515
|
+
throw new Error(`Unsupported hash algorithm: ${algorithm}`);
|
|
2516
|
+
}
|
|
2517
|
+
|
|
2518
|
+
// ../crypto/dist/esm/signing.js
|
|
2519
|
+
init_esbuild_shims();
|
|
2520
|
+
|
|
2521
|
+
// ../crypto/dist/esm/key-registry.js
|
|
2522
|
+
init_esbuild_shims();
|
|
2523
|
+
var InMemoryKeyStorage = class {
|
|
2524
|
+
constructor() {
|
|
2525
|
+
__publicField(this, "keys", /* @__PURE__ */ new Map());
|
|
2526
|
+
}
|
|
2527
|
+
async store(keyId, keypair, meta) {
|
|
2528
|
+
this.keys.set(keyId, { keypair, meta });
|
|
2529
|
+
}
|
|
2530
|
+
async load(keyId) {
|
|
2531
|
+
return this.keys.get(keyId) || null;
|
|
2532
|
+
}
|
|
2533
|
+
async list(filter) {
|
|
2534
|
+
const allMeta = Array.from(this.keys.values()).map((k2) => k2.meta);
|
|
2535
|
+
if (!filter) {
|
|
2536
|
+
return allMeta;
|
|
2537
|
+
}
|
|
2538
|
+
return allMeta.filter((meta) => {
|
|
2539
|
+
return Object.entries(filter).every(([key, value]) => {
|
|
2540
|
+
if (key === "usage" && Array.isArray(value)) {
|
|
2541
|
+
return value.some((u2) => meta.usage.includes(u2));
|
|
5071
2542
|
}
|
|
5072
|
-
return
|
|
5073
|
-
}
|
|
2543
|
+
return meta[key] === value;
|
|
2544
|
+
});
|
|
2545
|
+
});
|
|
2546
|
+
}
|
|
2547
|
+
async delete(keyId) {
|
|
2548
|
+
this.keys.delete(keyId);
|
|
2549
|
+
}
|
|
2550
|
+
async updateMeta(keyId, updates) {
|
|
2551
|
+
const existing = this.keys.get(keyId);
|
|
2552
|
+
if (!existing) {
|
|
2553
|
+
throw new Error(`Key not found: ${keyId}`);
|
|
2554
|
+
}
|
|
2555
|
+
this.keys.set(keyId, {
|
|
2556
|
+
keypair: existing.keypair,
|
|
2557
|
+
meta: { ...existing.meta, ...updates }
|
|
2558
|
+
});
|
|
2559
|
+
}
|
|
2560
|
+
/**
|
|
2561
|
+
* Clear all keys (testing only).
|
|
2562
|
+
*/
|
|
2563
|
+
clear() {
|
|
2564
|
+
this.keys.clear();
|
|
2565
|
+
}
|
|
2566
|
+
};
|
|
2567
|
+
var KeyRegistry = class {
|
|
2568
|
+
constructor(storage = new InMemoryKeyStorage()) {
|
|
2569
|
+
__publicField(this, "storage");
|
|
2570
|
+
this.storage = storage;
|
|
2571
|
+
}
|
|
2572
|
+
/**
|
|
2573
|
+
* Register a new keypair with metadata.
|
|
2574
|
+
*/
|
|
2575
|
+
async registerKey(keyId, keypair, suiteId, options = {}) {
|
|
2576
|
+
const meta = {
|
|
2577
|
+
keyId,
|
|
2578
|
+
suiteId,
|
|
2579
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2580
|
+
expiresAt: options.expiresAt,
|
|
2581
|
+
usage: options.usage || ["signing"],
|
|
2582
|
+
cryptoProfileVersion: options.cryptoProfileVersion || "1.0.0",
|
|
2583
|
+
status: options.status || "active"
|
|
2584
|
+
};
|
|
2585
|
+
await this.storage.store(keyId, keypair, meta);
|
|
2586
|
+
return meta;
|
|
2587
|
+
}
|
|
2588
|
+
/**
|
|
2589
|
+
* Get a keypair and its metadata.
|
|
2590
|
+
*/
|
|
2591
|
+
async getKey(keyId) {
|
|
2592
|
+
return await this.storage.load(keyId);
|
|
2593
|
+
}
|
|
2594
|
+
/**
|
|
2595
|
+
* Get only the public key (no private key).
|
|
2596
|
+
*/
|
|
2597
|
+
async getPublicKey(keyId) {
|
|
2598
|
+
const result = await this.storage.load(keyId);
|
|
2599
|
+
if (!result)
|
|
2600
|
+
return null;
|
|
2601
|
+
return {
|
|
2602
|
+
publicKey: result.keypair.publicKey,
|
|
2603
|
+
meta: result.meta
|
|
5074
2604
|
};
|
|
5075
|
-
|
|
5076
|
-
|
|
5077
|
-
|
|
5078
|
-
|
|
5079
|
-
|
|
5080
|
-
|
|
5081
|
-
|
|
5082
|
-
|
|
5083
|
-
|
|
5084
|
-
|
|
5085
|
-
|
|
5086
|
-
|
|
5087
|
-
|
|
5088
|
-
|
|
5089
|
-
|
|
5090
|
-
|
|
5091
|
-
exportPublicKey(pub) {
|
|
5092
|
-
return this.impl.exportPublicKey(pub);
|
|
5093
|
-
}
|
|
5094
|
-
importPublicKey(encoded) {
|
|
5095
|
-
return this.impl.importPublicKey(encoded);
|
|
2605
|
+
}
|
|
2606
|
+
/**
|
|
2607
|
+
* List all keys matching optional filter.
|
|
2608
|
+
*/
|
|
2609
|
+
async listKeys(filter) {
|
|
2610
|
+
return await this.storage.list(filter);
|
|
2611
|
+
}
|
|
2612
|
+
/**
|
|
2613
|
+
* List only active, non-expired keys.
|
|
2614
|
+
*/
|
|
2615
|
+
async listActiveKeys(filter) {
|
|
2616
|
+
const allKeys = await this.storage.list(filter);
|
|
2617
|
+
const now = /* @__PURE__ */ new Date();
|
|
2618
|
+
return allKeys.filter((meta) => {
|
|
2619
|
+
if (meta.status && meta.status !== "active") {
|
|
2620
|
+
return false;
|
|
5096
2621
|
}
|
|
5097
|
-
|
|
5098
|
-
return
|
|
2622
|
+
if (meta.expiresAt && new Date(meta.expiresAt) < now) {
|
|
2623
|
+
return false;
|
|
5099
2624
|
}
|
|
5100
|
-
|
|
5101
|
-
|
|
2625
|
+
return true;
|
|
2626
|
+
});
|
|
2627
|
+
}
|
|
2628
|
+
/**
|
|
2629
|
+
* Rotate a key: generate new keypair, mark old as 'rotated'.
|
|
2630
|
+
*
|
|
2631
|
+
* Returns the new key's metadata.
|
|
2632
|
+
*/
|
|
2633
|
+
async rotateKey(oldKeyId, newKeyId, newKeypair) {
|
|
2634
|
+
const oldKey = await this.storage.load(oldKeyId);
|
|
2635
|
+
if (!oldKey) {
|
|
2636
|
+
throw new Error(`Cannot rotate: key not found: ${oldKeyId}`);
|
|
2637
|
+
}
|
|
2638
|
+
await this.storage.updateMeta(oldKeyId, {
|
|
2639
|
+
status: "rotated"
|
|
2640
|
+
});
|
|
2641
|
+
await this.registerKey(newKeyId, newKeypair, oldKey.meta.suiteId, {
|
|
2642
|
+
usage: oldKey.meta.usage,
|
|
2643
|
+
cryptoProfileVersion: oldKey.meta.cryptoProfileVersion,
|
|
2644
|
+
expiresAt: oldKey.meta.expiresAt,
|
|
2645
|
+
status: "active"
|
|
2646
|
+
});
|
|
2647
|
+
await this.storage.updateMeta(newKeyId, {
|
|
2648
|
+
rotatedFrom: oldKeyId
|
|
2649
|
+
});
|
|
2650
|
+
const result = await this.storage.load(newKeyId);
|
|
2651
|
+
return result.meta;
|
|
2652
|
+
}
|
|
2653
|
+
/**
|
|
2654
|
+
* Revoke a key (marks as unusable, but doesn't delete).
|
|
2655
|
+
*/
|
|
2656
|
+
async revokeKey(keyId, reason) {
|
|
2657
|
+
await this.storage.updateMeta(keyId, {
|
|
2658
|
+
status: "revoked",
|
|
2659
|
+
revokedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
2660
|
+
});
|
|
2661
|
+
}
|
|
2662
|
+
/**
|
|
2663
|
+
* Delete a key permanently (use with caution).
|
|
2664
|
+
*/
|
|
2665
|
+
async deleteKey(keyId) {
|
|
2666
|
+
await this.storage.delete(keyId);
|
|
2667
|
+
}
|
|
2668
|
+
/**
|
|
2669
|
+
* Mark expired keys as 'expired' status.
|
|
2670
|
+
* Returns count of keys marked expired.
|
|
2671
|
+
*/
|
|
2672
|
+
async markExpiredKeys() {
|
|
2673
|
+
const allKeys = await this.storage.list();
|
|
2674
|
+
const now = /* @__PURE__ */ new Date();
|
|
2675
|
+
let count = 0;
|
|
2676
|
+
for (const meta of allKeys) {
|
|
2677
|
+
if (meta.expiresAt && new Date(meta.expiresAt) < now && meta.status === "active") {
|
|
2678
|
+
await this.storage.updateMeta(meta.keyId, {
|
|
2679
|
+
status: "expired"
|
|
2680
|
+
});
|
|
2681
|
+
count++;
|
|
5102
2682
|
}
|
|
2683
|
+
}
|
|
2684
|
+
return count;
|
|
2685
|
+
}
|
|
2686
|
+
/**
|
|
2687
|
+
* Cleanup: delete keys that have been revoked/expired for longer than retention period.
|
|
2688
|
+
*
|
|
2689
|
+
* @param retentionDays How many days to keep revoked/expired keys (default: 90)
|
|
2690
|
+
*/
|
|
2691
|
+
async pruneOldKeys(retentionDays = 90) {
|
|
2692
|
+
const allKeys = await this.storage.list();
|
|
2693
|
+
const cutoffDate = /* @__PURE__ */ new Date();
|
|
2694
|
+
cutoffDate.setDate(cutoffDate.getDate() - retentionDays);
|
|
2695
|
+
let count = 0;
|
|
2696
|
+
for (const meta of allKeys) {
|
|
2697
|
+
const shouldPrune = meta.status === "revoked" && meta.revokedAt && new Date(meta.revokedAt) < cutoffDate || meta.status === "expired" && meta.expiresAt && new Date(meta.expiresAt) < cutoffDate;
|
|
2698
|
+
if (shouldPrune) {
|
|
2699
|
+
await this.storage.delete(meta.keyId);
|
|
2700
|
+
count++;
|
|
2701
|
+
}
|
|
2702
|
+
}
|
|
2703
|
+
return count;
|
|
2704
|
+
}
|
|
2705
|
+
};
|
|
2706
|
+
|
|
2707
|
+
// ../crypto/dist/esm/errors.js
|
|
2708
|
+
init_esbuild_shims();
|
|
2709
|
+
|
|
2710
|
+
// ../crypto/dist/esm/stateless.js
|
|
2711
|
+
init_esbuild_shims();
|
|
2712
|
+
|
|
2713
|
+
// ../crypto/dist/esm/suites/bsv-ecdsa.js
|
|
2714
|
+
init_esbuild_shims();
|
|
2715
|
+
|
|
2716
|
+
// ../../node_modules/@noble/secp256k1/index.js
|
|
2717
|
+
init_esbuild_shims();
|
|
2718
|
+
var secp256k1_CURVE = {
|
|
2719
|
+
p: 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2fn,
|
|
2720
|
+
n: 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n,
|
|
2721
|
+
h: 1n,
|
|
2722
|
+
a: 0n,
|
|
2723
|
+
b: 7n,
|
|
2724
|
+
Gx: 0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n,
|
|
2725
|
+
Gy: 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n
|
|
2726
|
+
};
|
|
2727
|
+
var { p: P2, n: N2, Gx, Gy, b: _b } = secp256k1_CURVE;
|
|
2728
|
+
var L2 = 32;
|
|
2729
|
+
var L22 = 64;
|
|
2730
|
+
var err = (m2 = "") => {
|
|
2731
|
+
throw new Error(m2);
|
|
2732
|
+
};
|
|
2733
|
+
var isBig = (n2) => typeof n2 === "bigint";
|
|
2734
|
+
var isStr = (s2) => typeof s2 === "string";
|
|
2735
|
+
var isBytes2 = (a2) => a2 instanceof Uint8Array || ArrayBuffer.isView(a2) && a2.constructor.name === "Uint8Array";
|
|
2736
|
+
var abytes2 = (a2, l2) => !isBytes2(a2) || typeof l2 === "number" && l2 > 0 && a2.length !== l2 ? err("Uint8Array expected") : a2;
|
|
2737
|
+
var u8n = (len) => new Uint8Array(len);
|
|
2738
|
+
var u8fr = (buf) => Uint8Array.from(buf);
|
|
2739
|
+
var padh = (n2, pad) => n2.toString(16).padStart(pad, "0");
|
|
2740
|
+
var bytesToHex2 = (b2) => Array.from(abytes2(b2)).map((e2) => padh(e2, 2)).join("");
|
|
2741
|
+
var C2 = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
|
|
2742
|
+
var _ch = (ch) => {
|
|
2743
|
+
if (ch >= C2._0 && ch <= C2._9)
|
|
2744
|
+
return ch - C2._0;
|
|
2745
|
+
if (ch >= C2.A && ch <= C2.F)
|
|
2746
|
+
return ch - (C2.A - 10);
|
|
2747
|
+
if (ch >= C2.a && ch <= C2.f)
|
|
2748
|
+
return ch - (C2.a - 10);
|
|
2749
|
+
return;
|
|
2750
|
+
};
|
|
2751
|
+
var hexToBytes2 = (hex) => {
|
|
2752
|
+
const e2 = "hex invalid";
|
|
2753
|
+
if (!isStr(hex))
|
|
2754
|
+
return err(e2);
|
|
2755
|
+
const hl = hex.length;
|
|
2756
|
+
const al = hl / 2;
|
|
2757
|
+
if (hl % 2)
|
|
2758
|
+
return err(e2);
|
|
2759
|
+
const array = u8n(al);
|
|
2760
|
+
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
2761
|
+
const n1 = _ch(hex.charCodeAt(hi));
|
|
2762
|
+
const n2 = _ch(hex.charCodeAt(hi + 1));
|
|
2763
|
+
if (n1 === void 0 || n2 === void 0)
|
|
2764
|
+
return err(e2);
|
|
2765
|
+
array[ai] = n1 * 16 + n2;
|
|
2766
|
+
}
|
|
2767
|
+
return array;
|
|
2768
|
+
};
|
|
2769
|
+
var toU8 = (a2, len) => abytes2(isStr(a2) ? hexToBytes2(a2) : u8fr(abytes2(a2)), len);
|
|
2770
|
+
var cr = () => globalThis?.crypto;
|
|
2771
|
+
var subtle = () => cr()?.subtle ?? err("crypto.subtle must be defined");
|
|
2772
|
+
var concatBytes = (...arrs) => {
|
|
2773
|
+
const r2 = u8n(arrs.reduce((sum, a2) => sum + abytes2(a2).length, 0));
|
|
2774
|
+
let pad = 0;
|
|
2775
|
+
arrs.forEach((a2) => {
|
|
2776
|
+
r2.set(a2, pad);
|
|
2777
|
+
pad += a2.length;
|
|
2778
|
+
});
|
|
2779
|
+
return r2;
|
|
2780
|
+
};
|
|
2781
|
+
var randomBytes = (len = L2) => {
|
|
2782
|
+
const c2 = cr();
|
|
2783
|
+
return c2.getRandomValues(u8n(len));
|
|
2784
|
+
};
|
|
2785
|
+
var big = BigInt;
|
|
2786
|
+
var arange = (n2, min, max, msg = "bad number: out of range") => isBig(n2) && min <= n2 && n2 < max ? n2 : err(msg);
|
|
2787
|
+
var M2 = (a2, b2 = P2) => {
|
|
2788
|
+
const r2 = a2 % b2;
|
|
2789
|
+
return r2 >= 0n ? r2 : b2 + r2;
|
|
2790
|
+
};
|
|
2791
|
+
var modN = (a2) => M2(a2, N2);
|
|
2792
|
+
var invert = (num, md) => {
|
|
2793
|
+
if (num === 0n || md <= 0n)
|
|
2794
|
+
err("no inverse n=" + num + " mod=" + md);
|
|
2795
|
+
let a2 = M2(num, md), b2 = md, x2 = 0n, y2 = 1n, u2 = 1n, v2 = 0n;
|
|
2796
|
+
while (a2 !== 0n) {
|
|
2797
|
+
const q2 = b2 / a2, r2 = b2 % a2;
|
|
2798
|
+
const m2 = x2 - u2 * q2, n2 = y2 - v2 * q2;
|
|
2799
|
+
b2 = a2, a2 = r2, x2 = u2, y2 = v2, u2 = m2, v2 = n2;
|
|
2800
|
+
}
|
|
2801
|
+
return b2 === 1n ? M2(x2, md) : err("no inverse");
|
|
2802
|
+
};
|
|
2803
|
+
var callHash = (name) => {
|
|
2804
|
+
const fn = etc[name];
|
|
2805
|
+
if (typeof fn !== "function")
|
|
2806
|
+
err("hashes." + name + " not set");
|
|
2807
|
+
return fn;
|
|
2808
|
+
};
|
|
2809
|
+
var apoint = (p2) => p2 instanceof Point ? p2 : err("Point expected");
|
|
2810
|
+
var koblitz = (x2) => M2(M2(x2 * x2) * x2 + _b);
|
|
2811
|
+
var afield0 = (n2) => arange(n2, 0n, P2);
|
|
2812
|
+
var afield = (n2) => arange(n2, 1n, P2);
|
|
2813
|
+
var agroup = (n2) => arange(n2, 1n, N2);
|
|
2814
|
+
var isEven = (y2) => (y2 & 1n) === 0n;
|
|
2815
|
+
var u8of = (n2) => Uint8Array.of(n2);
|
|
2816
|
+
var getPrefix = (y2) => u8of(isEven(y2) ? 2 : 3);
|
|
2817
|
+
var lift_x = (x2) => {
|
|
2818
|
+
const c2 = koblitz(afield(x2));
|
|
2819
|
+
let r2 = 1n;
|
|
2820
|
+
for (let num = c2, e2 = (P2 + 1n) / 4n; e2 > 0n; e2 >>= 1n) {
|
|
2821
|
+
if (e2 & 1n)
|
|
2822
|
+
r2 = r2 * num % P2;
|
|
2823
|
+
num = num * num % P2;
|
|
2824
|
+
}
|
|
2825
|
+
return M2(r2 * r2) === c2 ? r2 : err("sqrt invalid");
|
|
2826
|
+
};
|
|
2827
|
+
var _Point = class _Point {
|
|
2828
|
+
constructor(px, py, pz) {
|
|
2829
|
+
__publicField(this, "px");
|
|
2830
|
+
__publicField(this, "py");
|
|
2831
|
+
__publicField(this, "pz");
|
|
2832
|
+
this.px = afield0(px);
|
|
2833
|
+
this.py = afield(py);
|
|
2834
|
+
this.pz = afield0(pz);
|
|
2835
|
+
Object.freeze(this);
|
|
2836
|
+
}
|
|
2837
|
+
/** Convert Uint8Array or hex string to Point. */
|
|
2838
|
+
static fromBytes(bytes) {
|
|
2839
|
+
abytes2(bytes);
|
|
2840
|
+
let p2 = void 0;
|
|
2841
|
+
const head = bytes[0];
|
|
2842
|
+
const tail = bytes.subarray(1);
|
|
2843
|
+
const x2 = sliceBytesNumBE(tail, 0, L2);
|
|
2844
|
+
const len = bytes.length;
|
|
2845
|
+
if (len === L2 + 1 && [2, 3].includes(head)) {
|
|
2846
|
+
let y2 = lift_x(x2);
|
|
2847
|
+
const evenY = isEven(y2);
|
|
2848
|
+
const evenH = isEven(big(head));
|
|
2849
|
+
if (evenH !== evenY)
|
|
2850
|
+
y2 = M2(-y2);
|
|
2851
|
+
p2 = new _Point(x2, y2, 1n);
|
|
2852
|
+
}
|
|
2853
|
+
if (len === L22 + 1 && head === 4)
|
|
2854
|
+
p2 = new _Point(x2, sliceBytesNumBE(tail, L2, L22), 1n);
|
|
2855
|
+
return p2 ? p2.assertValidity() : err("bad point: not on curve");
|
|
2856
|
+
}
|
|
2857
|
+
/** Equality check: compare points P&Q. */
|
|
2858
|
+
equals(other) {
|
|
2859
|
+
const { px: X1, py: Y1, pz: Z1 } = this;
|
|
2860
|
+
const { px: X2, py: Y2, pz: Z2 } = apoint(other);
|
|
2861
|
+
const X1Z2 = M2(X1 * Z2);
|
|
2862
|
+
const X2Z1 = M2(X2 * Z1);
|
|
2863
|
+
const Y1Z2 = M2(Y1 * Z2);
|
|
2864
|
+
const Y2Z1 = M2(Y2 * Z1);
|
|
2865
|
+
return X1Z2 === X2Z1 && Y1Z2 === Y2Z1;
|
|
2866
|
+
}
|
|
2867
|
+
is0() {
|
|
2868
|
+
return this.equals(I2);
|
|
2869
|
+
}
|
|
2870
|
+
/** Flip point over y coordinate. */
|
|
2871
|
+
negate() {
|
|
2872
|
+
return new _Point(this.px, M2(-this.py), this.pz);
|
|
2873
|
+
}
|
|
2874
|
+
/** Point doubling: P+P, complete formula. */
|
|
2875
|
+
double() {
|
|
2876
|
+
return this.add(this);
|
|
2877
|
+
}
|
|
2878
|
+
/**
|
|
2879
|
+
* Point addition: P+Q, complete, exception-free formula
|
|
2880
|
+
* (Renes-Costello-Batina, algo 1 of [2015/1060](https://eprint.iacr.org/2015/1060)).
|
|
2881
|
+
* Cost: `12M + 0S + 3*a + 3*b3 + 23add`.
|
|
2882
|
+
*/
|
|
2883
|
+
// prettier-ignore
|
|
2884
|
+
add(other) {
|
|
2885
|
+
const { px: X1, py: Y1, pz: Z1 } = this;
|
|
2886
|
+
const { px: X2, py: Y2, pz: Z2 } = apoint(other);
|
|
2887
|
+
const a2 = 0n;
|
|
2888
|
+
const b2 = _b;
|
|
2889
|
+
let X3 = 0n, Y3 = 0n, Z3 = 0n;
|
|
2890
|
+
const b3 = M2(b2 * 3n);
|
|
2891
|
+
let t0 = M2(X1 * X2), t1 = M2(Y1 * Y2), t2 = M2(Z1 * Z2), t3 = M2(X1 + Y1);
|
|
2892
|
+
let t4 = M2(X2 + Y2);
|
|
2893
|
+
t3 = M2(t3 * t4);
|
|
2894
|
+
t4 = M2(t0 + t1);
|
|
2895
|
+
t3 = M2(t3 - t4);
|
|
2896
|
+
t4 = M2(X1 + Z1);
|
|
2897
|
+
let t5 = M2(X2 + Z2);
|
|
2898
|
+
t4 = M2(t4 * t5);
|
|
2899
|
+
t5 = M2(t0 + t2);
|
|
2900
|
+
t4 = M2(t4 - t5);
|
|
2901
|
+
t5 = M2(Y1 + Z1);
|
|
2902
|
+
X3 = M2(Y2 + Z2);
|
|
2903
|
+
t5 = M2(t5 * X3);
|
|
2904
|
+
X3 = M2(t1 + t2);
|
|
2905
|
+
t5 = M2(t5 - X3);
|
|
2906
|
+
Z3 = M2(a2 * t4);
|
|
2907
|
+
X3 = M2(b3 * t2);
|
|
2908
|
+
Z3 = M2(X3 + Z3);
|
|
2909
|
+
X3 = M2(t1 - Z3);
|
|
2910
|
+
Z3 = M2(t1 + Z3);
|
|
2911
|
+
Y3 = M2(X3 * Z3);
|
|
2912
|
+
t1 = M2(t0 + t0);
|
|
2913
|
+
t1 = M2(t1 + t0);
|
|
2914
|
+
t2 = M2(a2 * t2);
|
|
2915
|
+
t4 = M2(b3 * t4);
|
|
2916
|
+
t1 = M2(t1 + t2);
|
|
2917
|
+
t2 = M2(t0 - t2);
|
|
2918
|
+
t2 = M2(a2 * t2);
|
|
2919
|
+
t4 = M2(t4 + t2);
|
|
2920
|
+
t0 = M2(t1 * t4);
|
|
2921
|
+
Y3 = M2(Y3 + t0);
|
|
2922
|
+
t0 = M2(t5 * t4);
|
|
2923
|
+
X3 = M2(t3 * X3);
|
|
2924
|
+
X3 = M2(X3 - t0);
|
|
2925
|
+
t0 = M2(t3 * t1);
|
|
2926
|
+
Z3 = M2(t5 * Z3);
|
|
2927
|
+
Z3 = M2(Z3 + t0);
|
|
2928
|
+
return new _Point(X3, Y3, Z3);
|
|
2929
|
+
}
|
|
2930
|
+
/**
|
|
2931
|
+
* Point-by-scalar multiplication. Scalar must be in range 1 <= n < CURVE.n.
|
|
2932
|
+
* Uses {@link wNAF} for base point.
|
|
2933
|
+
* Uses fake point to mitigate side-channel leakage.
|
|
2934
|
+
* @param n scalar by which point is multiplied
|
|
2935
|
+
* @param safe safe mode guards against timing attacks; unsafe mode is faster
|
|
2936
|
+
*/
|
|
2937
|
+
multiply(n2, safe = true) {
|
|
2938
|
+
if (!safe && n2 === 0n)
|
|
2939
|
+
return I2;
|
|
2940
|
+
agroup(n2);
|
|
2941
|
+
if (n2 === 1n)
|
|
2942
|
+
return this;
|
|
2943
|
+
if (this.equals(G2))
|
|
2944
|
+
return wNAF(n2).p;
|
|
2945
|
+
let p2 = I2;
|
|
2946
|
+
let f2 = G2;
|
|
2947
|
+
for (let d2 = this; n2 > 0n; d2 = d2.double(), n2 >>= 1n) {
|
|
2948
|
+
if (n2 & 1n)
|
|
2949
|
+
p2 = p2.add(d2);
|
|
2950
|
+
else if (safe)
|
|
2951
|
+
f2 = f2.add(d2);
|
|
2952
|
+
}
|
|
2953
|
+
return p2;
|
|
2954
|
+
}
|
|
2955
|
+
/** Convert point to 2d xy affine point. (X, Y, Z) ∋ (x=X/Z, y=Y/Z) */
|
|
2956
|
+
toAffine() {
|
|
2957
|
+
const { px: x2, py: y2, pz: z } = this;
|
|
2958
|
+
if (this.equals(I2))
|
|
2959
|
+
return { x: 0n, y: 0n };
|
|
2960
|
+
if (z === 1n)
|
|
2961
|
+
return { x: x2, y: y2 };
|
|
2962
|
+
const iz = invert(z, P2);
|
|
2963
|
+
if (M2(z * iz) !== 1n)
|
|
2964
|
+
err("inverse invalid");
|
|
2965
|
+
return { x: M2(x2 * iz), y: M2(y2 * iz) };
|
|
2966
|
+
}
|
|
2967
|
+
/** Checks if the point is valid and on-curve. */
|
|
2968
|
+
assertValidity() {
|
|
2969
|
+
const { x: x2, y: y2 } = this.toAffine();
|
|
2970
|
+
afield(x2);
|
|
2971
|
+
afield(y2);
|
|
2972
|
+
return M2(y2 * y2) === koblitz(x2) ? this : err("bad point: not on curve");
|
|
2973
|
+
}
|
|
2974
|
+
/** Converts point to 33/65-byte Uint8Array. */
|
|
2975
|
+
toBytes(isCompressed = true) {
|
|
2976
|
+
const { x: x2, y: y2 } = this.assertValidity().toAffine();
|
|
2977
|
+
const x32b = numTo32b(x2);
|
|
2978
|
+
if (isCompressed)
|
|
2979
|
+
return concatBytes(getPrefix(y2), x32b);
|
|
2980
|
+
return concatBytes(u8of(4), x32b, numTo32b(y2));
|
|
2981
|
+
}
|
|
2982
|
+
/** Create 3d xyz point from 2d xy. (0, 0) => (0, 1, 0), not (0, 0, 1) */
|
|
2983
|
+
static fromAffine(ap) {
|
|
2984
|
+
const { x: x2, y: y2 } = ap;
|
|
2985
|
+
return x2 === 0n && y2 === 0n ? I2 : new _Point(x2, y2, 1n);
|
|
2986
|
+
}
|
|
2987
|
+
toHex(isCompressed) {
|
|
2988
|
+
return bytesToHex2(this.toBytes(isCompressed));
|
|
2989
|
+
}
|
|
2990
|
+
static fromPrivateKey(k2) {
|
|
2991
|
+
return G2.multiply(toPrivScalar(k2));
|
|
2992
|
+
}
|
|
2993
|
+
static fromHex(hex) {
|
|
2994
|
+
return _Point.fromBytes(toU8(hex));
|
|
2995
|
+
}
|
|
2996
|
+
get x() {
|
|
2997
|
+
return this.toAffine().x;
|
|
2998
|
+
}
|
|
2999
|
+
get y() {
|
|
3000
|
+
return this.toAffine().y;
|
|
3001
|
+
}
|
|
3002
|
+
toRawBytes(isCompressed) {
|
|
3003
|
+
return this.toBytes(isCompressed);
|
|
3004
|
+
}
|
|
3005
|
+
};
|
|
3006
|
+
__publicField(_Point, "BASE");
|
|
3007
|
+
__publicField(_Point, "ZERO");
|
|
3008
|
+
var Point = _Point;
|
|
3009
|
+
var G2 = new Point(Gx, Gy, 1n);
|
|
3010
|
+
var I2 = new Point(0n, 1n, 0n);
|
|
3011
|
+
Point.BASE = G2;
|
|
3012
|
+
Point.ZERO = I2;
|
|
3013
|
+
var doubleScalarMulUns = (R2, u1, u2) => {
|
|
3014
|
+
return G2.multiply(u1, false).add(R2.multiply(u2, false)).assertValidity();
|
|
3015
|
+
};
|
|
3016
|
+
var bytesToNumBE = (b2) => big("0x" + (bytesToHex2(b2) || "0"));
|
|
3017
|
+
var sliceBytesNumBE = (b2, from, to) => bytesToNumBE(b2.subarray(from, to));
|
|
3018
|
+
var B256 = 2n ** 256n;
|
|
3019
|
+
var numTo32b = (num) => hexToBytes2(padh(arange(num, 0n, B256), L22));
|
|
3020
|
+
var toPrivScalar = (pr) => {
|
|
3021
|
+
const num = isBig(pr) ? pr : bytesToNumBE(toU8(pr, L2));
|
|
3022
|
+
return arange(num, 1n, N2, "private key invalid 3");
|
|
3023
|
+
};
|
|
3024
|
+
var highS = (n2) => n2 > N2 >> 1n;
|
|
3025
|
+
var getPublicKey = (privKey, isCompressed = true) => {
|
|
3026
|
+
return G2.multiply(toPrivScalar(privKey)).toBytes(isCompressed);
|
|
3027
|
+
};
|
|
3028
|
+
var Signature = class _Signature {
|
|
3029
|
+
constructor(r2, s2, recovery) {
|
|
3030
|
+
__publicField(this, "r");
|
|
3031
|
+
__publicField(this, "s");
|
|
3032
|
+
__publicField(this, "recovery");
|
|
3033
|
+
this.r = agroup(r2);
|
|
3034
|
+
this.s = agroup(s2);
|
|
3035
|
+
if (recovery != null)
|
|
3036
|
+
this.recovery = recovery;
|
|
3037
|
+
Object.freeze(this);
|
|
3038
|
+
}
|
|
3039
|
+
/** Create signature from 64b compact (r || s) representation. */
|
|
3040
|
+
static fromBytes(b2) {
|
|
3041
|
+
abytes2(b2, L22);
|
|
3042
|
+
const r2 = sliceBytesNumBE(b2, 0, L2);
|
|
3043
|
+
const s2 = sliceBytesNumBE(b2, L2, L22);
|
|
3044
|
+
return new _Signature(r2, s2);
|
|
3045
|
+
}
|
|
3046
|
+
toBytes() {
|
|
3047
|
+
const { r: r2, s: s2 } = this;
|
|
3048
|
+
return concatBytes(numTo32b(r2), numTo32b(s2));
|
|
3049
|
+
}
|
|
3050
|
+
/** Copy signature, with newly added recovery bit. */
|
|
3051
|
+
addRecoveryBit(bit) {
|
|
3052
|
+
return new _Signature(this.r, this.s, bit);
|
|
3053
|
+
}
|
|
3054
|
+
hasHighS() {
|
|
3055
|
+
return highS(this.s);
|
|
3056
|
+
}
|
|
3057
|
+
toCompactRawBytes() {
|
|
3058
|
+
return this.toBytes();
|
|
3059
|
+
}
|
|
3060
|
+
toCompactHex() {
|
|
3061
|
+
return bytesToHex2(this.toBytes());
|
|
3062
|
+
}
|
|
3063
|
+
recoverPublicKey(msg) {
|
|
3064
|
+
return recoverPublicKey(this, msg);
|
|
3065
|
+
}
|
|
3066
|
+
static fromCompact(hex) {
|
|
3067
|
+
return _Signature.fromBytes(toU8(hex, L22));
|
|
3068
|
+
}
|
|
3069
|
+
assertValidity() {
|
|
3070
|
+
return this;
|
|
3071
|
+
}
|
|
3072
|
+
normalizeS() {
|
|
3073
|
+
const { r: r2, s: s2, recovery } = this;
|
|
3074
|
+
return highS(s2) ? new _Signature(r2, modN(-s2), recovery) : this;
|
|
3075
|
+
}
|
|
3076
|
+
};
|
|
3077
|
+
var bits2int = (bytes) => {
|
|
3078
|
+
const delta = bytes.length * 8 - 256;
|
|
3079
|
+
if (delta > 1024)
|
|
3080
|
+
err("msg invalid");
|
|
3081
|
+
const num = bytesToNumBE(bytes);
|
|
3082
|
+
return delta > 0 ? num >> big(delta) : num;
|
|
3083
|
+
};
|
|
3084
|
+
var bits2int_modN = (bytes) => modN(bits2int(abytes2(bytes)));
|
|
3085
|
+
var signOpts = { lowS: true };
|
|
3086
|
+
var veriOpts = { lowS: true };
|
|
3087
|
+
var prepSig = (msgh, priv, opts = signOpts) => {
|
|
3088
|
+
if (["der", "recovered", "canonical"].some((k2) => k2 in opts))
|
|
3089
|
+
err("option not supported");
|
|
3090
|
+
let { lowS, extraEntropy } = opts;
|
|
3091
|
+
if (lowS == null)
|
|
3092
|
+
lowS = true;
|
|
3093
|
+
const i2o = numTo32b;
|
|
3094
|
+
const h1i = bits2int_modN(toU8(msgh));
|
|
3095
|
+
const h1o = i2o(h1i);
|
|
3096
|
+
const d2 = toPrivScalar(priv);
|
|
3097
|
+
const seed = [i2o(d2), h1o];
|
|
3098
|
+
if (extraEntropy)
|
|
3099
|
+
seed.push(extraEntropy === true ? randomBytes(L2) : toU8(extraEntropy));
|
|
3100
|
+
const m2 = h1i;
|
|
3101
|
+
const k2sig = (kBytes) => {
|
|
3102
|
+
const k2 = bits2int(kBytes);
|
|
3103
|
+
if (!(1n <= k2 && k2 < N2))
|
|
3104
|
+
return;
|
|
3105
|
+
const q2 = G2.multiply(k2).toAffine();
|
|
3106
|
+
const r2 = modN(q2.x);
|
|
3107
|
+
if (r2 === 0n)
|
|
3108
|
+
return;
|
|
3109
|
+
const ik = invert(k2, N2);
|
|
3110
|
+
const s2 = modN(ik * modN(m2 + modN(d2 * r2)));
|
|
3111
|
+
if (s2 === 0n)
|
|
3112
|
+
return;
|
|
3113
|
+
let normS = s2;
|
|
3114
|
+
let recovery = (q2.x === r2 ? 0 : 2) | Number(q2.y & 1n);
|
|
3115
|
+
if (lowS && highS(s2)) {
|
|
3116
|
+
normS = modN(-s2);
|
|
3117
|
+
recovery ^= 1;
|
|
3118
|
+
}
|
|
3119
|
+
return new Signature(r2, normS, recovery);
|
|
3120
|
+
};
|
|
3121
|
+
return { seed: concatBytes(...seed), k2sig };
|
|
3122
|
+
};
|
|
3123
|
+
var hmacDrbg = (asynchronous) => {
|
|
3124
|
+
let v2 = u8n(L2);
|
|
3125
|
+
let k2 = u8n(L2);
|
|
3126
|
+
let i2 = 0;
|
|
3127
|
+
const NULL = u8n(0);
|
|
3128
|
+
const reset = () => {
|
|
3129
|
+
v2.fill(1);
|
|
3130
|
+
k2.fill(0);
|
|
3131
|
+
i2 = 0;
|
|
3132
|
+
};
|
|
3133
|
+
const max = 1e3;
|
|
3134
|
+
const _e = "drbg: tried 1000 values";
|
|
3135
|
+
if (asynchronous) {
|
|
3136
|
+
const h2 = (...b2) => etc.hmacSha256Async(k2, v2, ...b2);
|
|
3137
|
+
const reseed = async (seed = NULL) => {
|
|
3138
|
+
k2 = await h2(u8of(0), seed);
|
|
3139
|
+
v2 = await h2();
|
|
3140
|
+
if (seed.length === 0)
|
|
3141
|
+
return;
|
|
3142
|
+
k2 = await h2(u8of(1), seed);
|
|
3143
|
+
v2 = await h2();
|
|
3144
|
+
};
|
|
3145
|
+
const gen = async () => {
|
|
3146
|
+
if (i2++ >= max)
|
|
3147
|
+
err(_e);
|
|
3148
|
+
v2 = await h2();
|
|
3149
|
+
return v2;
|
|
3150
|
+
};
|
|
3151
|
+
return async (seed, pred) => {
|
|
3152
|
+
reset();
|
|
3153
|
+
await reseed(seed);
|
|
3154
|
+
let res = void 0;
|
|
3155
|
+
while (!(res = pred(await gen())))
|
|
3156
|
+
await reseed();
|
|
3157
|
+
reset();
|
|
3158
|
+
return res;
|
|
3159
|
+
};
|
|
3160
|
+
} else {
|
|
3161
|
+
const h2 = (...b2) => callHash("hmacSha256Sync")(k2, v2, ...b2);
|
|
3162
|
+
const reseed = (seed = NULL) => {
|
|
3163
|
+
k2 = h2(u8of(0), seed);
|
|
3164
|
+
v2 = h2();
|
|
3165
|
+
if (seed.length === 0)
|
|
3166
|
+
return;
|
|
3167
|
+
k2 = h2(u8of(1), seed);
|
|
3168
|
+
v2 = h2();
|
|
3169
|
+
};
|
|
3170
|
+
const gen = () => {
|
|
3171
|
+
if (i2++ >= max)
|
|
3172
|
+
err(_e);
|
|
3173
|
+
v2 = h2();
|
|
3174
|
+
return v2;
|
|
3175
|
+
};
|
|
3176
|
+
return (seed, pred) => {
|
|
3177
|
+
reset();
|
|
3178
|
+
reseed(seed);
|
|
3179
|
+
let res = void 0;
|
|
3180
|
+
while (!(res = pred(gen())))
|
|
3181
|
+
reseed();
|
|
3182
|
+
reset();
|
|
3183
|
+
return res;
|
|
5103
3184
|
};
|
|
5104
|
-
exports2.MlDsaSuite = MlDsaSuite2;
|
|
5105
3185
|
}
|
|
5106
|
-
}
|
|
3186
|
+
};
|
|
3187
|
+
var sign = (msgh, priv, opts = signOpts) => {
|
|
3188
|
+
const { seed, k2sig } = prepSig(msgh, priv, opts);
|
|
3189
|
+
const sig = hmacDrbg(false)(seed, k2sig);
|
|
3190
|
+
return sig;
|
|
3191
|
+
};
|
|
3192
|
+
var verify = (sig, msgh, pub, opts = veriOpts) => {
|
|
3193
|
+
let { lowS } = opts;
|
|
3194
|
+
if (lowS == null)
|
|
3195
|
+
lowS = true;
|
|
3196
|
+
if ("strict" in opts)
|
|
3197
|
+
err("option not supported");
|
|
3198
|
+
let sigg;
|
|
3199
|
+
const rs = sig && typeof sig === "object" && "r" in sig;
|
|
3200
|
+
if (!rs && toU8(sig).length !== L22)
|
|
3201
|
+
err("signature must be 64 bytes");
|
|
3202
|
+
try {
|
|
3203
|
+
sigg = rs ? new Signature(sig.r, sig.s) : Signature.fromCompact(sig);
|
|
3204
|
+
const h2 = bits2int_modN(toU8(msgh));
|
|
3205
|
+
const P3 = Point.fromBytes(toU8(pub));
|
|
3206
|
+
const { r: r2, s: s2 } = sigg;
|
|
3207
|
+
if (lowS && highS(s2))
|
|
3208
|
+
return false;
|
|
3209
|
+
const is = invert(s2, N2);
|
|
3210
|
+
const u1 = modN(h2 * is);
|
|
3211
|
+
const u2 = modN(r2 * is);
|
|
3212
|
+
const R2 = doubleScalarMulUns(P3, u1, u2).toAffine();
|
|
3213
|
+
const v2 = modN(R2.x);
|
|
3214
|
+
return v2 === r2;
|
|
3215
|
+
} catch (error) {
|
|
3216
|
+
return false;
|
|
3217
|
+
}
|
|
3218
|
+
};
|
|
3219
|
+
var recoverPublicKey = (sig, msgh) => {
|
|
3220
|
+
const { r: r2, s: s2, recovery } = sig;
|
|
3221
|
+
if (![0, 1, 2, 3].includes(recovery))
|
|
3222
|
+
err("recovery id invalid");
|
|
3223
|
+
const h2 = bits2int_modN(toU8(msgh, L2));
|
|
3224
|
+
const radj = recovery === 2 || recovery === 3 ? r2 + N2 : r2;
|
|
3225
|
+
afield(radj);
|
|
3226
|
+
const head = getPrefix(big(recovery));
|
|
3227
|
+
const Rb = concatBytes(head, numTo32b(radj));
|
|
3228
|
+
const R2 = Point.fromBytes(Rb);
|
|
3229
|
+
const ir = invert(radj, N2);
|
|
3230
|
+
const u1 = modN(-h2 * ir);
|
|
3231
|
+
const u2 = modN(s2 * ir);
|
|
3232
|
+
return doubleScalarMulUns(R2, u1, u2);
|
|
3233
|
+
};
|
|
3234
|
+
var hashToPrivateKey = (hash) => {
|
|
3235
|
+
hash = toU8(hash);
|
|
3236
|
+
if (hash.length < L2 + 8 || hash.length > 1024)
|
|
3237
|
+
err("expected 40-1024b");
|
|
3238
|
+
const num = M2(bytesToNumBE(hash), N2 - 1n);
|
|
3239
|
+
return numTo32b(num + 1n);
|
|
3240
|
+
};
|
|
3241
|
+
var randomPrivateKey = () => hashToPrivateKey(randomBytes(L2 + 16));
|
|
3242
|
+
var _sha = "SHA-256";
|
|
3243
|
+
var etc = {
|
|
3244
|
+
hexToBytes: hexToBytes2,
|
|
3245
|
+
bytesToHex: bytesToHex2,
|
|
3246
|
+
concatBytes,
|
|
3247
|
+
bytesToNumberBE: bytesToNumBE,
|
|
3248
|
+
numberToBytesBE: numTo32b,
|
|
3249
|
+
mod: M2,
|
|
3250
|
+
invert,
|
|
3251
|
+
// math utilities
|
|
3252
|
+
hmacSha256Async: async (key, ...msgs) => {
|
|
3253
|
+
const s2 = subtle();
|
|
3254
|
+
const name = "HMAC";
|
|
3255
|
+
const k2 = await s2.importKey("raw", key, { name, hash: { name: _sha } }, false, ["sign"]);
|
|
3256
|
+
return u8n(await s2.sign(name, k2, concatBytes(...msgs)));
|
|
3257
|
+
},
|
|
3258
|
+
hmacSha256Sync: void 0,
|
|
3259
|
+
// For TypeScript. Actual logic is below
|
|
3260
|
+
hashToPrivateKey,
|
|
3261
|
+
randomBytes
|
|
3262
|
+
};
|
|
3263
|
+
var utils = {
|
|
3264
|
+
normPrivateKeyToScalar: toPrivScalar,
|
|
3265
|
+
isValidPrivateKey: (key) => {
|
|
3266
|
+
try {
|
|
3267
|
+
return !!toPrivScalar(key);
|
|
3268
|
+
} catch (e2) {
|
|
3269
|
+
return false;
|
|
3270
|
+
}
|
|
3271
|
+
},
|
|
3272
|
+
randomPrivateKey,
|
|
3273
|
+
precompute: (w2 = 8, p2 = G2) => {
|
|
3274
|
+
p2.multiply(3n);
|
|
3275
|
+
w2;
|
|
3276
|
+
return p2;
|
|
3277
|
+
}
|
|
3278
|
+
};
|
|
3279
|
+
var W2 = 8;
|
|
3280
|
+
var scalarBits = 256;
|
|
3281
|
+
var pwindows = Math.ceil(scalarBits / W2) + 1;
|
|
3282
|
+
var pwindowSize = 2 ** (W2 - 1);
|
|
3283
|
+
var precompute = () => {
|
|
3284
|
+
const points = [];
|
|
3285
|
+
let p2 = G2;
|
|
3286
|
+
let b2 = p2;
|
|
3287
|
+
for (let w2 = 0; w2 < pwindows; w2++) {
|
|
3288
|
+
b2 = p2;
|
|
3289
|
+
points.push(b2);
|
|
3290
|
+
for (let i2 = 1; i2 < pwindowSize; i2++) {
|
|
3291
|
+
b2 = b2.add(p2);
|
|
3292
|
+
points.push(b2);
|
|
3293
|
+
}
|
|
3294
|
+
p2 = b2.double();
|
|
3295
|
+
}
|
|
3296
|
+
return points;
|
|
3297
|
+
};
|
|
3298
|
+
var Gpows = void 0;
|
|
3299
|
+
var ctneg = (cnd, p2) => {
|
|
3300
|
+
const n2 = p2.negate();
|
|
3301
|
+
return cnd ? n2 : p2;
|
|
3302
|
+
};
|
|
3303
|
+
var wNAF = (n2) => {
|
|
3304
|
+
const comp = Gpows || (Gpows = precompute());
|
|
3305
|
+
let p2 = I2;
|
|
3306
|
+
let f2 = G2;
|
|
3307
|
+
const pow_2_w = 2 ** W2;
|
|
3308
|
+
const maxNum = pow_2_w;
|
|
3309
|
+
const mask = big(pow_2_w - 1);
|
|
3310
|
+
const shiftBy = big(W2);
|
|
3311
|
+
for (let w2 = 0; w2 < pwindows; w2++) {
|
|
3312
|
+
let wbits = Number(n2 & mask);
|
|
3313
|
+
n2 >>= shiftBy;
|
|
3314
|
+
if (wbits > pwindowSize) {
|
|
3315
|
+
wbits -= maxNum;
|
|
3316
|
+
n2 += 1n;
|
|
3317
|
+
}
|
|
3318
|
+
const off = w2 * pwindowSize;
|
|
3319
|
+
const offF = off;
|
|
3320
|
+
const offP = off + Math.abs(wbits) - 1;
|
|
3321
|
+
const isEven2 = w2 % 2 !== 0;
|
|
3322
|
+
const isNeg = wbits < 0;
|
|
3323
|
+
if (wbits === 0) {
|
|
3324
|
+
f2 = f2.add(ctneg(isEven2, comp[offF]));
|
|
3325
|
+
} else {
|
|
3326
|
+
p2 = p2.add(ctneg(isNeg, comp[offP]));
|
|
3327
|
+
}
|
|
3328
|
+
}
|
|
3329
|
+
return { p: p2, f: f2 };
|
|
3330
|
+
};
|
|
5107
3331
|
|
|
5108
|
-
//
|
|
5109
|
-
|
|
5110
|
-
|
|
5111
|
-
|
|
5112
|
-
|
|
5113
|
-
|
|
5114
|
-
|
|
5115
|
-
|
|
5116
|
-
|
|
5117
|
-
|
|
5118
|
-
|
|
5119
|
-
|
|
3332
|
+
// ../../node_modules/@noble/hashes/esm/hmac.js
|
|
3333
|
+
init_esbuild_shims();
|
|
3334
|
+
|
|
3335
|
+
// ../../node_modules/@noble/hashes/esm/utils.js
|
|
3336
|
+
init_esbuild_shims();
|
|
3337
|
+
function isBytes3(a2) {
|
|
3338
|
+
return a2 instanceof Uint8Array || ArrayBuffer.isView(a2) && a2.constructor.name === "Uint8Array";
|
|
3339
|
+
}
|
|
3340
|
+
function anumber2(n2) {
|
|
3341
|
+
if (!Number.isSafeInteger(n2) || n2 < 0)
|
|
3342
|
+
throw new Error("positive integer expected, got " + n2);
|
|
3343
|
+
}
|
|
3344
|
+
function abytes3(b2, ...lengths) {
|
|
3345
|
+
if (!isBytes3(b2))
|
|
3346
|
+
throw new Error("Uint8Array expected");
|
|
3347
|
+
if (lengths.length > 0 && !lengths.includes(b2.length))
|
|
3348
|
+
throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b2.length);
|
|
3349
|
+
}
|
|
3350
|
+
function ahash(h2) {
|
|
3351
|
+
if (typeof h2 !== "function" || typeof h2.create !== "function")
|
|
3352
|
+
throw new Error("Hash should be wrapped by utils.createHasher");
|
|
3353
|
+
anumber2(h2.outputLen);
|
|
3354
|
+
anumber2(h2.blockLen);
|
|
3355
|
+
}
|
|
3356
|
+
function aexists2(instance, checkFinished = true) {
|
|
3357
|
+
if (instance.destroyed)
|
|
3358
|
+
throw new Error("Hash instance has been destroyed");
|
|
3359
|
+
if (checkFinished && instance.finished)
|
|
3360
|
+
throw new Error("Hash#digest() has already been called");
|
|
3361
|
+
}
|
|
3362
|
+
function aoutput2(out, instance) {
|
|
3363
|
+
abytes3(out);
|
|
3364
|
+
const min = instance.outputLen;
|
|
3365
|
+
if (out.length < min) {
|
|
3366
|
+
throw new Error("digestInto() expects output buffer of length at least " + min);
|
|
3367
|
+
}
|
|
3368
|
+
}
|
|
3369
|
+
function clean2(...arrays) {
|
|
3370
|
+
for (let i2 = 0; i2 < arrays.length; i2++) {
|
|
3371
|
+
arrays[i2].fill(0);
|
|
3372
|
+
}
|
|
3373
|
+
}
|
|
3374
|
+
function createView2(arr) {
|
|
3375
|
+
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
3376
|
+
}
|
|
3377
|
+
function rotr2(word, shift) {
|
|
3378
|
+
return word << 32 - shift | word >>> shift;
|
|
3379
|
+
}
|
|
3380
|
+
function utf8ToBytes(str) {
|
|
3381
|
+
if (typeof str !== "string")
|
|
3382
|
+
throw new Error("string expected");
|
|
3383
|
+
return new Uint8Array(new TextEncoder().encode(str));
|
|
3384
|
+
}
|
|
3385
|
+
function toBytes(data) {
|
|
3386
|
+
if (typeof data === "string")
|
|
3387
|
+
data = utf8ToBytes(data);
|
|
3388
|
+
abytes3(data);
|
|
3389
|
+
return data;
|
|
3390
|
+
}
|
|
3391
|
+
var Hash = class {
|
|
3392
|
+
};
|
|
3393
|
+
function createHasher2(hashCons) {
|
|
3394
|
+
const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
|
|
3395
|
+
const tmp = hashCons();
|
|
3396
|
+
hashC.outputLen = tmp.outputLen;
|
|
3397
|
+
hashC.blockLen = tmp.blockLen;
|
|
3398
|
+
hashC.create = () => hashCons();
|
|
3399
|
+
return hashC;
|
|
3400
|
+
}
|
|
3401
|
+
|
|
3402
|
+
// ../../node_modules/@noble/hashes/esm/hmac.js
|
|
3403
|
+
var HMAC = class extends Hash {
|
|
3404
|
+
constructor(hash, _key) {
|
|
3405
|
+
super();
|
|
3406
|
+
this.finished = false;
|
|
3407
|
+
this.destroyed = false;
|
|
3408
|
+
ahash(hash);
|
|
3409
|
+
const key = toBytes(_key);
|
|
3410
|
+
this.iHash = hash.create();
|
|
3411
|
+
if (typeof this.iHash.update !== "function")
|
|
3412
|
+
throw new Error("Expected instance of class which extends utils.Hash");
|
|
3413
|
+
this.blockLen = this.iHash.blockLen;
|
|
3414
|
+
this.outputLen = this.iHash.outputLen;
|
|
3415
|
+
const blockLen = this.blockLen;
|
|
3416
|
+
const pad = new Uint8Array(blockLen);
|
|
3417
|
+
pad.set(key.length > blockLen ? hash.create().update(key).digest() : key);
|
|
3418
|
+
for (let i2 = 0; i2 < pad.length; i2++)
|
|
3419
|
+
pad[i2] ^= 54;
|
|
3420
|
+
this.iHash.update(pad);
|
|
3421
|
+
this.oHash = hash.create();
|
|
3422
|
+
for (let i2 = 0; i2 < pad.length; i2++)
|
|
3423
|
+
pad[i2] ^= 54 ^ 92;
|
|
3424
|
+
this.oHash.update(pad);
|
|
3425
|
+
clean2(pad);
|
|
3426
|
+
}
|
|
3427
|
+
update(buf) {
|
|
3428
|
+
aexists2(this);
|
|
3429
|
+
this.iHash.update(buf);
|
|
3430
|
+
return this;
|
|
3431
|
+
}
|
|
3432
|
+
digestInto(out) {
|
|
3433
|
+
aexists2(this);
|
|
3434
|
+
abytes3(out, this.outputLen);
|
|
3435
|
+
this.finished = true;
|
|
3436
|
+
this.iHash.digestInto(out);
|
|
3437
|
+
this.oHash.update(out);
|
|
3438
|
+
this.oHash.digestInto(out);
|
|
3439
|
+
this.destroy();
|
|
3440
|
+
}
|
|
3441
|
+
digest() {
|
|
3442
|
+
const out = new Uint8Array(this.oHash.outputLen);
|
|
3443
|
+
this.digestInto(out);
|
|
3444
|
+
return out;
|
|
3445
|
+
}
|
|
3446
|
+
_cloneInto(to) {
|
|
3447
|
+
to || (to = Object.create(Object.getPrototypeOf(this), {}));
|
|
3448
|
+
const { oHash, iHash, finished, destroyed, blockLen, outputLen } = this;
|
|
3449
|
+
to = to;
|
|
3450
|
+
to.finished = finished;
|
|
3451
|
+
to.destroyed = destroyed;
|
|
3452
|
+
to.blockLen = blockLen;
|
|
3453
|
+
to.outputLen = outputLen;
|
|
3454
|
+
to.oHash = oHash._cloneInto(to.oHash);
|
|
3455
|
+
to.iHash = iHash._cloneInto(to.iHash);
|
|
3456
|
+
return to;
|
|
3457
|
+
}
|
|
3458
|
+
clone() {
|
|
3459
|
+
return this._cloneInto();
|
|
3460
|
+
}
|
|
3461
|
+
destroy() {
|
|
3462
|
+
this.destroyed = true;
|
|
3463
|
+
this.oHash.destroy();
|
|
3464
|
+
this.iHash.destroy();
|
|
3465
|
+
}
|
|
3466
|
+
};
|
|
3467
|
+
var hmac = (hash, key, message) => new HMAC(hash, key).update(message).digest();
|
|
3468
|
+
hmac.create = (hash, key) => new HMAC(hash, key);
|
|
3469
|
+
|
|
3470
|
+
// ../../node_modules/@noble/hashes/esm/sha256.js
|
|
3471
|
+
init_esbuild_shims();
|
|
3472
|
+
|
|
3473
|
+
// ../../node_modules/@noble/hashes/esm/sha2.js
|
|
3474
|
+
init_esbuild_shims();
|
|
3475
|
+
|
|
3476
|
+
// ../../node_modules/@noble/hashes/esm/_md.js
|
|
3477
|
+
init_esbuild_shims();
|
|
3478
|
+
function setBigUint64(view, byteOffset, value, isLE2) {
|
|
3479
|
+
if (typeof view.setBigUint64 === "function")
|
|
3480
|
+
return view.setBigUint64(byteOffset, value, isLE2);
|
|
3481
|
+
const _32n2 = BigInt(32);
|
|
3482
|
+
const _u32_max = BigInt(4294967295);
|
|
3483
|
+
const wh = Number(value >> _32n2 & _u32_max);
|
|
3484
|
+
const wl = Number(value & _u32_max);
|
|
3485
|
+
const h2 = isLE2 ? 4 : 0;
|
|
3486
|
+
const l2 = isLE2 ? 0 : 4;
|
|
3487
|
+
view.setUint32(byteOffset + h2, wh, isLE2);
|
|
3488
|
+
view.setUint32(byteOffset + l2, wl, isLE2);
|
|
3489
|
+
}
|
|
3490
|
+
function Chi2(a2, b2, c2) {
|
|
3491
|
+
return a2 & b2 ^ ~a2 & c2;
|
|
3492
|
+
}
|
|
3493
|
+
function Maj2(a2, b2, c2) {
|
|
3494
|
+
return a2 & b2 ^ a2 & c2 ^ b2 & c2;
|
|
3495
|
+
}
|
|
3496
|
+
var HashMD2 = class extends Hash {
|
|
3497
|
+
constructor(blockLen, outputLen, padOffset, isLE2) {
|
|
3498
|
+
super();
|
|
3499
|
+
this.finished = false;
|
|
3500
|
+
this.length = 0;
|
|
3501
|
+
this.pos = 0;
|
|
3502
|
+
this.destroyed = false;
|
|
3503
|
+
this.blockLen = blockLen;
|
|
3504
|
+
this.outputLen = outputLen;
|
|
3505
|
+
this.padOffset = padOffset;
|
|
3506
|
+
this.isLE = isLE2;
|
|
3507
|
+
this.buffer = new Uint8Array(blockLen);
|
|
3508
|
+
this.view = createView2(this.buffer);
|
|
3509
|
+
}
|
|
3510
|
+
update(data) {
|
|
3511
|
+
aexists2(this);
|
|
3512
|
+
data = toBytes(data);
|
|
3513
|
+
abytes3(data);
|
|
3514
|
+
const { view, buffer, blockLen } = this;
|
|
3515
|
+
const len = data.length;
|
|
3516
|
+
for (let pos = 0; pos < len; ) {
|
|
3517
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
3518
|
+
if (take === blockLen) {
|
|
3519
|
+
const dataView = createView2(data);
|
|
3520
|
+
for (; blockLen <= len - pos; pos += blockLen)
|
|
3521
|
+
this.process(dataView, pos);
|
|
3522
|
+
continue;
|
|
3523
|
+
}
|
|
3524
|
+
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
3525
|
+
this.pos += take;
|
|
3526
|
+
pos += take;
|
|
3527
|
+
if (this.pos === blockLen) {
|
|
3528
|
+
this.process(view, 0);
|
|
3529
|
+
this.pos = 0;
|
|
5120
3530
|
}
|
|
5121
|
-
|
|
5122
|
-
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
|
|
5126
|
-
|
|
5127
|
-
|
|
3531
|
+
}
|
|
3532
|
+
this.length += data.length;
|
|
3533
|
+
this.roundClean();
|
|
3534
|
+
return this;
|
|
3535
|
+
}
|
|
3536
|
+
digestInto(out) {
|
|
3537
|
+
aexists2(this);
|
|
3538
|
+
aoutput2(out, this);
|
|
3539
|
+
this.finished = true;
|
|
3540
|
+
const { buffer, view, blockLen, isLE: isLE2 } = this;
|
|
3541
|
+
let { pos } = this;
|
|
3542
|
+
buffer[pos++] = 128;
|
|
3543
|
+
clean2(this.buffer.subarray(pos));
|
|
3544
|
+
if (this.padOffset > blockLen - pos) {
|
|
3545
|
+
this.process(view, 0);
|
|
3546
|
+
pos = 0;
|
|
3547
|
+
}
|
|
3548
|
+
for (let i2 = pos; i2 < blockLen; i2++)
|
|
3549
|
+
buffer[i2] = 0;
|
|
3550
|
+
setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE2);
|
|
3551
|
+
this.process(view, 0);
|
|
3552
|
+
const oview = createView2(out);
|
|
3553
|
+
const len = this.outputLen;
|
|
3554
|
+
if (len % 4)
|
|
3555
|
+
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
3556
|
+
const outLen = len / 4;
|
|
3557
|
+
const state = this.get();
|
|
3558
|
+
if (outLen > state.length)
|
|
3559
|
+
throw new Error("_sha2: outputLen bigger than state");
|
|
3560
|
+
for (let i2 = 0; i2 < outLen; i2++)
|
|
3561
|
+
oview.setUint32(4 * i2, state[i2], isLE2);
|
|
3562
|
+
}
|
|
3563
|
+
digest() {
|
|
3564
|
+
const { buffer, outputLen } = this;
|
|
3565
|
+
this.digestInto(buffer);
|
|
3566
|
+
const res = buffer.slice(0, outputLen);
|
|
3567
|
+
this.destroy();
|
|
3568
|
+
return res;
|
|
3569
|
+
}
|
|
3570
|
+
_cloneInto(to) {
|
|
3571
|
+
to || (to = new this.constructor());
|
|
3572
|
+
to.set(...this.get());
|
|
3573
|
+
const { blockLen, buffer, length, finished, destroyed, pos } = this;
|
|
3574
|
+
to.destroyed = destroyed;
|
|
3575
|
+
to.finished = finished;
|
|
3576
|
+
to.length = length;
|
|
3577
|
+
to.pos = pos;
|
|
3578
|
+
if (length % blockLen)
|
|
3579
|
+
to.buffer.set(buffer);
|
|
3580
|
+
return to;
|
|
3581
|
+
}
|
|
3582
|
+
clone() {
|
|
3583
|
+
return this._cloneInto();
|
|
3584
|
+
}
|
|
3585
|
+
};
|
|
3586
|
+
var SHA256_IV2 = /* @__PURE__ */ Uint32Array.from([
|
|
3587
|
+
1779033703,
|
|
3588
|
+
3144134277,
|
|
3589
|
+
1013904242,
|
|
3590
|
+
2773480762,
|
|
3591
|
+
1359893119,
|
|
3592
|
+
2600822924,
|
|
3593
|
+
528734635,
|
|
3594
|
+
1541459225
|
|
3595
|
+
]);
|
|
3596
|
+
|
|
3597
|
+
// ../../node_modules/@noble/hashes/esm/sha2.js
|
|
3598
|
+
var SHA256_K2 = /* @__PURE__ */ Uint32Array.from([
|
|
3599
|
+
1116352408,
|
|
3600
|
+
1899447441,
|
|
3601
|
+
3049323471,
|
|
3602
|
+
3921009573,
|
|
3603
|
+
961987163,
|
|
3604
|
+
1508970993,
|
|
3605
|
+
2453635748,
|
|
3606
|
+
2870763221,
|
|
3607
|
+
3624381080,
|
|
3608
|
+
310598401,
|
|
3609
|
+
607225278,
|
|
3610
|
+
1426881987,
|
|
3611
|
+
1925078388,
|
|
3612
|
+
2162078206,
|
|
3613
|
+
2614888103,
|
|
3614
|
+
3248222580,
|
|
3615
|
+
3835390401,
|
|
3616
|
+
4022224774,
|
|
3617
|
+
264347078,
|
|
3618
|
+
604807628,
|
|
3619
|
+
770255983,
|
|
3620
|
+
1249150122,
|
|
3621
|
+
1555081692,
|
|
3622
|
+
1996064986,
|
|
3623
|
+
2554220882,
|
|
3624
|
+
2821834349,
|
|
3625
|
+
2952996808,
|
|
3626
|
+
3210313671,
|
|
3627
|
+
3336571891,
|
|
3628
|
+
3584528711,
|
|
3629
|
+
113926993,
|
|
3630
|
+
338241895,
|
|
3631
|
+
666307205,
|
|
3632
|
+
773529912,
|
|
3633
|
+
1294757372,
|
|
3634
|
+
1396182291,
|
|
3635
|
+
1695183700,
|
|
3636
|
+
1986661051,
|
|
3637
|
+
2177026350,
|
|
3638
|
+
2456956037,
|
|
3639
|
+
2730485921,
|
|
3640
|
+
2820302411,
|
|
3641
|
+
3259730800,
|
|
3642
|
+
3345764771,
|
|
3643
|
+
3516065817,
|
|
3644
|
+
3600352804,
|
|
3645
|
+
4094571909,
|
|
3646
|
+
275423344,
|
|
3647
|
+
430227734,
|
|
3648
|
+
506948616,
|
|
3649
|
+
659060556,
|
|
3650
|
+
883997877,
|
|
3651
|
+
958139571,
|
|
3652
|
+
1322822218,
|
|
3653
|
+
1537002063,
|
|
3654
|
+
1747873779,
|
|
3655
|
+
1955562222,
|
|
3656
|
+
2024104815,
|
|
3657
|
+
2227730452,
|
|
3658
|
+
2361852424,
|
|
3659
|
+
2428436474,
|
|
3660
|
+
2756734187,
|
|
3661
|
+
3204031479,
|
|
3662
|
+
3329325298
|
|
3663
|
+
]);
|
|
3664
|
+
var SHA256_W2 = /* @__PURE__ */ new Uint32Array(64);
|
|
3665
|
+
var SHA256 = class extends HashMD2 {
|
|
3666
|
+
constructor(outputLen = 32) {
|
|
3667
|
+
super(64, outputLen, 8, false);
|
|
3668
|
+
this.A = SHA256_IV2[0] | 0;
|
|
3669
|
+
this.B = SHA256_IV2[1] | 0;
|
|
3670
|
+
this.C = SHA256_IV2[2] | 0;
|
|
3671
|
+
this.D = SHA256_IV2[3] | 0;
|
|
3672
|
+
this.E = SHA256_IV2[4] | 0;
|
|
3673
|
+
this.F = SHA256_IV2[5] | 0;
|
|
3674
|
+
this.G = SHA256_IV2[6] | 0;
|
|
3675
|
+
this.H = SHA256_IV2[7] | 0;
|
|
3676
|
+
}
|
|
3677
|
+
get() {
|
|
3678
|
+
const { A: A2, B: B2, C: C3, D: D2, E: E2, F: F2, G: G3, H: H2 } = this;
|
|
3679
|
+
return [A2, B2, C3, D2, E2, F2, G3, H2];
|
|
3680
|
+
}
|
|
3681
|
+
// prettier-ignore
|
|
3682
|
+
set(A2, B2, C3, D2, E2, F2, G3, H2) {
|
|
3683
|
+
this.A = A2 | 0;
|
|
3684
|
+
this.B = B2 | 0;
|
|
3685
|
+
this.C = C3 | 0;
|
|
3686
|
+
this.D = D2 | 0;
|
|
3687
|
+
this.E = E2 | 0;
|
|
3688
|
+
this.F = F2 | 0;
|
|
3689
|
+
this.G = G3 | 0;
|
|
3690
|
+
this.H = H2 | 0;
|
|
3691
|
+
}
|
|
3692
|
+
process(view, offset) {
|
|
3693
|
+
for (let i2 = 0; i2 < 16; i2++, offset += 4)
|
|
3694
|
+
SHA256_W2[i2] = view.getUint32(offset, false);
|
|
3695
|
+
for (let i2 = 16; i2 < 64; i2++) {
|
|
3696
|
+
const W15 = SHA256_W2[i2 - 15];
|
|
3697
|
+
const W22 = SHA256_W2[i2 - 2];
|
|
3698
|
+
const s0 = rotr2(W15, 7) ^ rotr2(W15, 18) ^ W15 >>> 3;
|
|
3699
|
+
const s1 = rotr2(W22, 17) ^ rotr2(W22, 19) ^ W22 >>> 10;
|
|
3700
|
+
SHA256_W2[i2] = s1 + SHA256_W2[i2 - 7] + s0 + SHA256_W2[i2 - 16] | 0;
|
|
3701
|
+
}
|
|
3702
|
+
let { A: A2, B: B2, C: C3, D: D2, E: E2, F: F2, G: G3, H: H2 } = this;
|
|
3703
|
+
for (let i2 = 0; i2 < 64; i2++) {
|
|
3704
|
+
const sigma1 = rotr2(E2, 6) ^ rotr2(E2, 11) ^ rotr2(E2, 25);
|
|
3705
|
+
const T1 = H2 + sigma1 + Chi2(E2, F2, G3) + SHA256_K2[i2] + SHA256_W2[i2] | 0;
|
|
3706
|
+
const sigma0 = rotr2(A2, 2) ^ rotr2(A2, 13) ^ rotr2(A2, 22);
|
|
3707
|
+
const T2 = sigma0 + Maj2(A2, B2, C3) | 0;
|
|
3708
|
+
H2 = G3;
|
|
3709
|
+
G3 = F2;
|
|
3710
|
+
F2 = E2;
|
|
3711
|
+
E2 = D2 + T1 | 0;
|
|
3712
|
+
D2 = C3;
|
|
3713
|
+
C3 = B2;
|
|
3714
|
+
B2 = A2;
|
|
3715
|
+
A2 = T1 + T2 | 0;
|
|
3716
|
+
}
|
|
3717
|
+
A2 = A2 + this.A | 0;
|
|
3718
|
+
B2 = B2 + this.B | 0;
|
|
3719
|
+
C3 = C3 + this.C | 0;
|
|
3720
|
+
D2 = D2 + this.D | 0;
|
|
3721
|
+
E2 = E2 + this.E | 0;
|
|
3722
|
+
F2 = F2 + this.F | 0;
|
|
3723
|
+
G3 = G3 + this.G | 0;
|
|
3724
|
+
H2 = H2 + this.H | 0;
|
|
3725
|
+
this.set(A2, B2, C3, D2, E2, F2, G3, H2);
|
|
3726
|
+
}
|
|
3727
|
+
roundClean() {
|
|
3728
|
+
clean2(SHA256_W2);
|
|
3729
|
+
}
|
|
3730
|
+
destroy() {
|
|
3731
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
3732
|
+
clean2(this.buffer);
|
|
3733
|
+
}
|
|
3734
|
+
};
|
|
3735
|
+
var sha2562 = /* @__PURE__ */ createHasher2(() => new SHA256());
|
|
3736
|
+
|
|
3737
|
+
// ../../node_modules/@noble/hashes/esm/sha256.js
|
|
3738
|
+
var sha2563 = sha2562;
|
|
3739
|
+
|
|
3740
|
+
// ../crypto/dist/esm/suites/bsv-ecdsa.js
|
|
3741
|
+
etc.hmacSha256Sync = (key, ...msgs) => hmac(sha2563, key, etc.concatBytes(...msgs));
|
|
3742
|
+
var BsvEcdsaSuite = class {
|
|
3743
|
+
constructor() {
|
|
3744
|
+
__publicField(this, "suiteId", "bsv-ecdsa-secp256k1");
|
|
3745
|
+
__publicField(this, "version", "1.0.0");
|
|
3746
|
+
}
|
|
3747
|
+
async generateKeypair() {
|
|
3748
|
+
const privateKey = utils.randomPrivateKey();
|
|
3749
|
+
const publicKey = getPublicKey(privateKey, true);
|
|
3750
|
+
return {
|
|
3751
|
+
privateKey,
|
|
3752
|
+
publicKey
|
|
5128
3753
|
};
|
|
5129
|
-
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
5130
|
-
exports2.globalRegistry = exports2.MlDsa87Suite = exports2.MlDsaSuite = exports2.BsvEcdsaSuite = void 0;
|
|
5131
|
-
__exportStar(require_types(), exports2);
|
|
5132
|
-
__exportStar(require_registry(), exports2);
|
|
5133
|
-
__exportStar(require_utils(), exports2);
|
|
5134
|
-
__exportStar(require_signing(), exports2);
|
|
5135
|
-
__exportStar(require_key_registry(), exports2);
|
|
5136
|
-
__exportStar(require_errors(), exports2);
|
|
5137
|
-
__exportStar(require_stateless(), exports2);
|
|
5138
|
-
var bsv_ecdsa_1 = require_bsv_ecdsa();
|
|
5139
|
-
Object.defineProperty(exports2, "BsvEcdsaSuite", { enumerable: true, get: function() {
|
|
5140
|
-
return bsv_ecdsa_1.BsvEcdsaSuite;
|
|
5141
|
-
} });
|
|
5142
|
-
var ml_dsa_1 = require_ml_dsa();
|
|
5143
|
-
Object.defineProperty(exports2, "MlDsaSuite", { enumerable: true, get: function() {
|
|
5144
|
-
return ml_dsa_1.MlDsaSuite;
|
|
5145
|
-
} });
|
|
5146
|
-
Object.defineProperty(exports2, "MlDsa87Suite", { enumerable: true, get: function() {
|
|
5147
|
-
return ml_dsa_1.MlDsa87Suite;
|
|
5148
|
-
} });
|
|
5149
|
-
var registry_1 = require_registry();
|
|
5150
|
-
Object.defineProperty(exports2, "globalRegistry", { enumerable: true, get: function() {
|
|
5151
|
-
return registry_1.globalRegistry;
|
|
5152
|
-
} });
|
|
5153
3754
|
}
|
|
5154
|
-
|
|
3755
|
+
async sign(privateKey, message) {
|
|
3756
|
+
try {
|
|
3757
|
+
const signature = await sign(message, privateKey);
|
|
3758
|
+
return signature.toCompactRawBytes();
|
|
3759
|
+
} catch (error) {
|
|
3760
|
+
throw new Error(`BsvEcdsaSuite signing failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
3761
|
+
}
|
|
3762
|
+
}
|
|
3763
|
+
async verify(publicKey, message, signature) {
|
|
3764
|
+
try {
|
|
3765
|
+
return verify(signature, message, publicKey);
|
|
3766
|
+
} catch (error) {
|
|
3767
|
+
return false;
|
|
3768
|
+
}
|
|
3769
|
+
}
|
|
3770
|
+
exportPublicKey(pub) {
|
|
3771
|
+
return bytesToHex(pub);
|
|
3772
|
+
}
|
|
3773
|
+
importPublicKey(encoded) {
|
|
3774
|
+
return hexToBytes(encoded);
|
|
3775
|
+
}
|
|
3776
|
+
exportPrivateKey(priv) {
|
|
3777
|
+
return bytesToHex(priv);
|
|
3778
|
+
}
|
|
3779
|
+
importPrivateKey(encoded) {
|
|
3780
|
+
const bytes = hexToBytes(encoded);
|
|
3781
|
+
if (bytes.length !== 32) {
|
|
3782
|
+
throw new Error("Private key must be 32 bytes");
|
|
3783
|
+
}
|
|
3784
|
+
return bytes;
|
|
3785
|
+
}
|
|
3786
|
+
};
|
|
5155
3787
|
|
|
5156
|
-
//
|
|
5157
|
-
var browser_exports = {};
|
|
5158
|
-
__export(browser_exports, {
|
|
5159
|
-
InMemoryKeyStorage: () => import_crypto3.InMemoryKeyStorage,
|
|
5160
|
-
createKeySDK: () => createKeySDK,
|
|
5161
|
-
default: () => browser_default
|
|
5162
|
-
});
|
|
3788
|
+
// ../crypto/dist/esm/suites/ml-dsa.js
|
|
5163
3789
|
init_esbuild_shims();
|
|
3790
|
+
var dilithiumLib = null;
|
|
3791
|
+
async function getDilithium() {
|
|
3792
|
+
if (!dilithiumLib) {
|
|
3793
|
+
dilithiumLib = await Promise.resolve().then(() => __toESM(require_dist(), 1));
|
|
3794
|
+
}
|
|
3795
|
+
return dilithiumLib;
|
|
3796
|
+
}
|
|
3797
|
+
var MlDsa87Suite = class {
|
|
3798
|
+
constructor() {
|
|
3799
|
+
__publicField(this, "suiteId", "ml-dsa-87");
|
|
3800
|
+
__publicField(this, "version", "1.0.0");
|
|
3801
|
+
}
|
|
3802
|
+
async generateKeypair() {
|
|
3803
|
+
try {
|
|
3804
|
+
const dilithium2 = await getDilithium();
|
|
3805
|
+
const keypair = await dilithium2.keyPair();
|
|
3806
|
+
return {
|
|
3807
|
+
publicKey: new Uint8Array(keypair.publicKey),
|
|
3808
|
+
privateKey: new Uint8Array(keypair.privateKey)
|
|
3809
|
+
};
|
|
3810
|
+
} catch (error) {
|
|
3811
|
+
throw new Error(`ML-DSA-87 key generation failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
3812
|
+
}
|
|
3813
|
+
}
|
|
3814
|
+
async sign(privateKey, message) {
|
|
3815
|
+
try {
|
|
3816
|
+
const dilithium2 = await getDilithium();
|
|
3817
|
+
const signature = await dilithium2.signDetached(Buffer.from(message), Buffer.from(privateKey));
|
|
3818
|
+
return new Uint8Array(signature);
|
|
3819
|
+
} catch (error) {
|
|
3820
|
+
throw new Error(`ML-DSA-87 signing failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
3821
|
+
}
|
|
3822
|
+
}
|
|
3823
|
+
async verify(publicKey, message, signature) {
|
|
3824
|
+
try {
|
|
3825
|
+
const dilithium2 = await getDilithium();
|
|
3826
|
+
return await dilithium2.verifyDetached(Buffer.from(signature), Buffer.from(message), Buffer.from(publicKey));
|
|
3827
|
+
} catch (error) {
|
|
3828
|
+
return false;
|
|
3829
|
+
}
|
|
3830
|
+
}
|
|
3831
|
+
exportPublicKey(pub) {
|
|
3832
|
+
return bytesToHex(pub);
|
|
3833
|
+
}
|
|
3834
|
+
importPublicKey(encoded) {
|
|
3835
|
+
const bytes = hexToBytes(encoded);
|
|
3836
|
+
if (bytes.length !== 2592) {
|
|
3837
|
+
throw new Error(`ML-DSA-87 public key must be 2592 bytes, got ${bytes.length}`);
|
|
3838
|
+
}
|
|
3839
|
+
return bytes;
|
|
3840
|
+
}
|
|
3841
|
+
exportPrivateKey(priv) {
|
|
3842
|
+
return bytesToHex(priv);
|
|
3843
|
+
}
|
|
3844
|
+
importPrivateKey(encoded) {
|
|
3845
|
+
const bytes = hexToBytes(encoded);
|
|
3846
|
+
if (bytes.length !== 4864) {
|
|
3847
|
+
throw new Error(`ML-DSA-87 private key must be 4864 bytes, got ${bytes.length}`);
|
|
3848
|
+
}
|
|
3849
|
+
return bytes;
|
|
3850
|
+
}
|
|
3851
|
+
};
|
|
3852
|
+
var MlDsaSuite = class {
|
|
3853
|
+
constructor() {
|
|
3854
|
+
__publicField(this, "suiteId", "ml-dsa-65");
|
|
3855
|
+
__publicField(this, "version", "1.0.0");
|
|
3856
|
+
__publicField(this, "impl", new MlDsa87Suite());
|
|
3857
|
+
}
|
|
3858
|
+
async generateKeypair() {
|
|
3859
|
+
return this.impl.generateKeypair();
|
|
3860
|
+
}
|
|
3861
|
+
async sign(privateKey, message) {
|
|
3862
|
+
return this.impl.sign(privateKey, message);
|
|
3863
|
+
}
|
|
3864
|
+
async verify(publicKey, message, signature) {
|
|
3865
|
+
return this.impl.verify(publicKey, message, signature);
|
|
3866
|
+
}
|
|
3867
|
+
exportPublicKey(pub) {
|
|
3868
|
+
return this.impl.exportPublicKey(pub);
|
|
3869
|
+
}
|
|
3870
|
+
importPublicKey(encoded) {
|
|
3871
|
+
return this.impl.importPublicKey(encoded);
|
|
3872
|
+
}
|
|
3873
|
+
exportPrivateKey(priv) {
|
|
3874
|
+
return this.impl.exportPrivateKey(priv);
|
|
3875
|
+
}
|
|
3876
|
+
importPrivateKey(encoded) {
|
|
3877
|
+
return this.impl.importPrivateKey(encoded);
|
|
3878
|
+
}
|
|
3879
|
+
};
|
|
5164
3880
|
|
|
5165
3881
|
// src/sdk.ts
|
|
5166
|
-
init_esbuild_shims();
|
|
5167
|
-
var import_crypto = __toESM(require_dist2());
|
|
5168
3882
|
var DefaultKeySDK = class {
|
|
5169
3883
|
// agentId -> counter
|
|
5170
3884
|
constructor(config) {
|
|
@@ -5222,7 +3936,7 @@ var LumenKeys = (() => {
|
|
|
5222
3936
|
}
|
|
5223
3937
|
const suite = this.suiteRegistry.getSuite(result.meta.suiteId);
|
|
5224
3938
|
const hashAlg = this.getHashAlgorithm(result.meta.suiteId);
|
|
5225
|
-
const messageHash = await
|
|
3939
|
+
const messageHash = await hashBytes(message, hashAlg);
|
|
5226
3940
|
return await suite.sign(result.keypair.privateKey, messageHash);
|
|
5227
3941
|
}
|
|
5228
3942
|
/**
|
|
@@ -5235,7 +3949,7 @@ var LumenKeys = (() => {
|
|
|
5235
3949
|
}
|
|
5236
3950
|
const suite = this.suiteRegistry.getSuite(result.meta.suiteId);
|
|
5237
3951
|
const hashAlg = this.getHashAlgorithm(result.meta.suiteId);
|
|
5238
|
-
const messageHash = await
|
|
3952
|
+
const messageHash = await hashBytes(message, hashAlg);
|
|
5239
3953
|
try {
|
|
5240
3954
|
return await suite.verify(result.publicKey, messageHash, signature);
|
|
5241
3955
|
} catch {
|
|
@@ -5332,20 +4046,16 @@ var LumenKeys = (() => {
|
|
|
5332
4046
|
}
|
|
5333
4047
|
};
|
|
5334
4048
|
|
|
5335
|
-
// src/browser.ts
|
|
5336
|
-
var import_crypto2 = __toESM(require_dist2());
|
|
5337
|
-
|
|
5338
4049
|
// src/types.ts
|
|
5339
4050
|
init_esbuild_shims();
|
|
5340
4051
|
|
|
5341
4052
|
// src/browser.ts
|
|
5342
|
-
var import_crypto3 = __toESM(require_dist2());
|
|
5343
4053
|
async function createKeySDK() {
|
|
5344
|
-
const storage = new
|
|
5345
|
-
const keyRegistry = new
|
|
5346
|
-
const suiteRegistry = new
|
|
5347
|
-
suiteRegistry.register(new
|
|
5348
|
-
suiteRegistry.register(new
|
|
4054
|
+
const storage = new InMemoryKeyStorage();
|
|
4055
|
+
const keyRegistry = new KeyRegistry(storage);
|
|
4056
|
+
const suiteRegistry = new SignatureSuiteRegistry();
|
|
4057
|
+
suiteRegistry.register(new BsvEcdsaSuite());
|
|
4058
|
+
suiteRegistry.register(new MlDsaSuite());
|
|
5349
4059
|
const sdk = new DefaultKeySDK({
|
|
5350
4060
|
keyRegistry,
|
|
5351
4061
|
suiteRegistry
|
|
@@ -5365,7 +4075,7 @@ var LumenKeys = (() => {
|
|
|
5365
4075
|
/*! Bundled license information:
|
|
5366
4076
|
|
|
5367
4077
|
@noble/hashes/utils.js:
|
|
5368
|
-
@noble/hashes/utils.js:
|
|
4078
|
+
@noble/hashes/esm/utils.js:
|
|
5369
4079
|
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
5370
4080
|
|
|
5371
4081
|
@noble/secp256k1/index.js:
|