@dynamic-labs-wallet/forward-mpc-shared 0.1.0-alpha.6 → 0.1.0-alpha.7
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/index.cjs +823 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1030 -0
- package/dist/index.d.ts +1030 -9
- package/dist/index.js +768 -17
- package/dist/index.js.map +1 -1
- package/package.json +9 -7
- package/dist/attestation/index.d.ts +0 -1
- package/dist/attestation/index.d.ts.map +0 -1
- package/dist/attestation/index.js +0 -4
- package/dist/attestation/index.js.map +0 -1
- package/dist/codecs/DomainCodec.d.ts +0 -11
- package/dist/codecs/DomainCodec.d.ts.map +0 -1
- package/dist/codecs/DomainCodec.js +0 -25
- package/dist/codecs/DomainCodec.js.map +0 -1
- package/dist/codecs/EncryptedKeyshareCodec.d.ts +0 -11
- package/dist/codecs/EncryptedKeyshareCodec.d.ts.map +0 -1
- package/dist/codecs/EncryptedKeyshareCodec.js +0 -11
- package/dist/codecs/EncryptedKeyshareCodec.js.map +0 -1
- package/dist/codecs/Uint32ArrayCodec.d.ts +0 -3
- package/dist/codecs/Uint32ArrayCodec.d.ts.map +0 -1
- package/dist/codecs/Uint32ArrayCodec.js +0 -37
- package/dist/codecs/Uint32ArrayCodec.js.map +0 -1
- package/dist/codecs/Uint8ArrayCodec.d.ts +0 -3
- package/dist/codecs/Uint8ArrayCodec.d.ts.map +0 -1
- package/dist/codecs/Uint8ArrayCodec.js +0 -26
- package/dist/codecs/Uint8ArrayCodec.js.map +0 -1
- package/dist/codecs/Uint8ArrayOrHexCodec.d.ts +0 -3
- package/dist/codecs/Uint8ArrayOrHexCodec.d.ts.map +0 -1
- package/dist/codecs/Uint8ArrayOrHexCodec.js +0 -35
- package/dist/codecs/Uint8ArrayOrHexCodec.js.map +0 -1
- package/dist/codecs/WebSocketErrorCodec.d.ts +0 -15
- package/dist/codecs/WebSocketErrorCodec.d.ts.map +0 -1
- package/dist/codecs/WebSocketErrorCodec.js +0 -14
- package/dist/codecs/WebSocketErrorCodec.js.map +0 -1
- package/dist/codecs/index.d.ts +0 -4
- package/dist/codecs/index.d.ts.map +0 -1
- package/dist/codecs/index.js +0 -4
- package/dist/codecs/index.js.map +0 -1
- package/dist/constants/algorithms.d.ts +0 -56
- package/dist/constants/algorithms.d.ts.map +0 -1
- package/dist/constants/algorithms.js +0 -60
- package/dist/constants/algorithms.js.map +0 -1
- package/dist/constants/index.d.ts +0 -2
- package/dist/constants/index.d.ts.map +0 -1
- package/dist/constants/index.js +0 -2
- package/dist/constants/index.js.map +0 -1
- package/dist/crypto/decapsulate.d.ts +0 -2
- package/dist/crypto/decapsulate.d.ts.map +0 -1
- package/dist/crypto/decapsulate.js +0 -5
- package/dist/crypto/decapsulate.js.map +0 -1
- package/dist/crypto/encapsulate.d.ts +0 -5
- package/dist/crypto/encapsulate.d.ts.map +0 -1
- package/dist/crypto/encapsulate.js +0 -5
- package/dist/crypto/encapsulate.js.map +0 -1
- package/dist/crypto/generateKeypair.d.ts +0 -5
- package/dist/crypto/generateKeypair.d.ts.map +0 -1
- package/dist/crypto/generateKeypair.js +0 -17
- package/dist/crypto/generateKeypair.js.map +0 -1
- package/dist/crypto/index.d.ts +0 -6
- package/dist/crypto/index.d.ts.map +0 -1
- package/dist/crypto/index.js +0 -6
- package/dist/crypto/index.js.map +0 -1
- package/dist/crypto/keyDerivation.d.ts +0 -14
- package/dist/crypto/keyDerivation.d.ts.map +0 -1
- package/dist/crypto/keyDerivation.js +0 -21
- package/dist/crypto/keyDerivation.js.map +0 -1
- package/dist/crypto/keyshareEncryption.d.ts +0 -13
- package/dist/crypto/keyshareEncryption.d.ts.map +0 -1
- package/dist/crypto/keyshareEncryption.js +0 -39
- package/dist/crypto/keyshareEncryption.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/messages/ConnectionAckV1Request.d.ts +0 -43
- package/dist/messages/ConnectionAckV1Request.d.ts.map +0 -1
- package/dist/messages/ConnectionAckV1Request.js +0 -17
- package/dist/messages/ConnectionAckV1Request.js.map +0 -1
- package/dist/messages/ConnectionAckV1Response.d.ts +0 -45
- package/dist/messages/ConnectionAckV1Response.d.ts.map +0 -1
- package/dist/messages/ConnectionAckV1Response.js +0 -18
- package/dist/messages/ConnectionAckV1Response.js.map +0 -1
- package/dist/messages/HandshakeV1Request.d.ts +0 -45
- package/dist/messages/HandshakeV1Request.d.ts.map +0 -1
- package/dist/messages/HandshakeV1Request.js +0 -28
- package/dist/messages/HandshakeV1Request.js.map +0 -1
- package/dist/messages/HandshakeV1Response.d.ts +0 -47
- package/dist/messages/HandshakeV1Response.d.ts.map +0 -1
- package/dist/messages/HandshakeV1Response.js +0 -20
- package/dist/messages/HandshakeV1Response.js.map +0 -1
- package/dist/messages/SignMessageV1Request.d.ts +0 -63
- package/dist/messages/SignMessageV1Request.d.ts.map +0 -1
- package/dist/messages/SignMessageV1Request.js +0 -42
- package/dist/messages/SignMessageV1Request.js.map +0 -1
- package/dist/messages/SignMessageV1Response.d.ts +0 -47
- package/dist/messages/SignMessageV1Response.d.ts.map +0 -1
- package/dist/messages/SignMessageV1Response.js +0 -28
- package/dist/messages/SignMessageV1Response.js.map +0 -1
- package/dist/messages/allMessages.d.ts +0 -259
- package/dist/messages/allMessages.d.ts.map +0 -1
- package/dist/messages/allMessages.js +0 -57
- package/dist/messages/allMessages.js.map +0 -1
- package/dist/messages/base.d.ts +0 -27
- package/dist/messages/base.d.ts.map +0 -1
- package/dist/messages/base.js +0 -12
- package/dist/messages/base.js.map +0 -1
- package/dist/messages/index.d.ts +0 -11
- package/dist/messages/index.d.ts.map +0 -1
- package/dist/messages/index.js +0 -14
- package/dist/messages/index.js.map +0 -1
- package/dist/messages/registry.d.ts +0 -136
- package/dist/messages/registry.d.ts.map +0 -1
- package/dist/messages/registry.js +0 -67
- package/dist/messages/registry.js.map +0 -1
- package/dist/messages/utils/StandardMessage.d.ts +0 -97
- package/dist/messages/utils/StandardMessage.d.ts.map +0 -1
- package/dist/messages/utils/StandardMessage.js +0 -98
- package/dist/messages/utils/StandardMessage.js.map +0 -1
- package/dist/messages/utils/encodingHelpers.d.ts +0 -20
- package/dist/messages/utils/encodingHelpers.d.ts.map +0 -1
- package/dist/messages/utils/encodingHelpers.js +0 -50
- package/dist/messages/utils/encodingHelpers.js.map +0 -1
- package/dist/messages/utils/index.d.ts +0 -4
- package/dist/messages/utils/index.d.ts.map +0 -1
- package/dist/messages/utils/index.js +0 -5
- package/dist/messages/utils/index.js.map +0 -1
- package/dist/messages/utils/schemaBuilder.d.ts +0 -19
- package/dist/messages/utils/schemaBuilder.d.ts.map +0 -1
- package/dist/messages/utils/schemaBuilder.js +0 -31
- package/dist/messages/utils/schemaBuilder.js.map +0 -1
- package/dist/signing/algorithms/BIP340SigningAlgorithm.d.ts +0 -20
- package/dist/signing/algorithms/BIP340SigningAlgorithm.d.ts.map +0 -1
- package/dist/signing/algorithms/BIP340SigningAlgorithm.js +0 -35
- package/dist/signing/algorithms/BIP340SigningAlgorithm.js.map +0 -1
- package/dist/signing/algorithms/EcdsaSigningAlgorithm.d.ts +0 -20
- package/dist/signing/algorithms/EcdsaSigningAlgorithm.d.ts.map +0 -1
- package/dist/signing/algorithms/EcdsaSigningAlgorithm.js +0 -43
- package/dist/signing/algorithms/EcdsaSigningAlgorithm.js.map +0 -1
- package/dist/signing/algorithms/Ed25519SigningAlgorithm.d.ts +0 -18
- package/dist/signing/algorithms/Ed25519SigningAlgorithm.d.ts.map +0 -1
- package/dist/signing/algorithms/Ed25519SigningAlgorithm.js +0 -34
- package/dist/signing/algorithms/Ed25519SigningAlgorithm.js.map +0 -1
- package/dist/signing/allAlgorithms.d.ts +0 -50
- package/dist/signing/allAlgorithms.d.ts.map +0 -1
- package/dist/signing/allAlgorithms.js +0 -59
- package/dist/signing/allAlgorithms.js.map +0 -1
- package/dist/signing/base.d.ts +0 -42
- package/dist/signing/base.d.ts.map +0 -1
- package/dist/signing/base.js +0 -6
- package/dist/signing/base.js.map +0 -1
- package/dist/signing/index.d.ts +0 -7
- package/dist/signing/index.d.ts.map +0 -1
- package/dist/signing/index.js +0 -9
- package/dist/signing/index.js.map +0 -1
- package/dist/signing/registry.d.ts +0 -26
- package/dist/signing/registry.d.ts.map +0 -1
- package/dist/signing/registry.js +0 -36
- package/dist/signing/registry.js.map +0 -1
- package/dist/types.d.ts +0 -42
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -12
- package/dist/types.js.map +0 -1
- package/dist/utils/assertDefined.d.ts +0 -16
- package/dist/utils/assertDefined.d.ts.map +0 -1
- package/dist/utils/assertDefined.js +0 -27
- package/dist/utils/assertDefined.js.map +0 -1
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,823 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fpTs = require('fp-ts');
|
|
4
|
+
var ioTs = require('io-ts');
|
|
5
|
+
var utils_js = require('@noble/hashes/utils.js');
|
|
6
|
+
var core = require('@dynamic-labs-wallet/core');
|
|
7
|
+
var mlKem_js = require('@noble/post-quantum/ml-kem.js');
|
|
8
|
+
var hkdf_js = require('@noble/hashes/hkdf.js');
|
|
9
|
+
var sha2_js = require('@noble/hashes/sha2.js');
|
|
10
|
+
var aes = require('@noble/ciphers/aes');
|
|
11
|
+
|
|
12
|
+
var __defProp = Object.defineProperty;
|
|
13
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
14
|
+
|
|
15
|
+
// src/types.ts
|
|
16
|
+
var WebSocketErrorType = /* @__PURE__ */ (function(WebSocketErrorType2) {
|
|
17
|
+
WebSocketErrorType2["INVALID_MESSAGE"] = "INVALID_MESSAGE";
|
|
18
|
+
WebSocketErrorType2["HANDLER_NOT_FOUND"] = "HANDLER_NOT_FOUND";
|
|
19
|
+
WebSocketErrorType2["HANDLER_ERROR"] = "HANDLER_ERROR";
|
|
20
|
+
WebSocketErrorType2["CONNECTION_ERROR"] = "CONNECTION_ERROR";
|
|
21
|
+
WebSocketErrorType2["VALIDATION_ERROR"] = "VALIDATION_ERROR";
|
|
22
|
+
return WebSocketErrorType2;
|
|
23
|
+
})({});
|
|
24
|
+
|
|
25
|
+
// src/messages/base.ts
|
|
26
|
+
var BaseMessage = class {
|
|
27
|
+
static {
|
|
28
|
+
__name(this, "BaseMessage");
|
|
29
|
+
}
|
|
30
|
+
data;
|
|
31
|
+
constructor(data) {
|
|
32
|
+
this.data = data;
|
|
33
|
+
}
|
|
34
|
+
getData() {
|
|
35
|
+
return this.data;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var Uint8ArrayCodec = new ioTs.Type(
|
|
39
|
+
"Uint8Array",
|
|
40
|
+
(u) => u instanceof Uint8Array,
|
|
41
|
+
(u, c) => {
|
|
42
|
+
if (typeof u !== "string") {
|
|
43
|
+
return ioTs.failure(u, c, "Expected a hex string for Uint8Array");
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
const cleanHex = u.startsWith("0x") ? u.slice(2) : u;
|
|
47
|
+
if (cleanHex.length % 2 !== 0 || !/^[0-9a-fA-F]+$/.test(cleanHex)) {
|
|
48
|
+
return ioTs.failure(u, c, "Invalid hex string format");
|
|
49
|
+
}
|
|
50
|
+
const decoded = utils_js.hexToBytes(cleanHex);
|
|
51
|
+
return ioTs.success(decoded);
|
|
52
|
+
} catch (e) {
|
|
53
|
+
return ioTs.failure(u, c, `Invalid hex string: ${e}`);
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
// The `encode` function for converting back to the output type
|
|
57
|
+
(a) => utils_js.bytesToHex(a)
|
|
58
|
+
);
|
|
59
|
+
var Uint32ArrayCodec = new ioTs.Type(
|
|
60
|
+
"Uint32Array",
|
|
61
|
+
(u) => u instanceof Uint32Array,
|
|
62
|
+
(u, c) => {
|
|
63
|
+
if (typeof u !== "string") {
|
|
64
|
+
return ioTs.failure(u, c, "Expected a hex string for Uint32Array");
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
const cleanHex = u.startsWith("0x") ? u.slice(2) : u;
|
|
68
|
+
if (cleanHex.length === 0) {
|
|
69
|
+
return ioTs.failure(u, c, "Empty hex string not allowed for Uint32Array");
|
|
70
|
+
}
|
|
71
|
+
if (cleanHex.length % 8 !== 0) {
|
|
72
|
+
return ioTs.failure(u, c, "Invalid hex string format for Uint32Array (must be multiple of 8 hex characters)");
|
|
73
|
+
}
|
|
74
|
+
const uint8Array = utils_js.hexToBytes(cleanHex);
|
|
75
|
+
const uint32Array = new Uint32Array(uint8Array.buffer);
|
|
76
|
+
return ioTs.success(uint32Array);
|
|
77
|
+
} catch (e) {
|
|
78
|
+
return ioTs.failure(u, c, `Invalid hex string: ${e}`);
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
// The `encode` function for converting back to the output type
|
|
82
|
+
(a) => {
|
|
83
|
+
const uint8Array = new Uint8Array(a.buffer);
|
|
84
|
+
return utils_js.bytesToHex(uint8Array);
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
var EncryptedKeyshareCodec = ioTs.type({
|
|
88
|
+
salt: Uint8ArrayCodec,
|
|
89
|
+
encryptedPayload: Uint8ArrayCodec
|
|
90
|
+
});
|
|
91
|
+
function buildMessageSchema(messageType, version, additionalFields = {}, ...additionalSchemas) {
|
|
92
|
+
const schema = ioTs.type({
|
|
93
|
+
type: ioTs.literal(messageType),
|
|
94
|
+
version: ioTs.literal(version),
|
|
95
|
+
...additionalFields
|
|
96
|
+
});
|
|
97
|
+
if (additionalSchemas.length === 0) {
|
|
98
|
+
return schema;
|
|
99
|
+
}
|
|
100
|
+
if (additionalSchemas.length === 1) {
|
|
101
|
+
return ioTs.intersection([
|
|
102
|
+
schema,
|
|
103
|
+
additionalSchemas[0]
|
|
104
|
+
]);
|
|
105
|
+
}
|
|
106
|
+
let result = ioTs.intersection([
|
|
107
|
+
schema,
|
|
108
|
+
additionalSchemas[0]
|
|
109
|
+
]);
|
|
110
|
+
for (let i = 1; i < additionalSchemas.length; i++) {
|
|
111
|
+
result = ioTs.intersection([
|
|
112
|
+
result,
|
|
113
|
+
additionalSchemas[i]
|
|
114
|
+
]);
|
|
115
|
+
}
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
__name(buildMessageSchema, "buildMessageSchema");
|
|
119
|
+
|
|
120
|
+
// src/messages/utils/encodingHelpers.ts
|
|
121
|
+
function createComplexEncoder(messageType, version, fieldTransforms = {}) {
|
|
122
|
+
return (data) => {
|
|
123
|
+
const encoded = {
|
|
124
|
+
type: messageType,
|
|
125
|
+
version
|
|
126
|
+
};
|
|
127
|
+
for (const [key, value] of Object.entries(data)) {
|
|
128
|
+
if (value !== void 0) {
|
|
129
|
+
encoded[key] = fieldTransforms[key] ? fieldTransforms[key](value) : value;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return encoded;
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
__name(createComplexEncoder, "createComplexEncoder");
|
|
136
|
+
function createStandardDecoder(fieldExtractor) {
|
|
137
|
+
return (decoded) => fieldExtractor(decoded);
|
|
138
|
+
}
|
|
139
|
+
__name(createStandardDecoder, "createStandardDecoder");
|
|
140
|
+
function createStandardMessage(config) {
|
|
141
|
+
let StandardMessageClass = class StandardMessageClass2 extends BaseMessage {
|
|
142
|
+
static {
|
|
143
|
+
__name(this, "StandardMessageClass");
|
|
144
|
+
}
|
|
145
|
+
static MESSAGE_TYPE = config.messageType;
|
|
146
|
+
static MESSAGE_VERSION = config.version;
|
|
147
|
+
static schema = config.schema;
|
|
148
|
+
type = config.messageType;
|
|
149
|
+
version = config.version;
|
|
150
|
+
constructor(data) {
|
|
151
|
+
super(data);
|
|
152
|
+
}
|
|
153
|
+
encode() {
|
|
154
|
+
return config.encodeData(this.data, this.type, this.version);
|
|
155
|
+
}
|
|
156
|
+
static decode(wireData) {
|
|
157
|
+
const result = config.schema.decode(wireData);
|
|
158
|
+
if (fpTs.either.isLeft(result)) {
|
|
159
|
+
return result;
|
|
160
|
+
}
|
|
161
|
+
const decoded = result.right;
|
|
162
|
+
return {
|
|
163
|
+
_tag: "Right",
|
|
164
|
+
right: new StandardMessageClass2(config.decodeData(decoded))
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
return StandardMessageClass;
|
|
169
|
+
}
|
|
170
|
+
__name(createStandardMessage, "createStandardMessage");
|
|
171
|
+
function createSimpleMessage(config) {
|
|
172
|
+
return createStandardMessage({
|
|
173
|
+
messageType: config.messageType,
|
|
174
|
+
version: config.version,
|
|
175
|
+
schema: config.schema,
|
|
176
|
+
encodeData: /* @__PURE__ */ __name((data) => ({
|
|
177
|
+
type: config.messageType,
|
|
178
|
+
version: config.version,
|
|
179
|
+
...data
|
|
180
|
+
}), "encodeData"),
|
|
181
|
+
decodeData: /* @__PURE__ */ __name((decoded) => {
|
|
182
|
+
const { type: type7, version, ...data } = decoded;
|
|
183
|
+
return data;
|
|
184
|
+
}, "decodeData")
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
__name(createSimpleMessage, "createSimpleMessage");
|
|
188
|
+
|
|
189
|
+
// src/messages/HandshakeV1Request.ts
|
|
190
|
+
var HandshakeRequestSchema = buildMessageSchema("handshake", 1, {
|
|
191
|
+
challenge: Uint8ArrayCodec,
|
|
192
|
+
nonce: Uint8ArrayCodec
|
|
193
|
+
});
|
|
194
|
+
var HandshakeV1RequestMessage = createStandardMessage({
|
|
195
|
+
messageType: "handshake",
|
|
196
|
+
version: 1,
|
|
197
|
+
schema: HandshakeRequestSchema,
|
|
198
|
+
encodeData: /* @__PURE__ */ __name((data) => HandshakeRequestSchema.encode({
|
|
199
|
+
type: "handshake",
|
|
200
|
+
version: 1,
|
|
201
|
+
challenge: data.challenge,
|
|
202
|
+
nonce: data.nonce
|
|
203
|
+
}), "encodeData"),
|
|
204
|
+
decodeData: createStandardDecoder((decoded) => ({
|
|
205
|
+
challenge: decoded.challenge,
|
|
206
|
+
nonce: decoded.nonce
|
|
207
|
+
}))
|
|
208
|
+
});
|
|
209
|
+
var HandshakeResponseSchema = buildMessageSchema("handshake_response", 1, {
|
|
210
|
+
encapsulatedSharedSecret: ioTs.string,
|
|
211
|
+
attestationDoc: ioTs.string,
|
|
212
|
+
connectionId: ioTs.string
|
|
213
|
+
});
|
|
214
|
+
var HandshakeV1ResponseMessage = createSimpleMessage({
|
|
215
|
+
messageType: "handshake_response",
|
|
216
|
+
version: 1,
|
|
217
|
+
schema: HandshakeResponseSchema
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
// src/signing/base.ts
|
|
221
|
+
var BaseSigningAlgorithm = class {
|
|
222
|
+
static {
|
|
223
|
+
__name(this, "BaseSigningAlgorithm");
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
var Ed25519SigningAlgorithm = class extends BaseSigningAlgorithm {
|
|
227
|
+
static {
|
|
228
|
+
__name(this, "Ed25519SigningAlgorithm");
|
|
229
|
+
}
|
|
230
|
+
algorithmName = "ed25519";
|
|
231
|
+
version = 1;
|
|
232
|
+
schema = ioTs.intersection([
|
|
233
|
+
ioTs.type({
|
|
234
|
+
signingAlgo: ioTs.literal("ed25519")
|
|
235
|
+
}),
|
|
236
|
+
ioTs.partial({
|
|
237
|
+
derivationPath: Uint32ArrayCodec
|
|
238
|
+
})
|
|
239
|
+
]);
|
|
240
|
+
createKeygenResultFromSecretShare(secretShare) {
|
|
241
|
+
return {
|
|
242
|
+
secretShare,
|
|
243
|
+
pubkey: new Uint8Array(32)
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
createSignRequest(keygenResult, params) {
|
|
247
|
+
return {
|
|
248
|
+
secretShare: keygenResult.secretShare,
|
|
249
|
+
...params
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
processSignResult(_result) {
|
|
253
|
+
return new Uint8Array(64);
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
var BIP340SigningAlgorithm = class extends BaseSigningAlgorithm {
|
|
257
|
+
static {
|
|
258
|
+
__name(this, "BIP340SigningAlgorithm");
|
|
259
|
+
}
|
|
260
|
+
algorithmName = "bip340";
|
|
261
|
+
version = 1;
|
|
262
|
+
schema = ioTs.intersection([
|
|
263
|
+
ioTs.type({
|
|
264
|
+
signingAlgo: ioTs.literal("bip340")
|
|
265
|
+
}),
|
|
266
|
+
ioTs.partial({
|
|
267
|
+
derivationPath: Uint32ArrayCodec,
|
|
268
|
+
tweak: Uint8ArrayCodec
|
|
269
|
+
})
|
|
270
|
+
]);
|
|
271
|
+
createKeygenResultFromSecretShare(secretShare) {
|
|
272
|
+
return {
|
|
273
|
+
secretShare,
|
|
274
|
+
pubkey: new Uint8Array(32)
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
createSignRequest(keygenResult, params) {
|
|
278
|
+
return {
|
|
279
|
+
secretShare: keygenResult.secretShare,
|
|
280
|
+
...params
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
processSignResult(_result) {
|
|
284
|
+
return new Uint8Array(64);
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
var EcdsaSigningAlgorithm = class extends BaseSigningAlgorithm {
|
|
288
|
+
static {
|
|
289
|
+
__name(this, "EcdsaSigningAlgorithm");
|
|
290
|
+
}
|
|
291
|
+
algorithmName = "ecdsa";
|
|
292
|
+
version = 1;
|
|
293
|
+
schema = ioTs.intersection([
|
|
294
|
+
ioTs.type({
|
|
295
|
+
signingAlgo: ioTs.literal("ecdsa")
|
|
296
|
+
}),
|
|
297
|
+
ioTs.partial({
|
|
298
|
+
hashAlgo: ioTs.union([
|
|
299
|
+
ioTs.literal("sha256"),
|
|
300
|
+
ioTs.literal("sha256d"),
|
|
301
|
+
ioTs.literal("keccak256")
|
|
302
|
+
]),
|
|
303
|
+
derivationPath: Uint32ArrayCodec
|
|
304
|
+
})
|
|
305
|
+
]);
|
|
306
|
+
createKeygenResultFromSecretShare(secretShare) {
|
|
307
|
+
return {
|
|
308
|
+
secretShare,
|
|
309
|
+
pubkey: {
|
|
310
|
+
pubKeyAsHex: /* @__PURE__ */ __name(() => "0x" + "00".repeat(33), "pubKeyAsHex"),
|
|
311
|
+
serializeCompressed: /* @__PURE__ */ __name(() => new Uint8Array(33), "serializeCompressed"),
|
|
312
|
+
serializeUncompressed: /* @__PURE__ */ __name(() => new Uint8Array(65), "serializeUncompressed")
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
createSignRequest(keygenResult, params) {
|
|
317
|
+
return {
|
|
318
|
+
secretShare: keygenResult.secretShare,
|
|
319
|
+
...params
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
processSignResult(_result) {
|
|
323
|
+
return new Uint8Array(64);
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
// src/signing/allAlgorithms.ts
|
|
328
|
+
var SIGNING_ALGORITHM_CLASSES = {
|
|
329
|
+
ed25519: Ed25519SigningAlgorithm,
|
|
330
|
+
bip340: BIP340SigningAlgorithm,
|
|
331
|
+
ecdsa: EcdsaSigningAlgorithm
|
|
332
|
+
};
|
|
333
|
+
var ALL_SIGNING_ALGORITHM_NAMES = Object.keys(SIGNING_ALGORITHM_CLASSES);
|
|
334
|
+
var SIGNING_ALGORITHM_INSTANCES = {
|
|
335
|
+
ed25519: new SIGNING_ALGORITHM_CLASSES.ed25519(),
|
|
336
|
+
bip340: new SIGNING_ALGORITHM_CLASSES.bip340(),
|
|
337
|
+
ecdsa: new SIGNING_ALGORITHM_CLASSES.ecdsa()
|
|
338
|
+
};
|
|
339
|
+
var ALL_SIGNING_ALGORITHM_SCHEMA = (() => {
|
|
340
|
+
const schemas = Object.values(SIGNING_ALGORITHM_INSTANCES).map((instance) => instance.schema);
|
|
341
|
+
if (schemas.length === 0) {
|
|
342
|
+
throw new Error("No signing algorithms defined");
|
|
343
|
+
}
|
|
344
|
+
if (schemas.length === 1) {
|
|
345
|
+
return schemas[0];
|
|
346
|
+
}
|
|
347
|
+
return ioTs.union([
|
|
348
|
+
schemas[0],
|
|
349
|
+
schemas[1],
|
|
350
|
+
...schemas.slice(2)
|
|
351
|
+
]);
|
|
352
|
+
})();
|
|
353
|
+
function isValidSigningAlgorithm(name) {
|
|
354
|
+
return name in SIGNING_ALGORITHM_CLASSES;
|
|
355
|
+
}
|
|
356
|
+
__name(isValidSigningAlgorithm, "isValidSigningAlgorithm");
|
|
357
|
+
function createKeygenResultFromSecretShare(algorithmName, secretShare) {
|
|
358
|
+
const algorithm = SIGNING_ALGORITHM_INSTANCES[algorithmName];
|
|
359
|
+
if (!algorithm) {
|
|
360
|
+
throw new Error(`Unknown signing algorithm: ${algorithmName}`);
|
|
361
|
+
}
|
|
362
|
+
return algorithm.createKeygenResultFromSecretShare(secretShare);
|
|
363
|
+
}
|
|
364
|
+
__name(createKeygenResultFromSecretShare, "createKeygenResultFromSecretShare");
|
|
365
|
+
var ALGORITHMS = {
|
|
366
|
+
[core.SigningAlgorithm.ECDSA]: {
|
|
367
|
+
name: "ecdsa",
|
|
368
|
+
dynamicEnum: core.SigningAlgorithm.ECDSA,
|
|
369
|
+
className: "Ecdsa",
|
|
370
|
+
requiresHashAlgo: true,
|
|
371
|
+
supportsDerivationPath: true,
|
|
372
|
+
supportsTweak: false,
|
|
373
|
+
supportedHashAlgos: [
|
|
374
|
+
"sha256",
|
|
375
|
+
"sha256d",
|
|
376
|
+
"keccak256"
|
|
377
|
+
]
|
|
378
|
+
},
|
|
379
|
+
[core.SigningAlgorithm.ED25519]: {
|
|
380
|
+
name: "ed25519",
|
|
381
|
+
dynamicEnum: core.SigningAlgorithm.ED25519,
|
|
382
|
+
className: "Ed25519",
|
|
383
|
+
requiresHashAlgo: false,
|
|
384
|
+
supportsDerivationPath: true,
|
|
385
|
+
supportsTweak: false,
|
|
386
|
+
supportedHashAlgos: []
|
|
387
|
+
},
|
|
388
|
+
[core.SigningAlgorithm.BIP340]: {
|
|
389
|
+
name: "bip340",
|
|
390
|
+
dynamicEnum: core.SigningAlgorithm.BIP340,
|
|
391
|
+
className: "BIP340",
|
|
392
|
+
requiresHashAlgo: false,
|
|
393
|
+
supportsDerivationPath: true,
|
|
394
|
+
supportsTweak: true,
|
|
395
|
+
supportedHashAlgos: []
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
function toDynamicSigningAlgorithm(algorithmName) {
|
|
399
|
+
const algorithmConfig = Object.values(ALGORITHMS).find((config) => config.name === algorithmName);
|
|
400
|
+
if (!algorithmConfig) {
|
|
401
|
+
throw new Error(`Unknown algorithm: ${algorithmName}`);
|
|
402
|
+
}
|
|
403
|
+
return algorithmConfig.dynamicEnum;
|
|
404
|
+
}
|
|
405
|
+
__name(toDynamicSigningAlgorithm, "toDynamicSigningAlgorithm");
|
|
406
|
+
function fromDynamicSigningAlgorithm(dynamicAlgorithm) {
|
|
407
|
+
const algorithmConfig = ALGORITHMS[dynamicAlgorithm];
|
|
408
|
+
if (!algorithmConfig) {
|
|
409
|
+
throw new Error(`Unknown Dynamic SDK algorithm: ${dynamicAlgorithm}`);
|
|
410
|
+
}
|
|
411
|
+
return algorithmConfig.name;
|
|
412
|
+
}
|
|
413
|
+
__name(fromDynamicSigningAlgorithm, "fromDynamicSigningAlgorithm");
|
|
414
|
+
var SignatureAlgoSchema = ALL_SIGNING_ALGORITHM_SCHEMA;
|
|
415
|
+
var DomainCodec = new ioTs.Type("DomainCodec", (u) => typeof u === "string", (u, c) => {
|
|
416
|
+
if (typeof u !== "string") {
|
|
417
|
+
return ioTs.failure(u, c, "Value must be a string");
|
|
418
|
+
}
|
|
419
|
+
const domainPattern = /^[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*(?::\d{1,5})?$/;
|
|
420
|
+
if (!domainPattern.test(u)) {
|
|
421
|
+
return ioTs.failure(u, c, "Invalid domain format");
|
|
422
|
+
}
|
|
423
|
+
return ioTs.success(u);
|
|
424
|
+
}, ioTs.identity);
|
|
425
|
+
var Uint8ArrayOrHexCodec = new ioTs.Type(
|
|
426
|
+
"Uint8ArrayOrHex",
|
|
427
|
+
(u) => u instanceof Uint8Array,
|
|
428
|
+
(u, c) => {
|
|
429
|
+
if (u instanceof Uint8Array) {
|
|
430
|
+
return ioTs.success(u);
|
|
431
|
+
}
|
|
432
|
+
if (typeof u !== "string") {
|
|
433
|
+
return ioTs.failure(u, c, "Expected a hex string or Uint8Array");
|
|
434
|
+
}
|
|
435
|
+
try {
|
|
436
|
+
const cleanHex = u.startsWith("0x") ? u.slice(2) : u;
|
|
437
|
+
if (cleanHex.length % 2 !== 0 || !/^[0-9a-fA-F]+$/.test(cleanHex)) {
|
|
438
|
+
return ioTs.failure(u, c, "Invalid hex string format");
|
|
439
|
+
}
|
|
440
|
+
const decoded = utils_js.hexToBytes(cleanHex);
|
|
441
|
+
return ioTs.success(decoded);
|
|
442
|
+
} catch (e) {
|
|
443
|
+
return ioTs.failure(u, c, `Invalid hex string: ${e}`);
|
|
444
|
+
}
|
|
445
|
+
},
|
|
446
|
+
// The `encode` function for converting back to the output type
|
|
447
|
+
(a) => {
|
|
448
|
+
if (typeof a === "string") {
|
|
449
|
+
return a;
|
|
450
|
+
}
|
|
451
|
+
return utils_js.bytesToHex(a);
|
|
452
|
+
}
|
|
453
|
+
);
|
|
454
|
+
|
|
455
|
+
// src/messages/SignMessageV1Request.ts
|
|
456
|
+
var SignMessageRequestSchema = buildMessageSchema("signMessage", 1, {
|
|
457
|
+
relayDomain: DomainCodec,
|
|
458
|
+
keyshare: EncryptedKeyshareCodec,
|
|
459
|
+
message: Uint8ArrayOrHexCodec,
|
|
460
|
+
roomUuid: ioTs.string
|
|
461
|
+
}, SignatureAlgoSchema);
|
|
462
|
+
var SignMessageV1RequestMessage = createStandardMessage({
|
|
463
|
+
messageType: "signMessage",
|
|
464
|
+
version: 1,
|
|
465
|
+
schema: SignMessageRequestSchema,
|
|
466
|
+
encodeData: createComplexEncoder("signMessage", 1, {
|
|
467
|
+
signingAlgo: /* @__PURE__ */ __name((value) => fromDynamicSigningAlgorithm(value), "signingAlgo"),
|
|
468
|
+
derivationPath: /* @__PURE__ */ __name((value) => Uint32ArrayCodec.encode(value), "derivationPath"),
|
|
469
|
+
tweak: /* @__PURE__ */ __name((value) => Uint8ArrayCodec.encode(value), "tweak"),
|
|
470
|
+
keyshare: /* @__PURE__ */ __name((value) => EncryptedKeyshareCodec.encode(value), "keyshare"),
|
|
471
|
+
message: /* @__PURE__ */ __name((value) => Uint8ArrayOrHexCodec.encode(value), "message")
|
|
472
|
+
}),
|
|
473
|
+
decodeData: createStandardDecoder((decoded) => ({
|
|
474
|
+
relayDomain: decoded.relayDomain,
|
|
475
|
+
signingAlgo: decoded.signingAlgo,
|
|
476
|
+
hashAlgo: decoded.hashAlgo,
|
|
477
|
+
derivationPath: decoded.derivationPath,
|
|
478
|
+
tweak: decoded.tweak,
|
|
479
|
+
keyshare: decoded.keyshare,
|
|
480
|
+
message: decoded.message,
|
|
481
|
+
roomUuid: decoded.roomUuid
|
|
482
|
+
}))
|
|
483
|
+
});
|
|
484
|
+
var WebSocketErrorTypeCodec = ioTs.string;
|
|
485
|
+
var WebSocketErrorCodec = ioTs.type({
|
|
486
|
+
type: WebSocketErrorTypeCodec,
|
|
487
|
+
message: ioTs.string,
|
|
488
|
+
details: ioTs.union([
|
|
489
|
+
ioTs.unknown,
|
|
490
|
+
ioTs.undefined
|
|
491
|
+
])
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
// src/messages/SignMessageV1Response.ts
|
|
495
|
+
var SignMessageResponseSchema = buildMessageSchema("signMessage_response", 1, {
|
|
496
|
+
signature: ioTs.union([
|
|
497
|
+
Uint8ArrayOrHexCodec,
|
|
498
|
+
ioTs.undefined
|
|
499
|
+
]),
|
|
500
|
+
error: ioTs.union([
|
|
501
|
+
WebSocketErrorCodec,
|
|
502
|
+
ioTs.undefined
|
|
503
|
+
])
|
|
504
|
+
});
|
|
505
|
+
var SignMessageV1ResponseMessage = createStandardMessage({
|
|
506
|
+
messageType: "signMessage_response",
|
|
507
|
+
version: 1,
|
|
508
|
+
schema: SignMessageResponseSchema,
|
|
509
|
+
encodeData: createComplexEncoder("signMessage_response", 1, {
|
|
510
|
+
signature: /* @__PURE__ */ __name((value) => Uint8ArrayOrHexCodec.encode(value), "signature")
|
|
511
|
+
}),
|
|
512
|
+
decodeData: createStandardDecoder((decoded) => ({
|
|
513
|
+
signature: decoded.signature,
|
|
514
|
+
error: decoded.error
|
|
515
|
+
}))
|
|
516
|
+
});
|
|
517
|
+
var ConnectionAckRequestSchema = buildMessageSchema("connection_ack", 1, {
|
|
518
|
+
connectionId: ioTs.union([
|
|
519
|
+
ioTs.string,
|
|
520
|
+
ioTs.undefined
|
|
521
|
+
])
|
|
522
|
+
});
|
|
523
|
+
var ConnectionAckV1RequestMessage = createSimpleMessage({
|
|
524
|
+
messageType: "connection_ack",
|
|
525
|
+
version: 1,
|
|
526
|
+
schema: ConnectionAckRequestSchema
|
|
527
|
+
});
|
|
528
|
+
var ConnectionAckResponseSchema = buildMessageSchema("connection_ack_response", 1, {
|
|
529
|
+
status: ioTs.literal("acknowledged"),
|
|
530
|
+
timestamp: ioTs.string
|
|
531
|
+
});
|
|
532
|
+
var ConnectionAckV1ResponseMessage = createSimpleMessage({
|
|
533
|
+
messageType: "connection_ack_response",
|
|
534
|
+
version: 1,
|
|
535
|
+
schema: ConnectionAckResponseSchema
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
// src/messages/allMessages.ts
|
|
539
|
+
var ALL_MESSAGE_CLASSES = {
|
|
540
|
+
"handshake@1": HandshakeV1RequestMessage,
|
|
541
|
+
"handshake_response@1": HandshakeV1ResponseMessage,
|
|
542
|
+
"signMessage@1": SignMessageV1RequestMessage,
|
|
543
|
+
"signMessage_response@1": SignMessageV1ResponseMessage,
|
|
544
|
+
"connection_ack@1": ConnectionAckV1RequestMessage,
|
|
545
|
+
"connection_ack_response@1": ConnectionAckV1ResponseMessage
|
|
546
|
+
};
|
|
547
|
+
var ALL_MESSAGE_KEYS = Object.keys(ALL_MESSAGE_CLASSES);
|
|
548
|
+
function getMessageClass(type7, version) {
|
|
549
|
+
const key = `${type7}@${version}`;
|
|
550
|
+
const MessageClass = ALL_MESSAGE_CLASSES[key];
|
|
551
|
+
if (!MessageClass) {
|
|
552
|
+
throw new Error(`Unknown message type: ${type7} version ${version}`);
|
|
553
|
+
}
|
|
554
|
+
return MessageClass;
|
|
555
|
+
}
|
|
556
|
+
__name(getMessageClass, "getMessageClass");
|
|
557
|
+
function isValidMessageType(type7, version) {
|
|
558
|
+
const key = `${type7}@${version}`;
|
|
559
|
+
return key in ALL_MESSAGE_CLASSES;
|
|
560
|
+
}
|
|
561
|
+
__name(isValidMessageType, "isValidMessageType");
|
|
562
|
+
function getAllSupportedMessages() {
|
|
563
|
+
return ALL_MESSAGE_KEYS.map((key) => {
|
|
564
|
+
const [type7, versionStr] = key.split("@");
|
|
565
|
+
return {
|
|
566
|
+
type: type7,
|
|
567
|
+
version: parseInt(versionStr, 10)
|
|
568
|
+
};
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
__name(getAllSupportedMessages, "getAllSupportedMessages");
|
|
572
|
+
function parseMessageKey(key) {
|
|
573
|
+
const [type7, versionStr] = key.split("@");
|
|
574
|
+
return {
|
|
575
|
+
type: type7,
|
|
576
|
+
version: parseInt(versionStr, 10)
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
__name(parseMessageKey, "parseMessageKey");
|
|
580
|
+
|
|
581
|
+
// src/messages/registry.ts
|
|
582
|
+
var MessageRegistry = class _MessageRegistry {
|
|
583
|
+
static {
|
|
584
|
+
__name(this, "MessageRegistry");
|
|
585
|
+
}
|
|
586
|
+
static instance;
|
|
587
|
+
constructor() {
|
|
588
|
+
}
|
|
589
|
+
static getInstance() {
|
|
590
|
+
if (!_MessageRegistry.instance) {
|
|
591
|
+
_MessageRegistry.instance = new _MessageRegistry();
|
|
592
|
+
}
|
|
593
|
+
return _MessageRegistry.instance;
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* Get a message class by type and version (derived from single source)
|
|
597
|
+
*/
|
|
598
|
+
getMessageClass(type7, version) {
|
|
599
|
+
try {
|
|
600
|
+
return getMessageClass(type7, version);
|
|
601
|
+
} catch {
|
|
602
|
+
return void 0;
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
/**
|
|
606
|
+
* Create a message instance from wire data (using derived message classes)
|
|
607
|
+
*/
|
|
608
|
+
decode(wireData) {
|
|
609
|
+
if (!wireData || typeof wireData !== "object") {
|
|
610
|
+
return {
|
|
611
|
+
_tag: "Left",
|
|
612
|
+
left: "Invalid wire data: must be an object"
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
const { type: type7, version } = wireData;
|
|
616
|
+
if (!type7 || !version) {
|
|
617
|
+
return {
|
|
618
|
+
_tag: "Left",
|
|
619
|
+
left: "Invalid wire data: missing type or version"
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
const MessageClass = this.getMessageClass(type7, version);
|
|
623
|
+
if (!MessageClass) {
|
|
624
|
+
return {
|
|
625
|
+
_tag: "Left",
|
|
626
|
+
left: `Unknown message type: ${type7}@${version}`
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
const result = MessageClass.decode(wireData);
|
|
630
|
+
if (fpTs.either.isLeft(result)) {
|
|
631
|
+
return {
|
|
632
|
+
_tag: "Left",
|
|
633
|
+
left: `Decode error: ${result.left.map((e) => e.message).join(", ")}`
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
return {
|
|
637
|
+
_tag: "Right",
|
|
638
|
+
right: result.right
|
|
639
|
+
};
|
|
640
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* Encode a message to wire format
|
|
643
|
+
*/
|
|
644
|
+
encode(message) {
|
|
645
|
+
return message.encode();
|
|
646
|
+
}
|
|
647
|
+
/**
|
|
648
|
+
* Get all registered message types (derived from single source)
|
|
649
|
+
*/
|
|
650
|
+
getRegisteredTypes() {
|
|
651
|
+
return getAllSupportedMessages().map(({ type: type7, version }) => `${type7}@${version}`);
|
|
652
|
+
}
|
|
653
|
+
};
|
|
654
|
+
var messageRegistry = MessageRegistry.getInstance();
|
|
655
|
+
|
|
656
|
+
// src/utils/assertDefined.ts
|
|
657
|
+
function assertDefined(value, message) {
|
|
658
|
+
if (value === null || value === void 0) {
|
|
659
|
+
throw new Error(message ?? "Value must be defined");
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
__name(assertDefined, "assertDefined");
|
|
663
|
+
function assertNotNull(value, message) {
|
|
664
|
+
if (value === null) {
|
|
665
|
+
throw new Error(message ?? "Value must not be null");
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
__name(assertNotNull, "assertNotNull");
|
|
669
|
+
function getDefined(value, message) {
|
|
670
|
+
assertDefined(value, message);
|
|
671
|
+
return value;
|
|
672
|
+
}
|
|
673
|
+
__name(getDefined, "getDefined");
|
|
674
|
+
|
|
675
|
+
// src/crypto/generateKeypair.ts
|
|
676
|
+
var generateMlKem768Keypair = /* @__PURE__ */ __name(() => {
|
|
677
|
+
try {
|
|
678
|
+
const keys = mlKem_js.ml_kem768.keygen();
|
|
679
|
+
assertNotNull(keys.publicKey, "Encapsulation key must be defined");
|
|
680
|
+
assertNotNull(keys.secretKey, "Decapsulation key must be defined");
|
|
681
|
+
return {
|
|
682
|
+
encapsulationKey: keys.publicKey,
|
|
683
|
+
decapsulationKey: keys.secretKey
|
|
684
|
+
};
|
|
685
|
+
} catch (error) {
|
|
686
|
+
throw new Error(`Failed to generate ML-KEM-768 keypair: ${error instanceof Error ? error.message : String(error)}`);
|
|
687
|
+
}
|
|
688
|
+
}, "generateMlKem768Keypair");
|
|
689
|
+
var encapsulateMlKem768 = /* @__PURE__ */ __name((encapsulationKey) => {
|
|
690
|
+
return mlKem_js.ml_kem768.encapsulate(encapsulationKey);
|
|
691
|
+
}, "encapsulateMlKem768");
|
|
692
|
+
var decapsulateMlKem768 = /* @__PURE__ */ __name((decapsulationKey, cipherText) => {
|
|
693
|
+
return mlKem_js.ml_kem768.decapsulate(cipherText, decapsulationKey);
|
|
694
|
+
}, "decapsulateMlKem768");
|
|
695
|
+
var AES_256_GCM_KEY_SIZE = 32;
|
|
696
|
+
var AES_256_GCM_NONCE_SIZE = 12;
|
|
697
|
+
var AES_256_GCM_TAG_SIZE = 16;
|
|
698
|
+
var HKDF_SALT_SIZE = 32;
|
|
699
|
+
function deriveAESKey(sharedSecret, salt, info) {
|
|
700
|
+
const infoBytes = new TextEncoder().encode(info);
|
|
701
|
+
return hkdf_js.hkdf(sha2_js.sha256, sharedSecret, salt, infoBytes, AES_256_GCM_KEY_SIZE);
|
|
702
|
+
}
|
|
703
|
+
__name(deriveAESKey, "deriveAESKey");
|
|
704
|
+
function createKeyDerivationInfo(purpose, connectionId, version = 1) {
|
|
705
|
+
return `forward-mpc-${purpose}-v${version}-${connectionId}`;
|
|
706
|
+
}
|
|
707
|
+
__name(createKeyDerivationInfo, "createKeyDerivationInfo");
|
|
708
|
+
async function encryptKeyshare(keyshare, sharedSecret, connectionId, signingAlgorithm) {
|
|
709
|
+
const salt = utils_js.randomBytes(32);
|
|
710
|
+
const keyshareInfo = createKeyDerivationInfo("keyshare", connectionId);
|
|
711
|
+
const aesKey = deriveAESKey(sharedSecret, salt, keyshareInfo);
|
|
712
|
+
const keyshareData = {
|
|
713
|
+
keyshare,
|
|
714
|
+
signingAlgorithm,
|
|
715
|
+
timestamp: Date.now(),
|
|
716
|
+
nonce: utils_js.bytesToHex(utils_js.randomBytes(16))
|
|
717
|
+
};
|
|
718
|
+
const nonce = utils_js.randomBytes(12);
|
|
719
|
+
const aes256Gcm = aes.gcm(aesKey, nonce);
|
|
720
|
+
const plaintext = new TextEncoder().encode(JSON.stringify(keyshareData));
|
|
721
|
+
const ciphertext = aes256Gcm.encrypt(plaintext);
|
|
722
|
+
const encryptedPayload = new Uint8Array(nonce.length + ciphertext.length);
|
|
723
|
+
encryptedPayload.set(nonce, 0);
|
|
724
|
+
encryptedPayload.set(ciphertext, nonce.length);
|
|
725
|
+
aesKey.fill(0);
|
|
726
|
+
return {
|
|
727
|
+
salt,
|
|
728
|
+
encryptedPayload
|
|
729
|
+
};
|
|
730
|
+
}
|
|
731
|
+
__name(encryptKeyshare, "encryptKeyshare");
|
|
732
|
+
|
|
733
|
+
// src/signing/registry.ts
|
|
734
|
+
var SigningAlgorithmRegistry = class SigningAlgorithmRegistry2 {
|
|
735
|
+
static {
|
|
736
|
+
__name(this, "SigningAlgorithmRegistry");
|
|
737
|
+
}
|
|
738
|
+
/**
|
|
739
|
+
* Get algorithm instance (derived from single source of truth)
|
|
740
|
+
*/
|
|
741
|
+
get(name) {
|
|
742
|
+
const algorithm = SIGNING_ALGORITHM_INSTANCES[name];
|
|
743
|
+
if (!algorithm) {
|
|
744
|
+
throw new Error(`Unknown signing algorithm: ${name}`);
|
|
745
|
+
}
|
|
746
|
+
return algorithm;
|
|
747
|
+
}
|
|
748
|
+
/**
|
|
749
|
+
* Type-safe check if algorithm exists
|
|
750
|
+
*/
|
|
751
|
+
has(name) {
|
|
752
|
+
return isValidSigningAlgorithm(name);
|
|
753
|
+
}
|
|
754
|
+
/**
|
|
755
|
+
* Get all algorithm names (derived from classes)
|
|
756
|
+
*/
|
|
757
|
+
getAllNames() {
|
|
758
|
+
return ALL_SIGNING_ALGORITHM_NAMES;
|
|
759
|
+
}
|
|
760
|
+
/**
|
|
761
|
+
* Get all algorithm instances (derived from classes)
|
|
762
|
+
*/
|
|
763
|
+
getAllInstances() {
|
|
764
|
+
return SIGNING_ALGORITHM_INSTANCES;
|
|
765
|
+
}
|
|
766
|
+
};
|
|
767
|
+
var signingAlgorithmRegistry = new SigningAlgorithmRegistry();
|
|
768
|
+
|
|
769
|
+
exports.AES_256_GCM_KEY_SIZE = AES_256_GCM_KEY_SIZE;
|
|
770
|
+
exports.AES_256_GCM_NONCE_SIZE = AES_256_GCM_NONCE_SIZE;
|
|
771
|
+
exports.AES_256_GCM_TAG_SIZE = AES_256_GCM_TAG_SIZE;
|
|
772
|
+
exports.ALGORITHMS = ALGORITHMS;
|
|
773
|
+
exports.ALL_MESSAGE_CLASSES = ALL_MESSAGE_CLASSES;
|
|
774
|
+
exports.ALL_MESSAGE_KEYS = ALL_MESSAGE_KEYS;
|
|
775
|
+
exports.ALL_SIGNING_ALGORITHM_NAMES = ALL_SIGNING_ALGORITHM_NAMES;
|
|
776
|
+
exports.ALL_SIGNING_ALGORITHM_SCHEMA = ALL_SIGNING_ALGORITHM_SCHEMA;
|
|
777
|
+
exports.BIP340SigningAlgorithm = BIP340SigningAlgorithm;
|
|
778
|
+
exports.BaseMessage = BaseMessage;
|
|
779
|
+
exports.BaseSigningAlgorithm = BaseSigningAlgorithm;
|
|
780
|
+
exports.ConnectionAckRequestSchema = ConnectionAckRequestSchema;
|
|
781
|
+
exports.ConnectionAckResponseSchema = ConnectionAckResponseSchema;
|
|
782
|
+
exports.ConnectionAckV1RequestMessage = ConnectionAckV1RequestMessage;
|
|
783
|
+
exports.ConnectionAckV1ResponseMessage = ConnectionAckV1ResponseMessage;
|
|
784
|
+
exports.EcdsaSigningAlgorithm = EcdsaSigningAlgorithm;
|
|
785
|
+
exports.Ed25519SigningAlgorithm = Ed25519SigningAlgorithm;
|
|
786
|
+
exports.EncryptedKeyshareCodec = EncryptedKeyshareCodec;
|
|
787
|
+
exports.HKDF_SALT_SIZE = HKDF_SALT_SIZE;
|
|
788
|
+
exports.HandshakeRequestSchema = HandshakeRequestSchema;
|
|
789
|
+
exports.HandshakeResponseSchema = HandshakeResponseSchema;
|
|
790
|
+
exports.HandshakeV1RequestMessage = HandshakeV1RequestMessage;
|
|
791
|
+
exports.HandshakeV1ResponseMessage = HandshakeV1ResponseMessage;
|
|
792
|
+
exports.MessageRegistry = MessageRegistry;
|
|
793
|
+
exports.SIGNING_ALGORITHM_CLASSES = SIGNING_ALGORITHM_CLASSES;
|
|
794
|
+
exports.SIGNING_ALGORITHM_INSTANCES = SIGNING_ALGORITHM_INSTANCES;
|
|
795
|
+
exports.SignMessageRequestSchema = SignMessageRequestSchema;
|
|
796
|
+
exports.SignMessageResponseSchema = SignMessageResponseSchema;
|
|
797
|
+
exports.SignMessageV1RequestMessage = SignMessageV1RequestMessage;
|
|
798
|
+
exports.SignMessageV1ResponseMessage = SignMessageV1ResponseMessage;
|
|
799
|
+
exports.SignatureAlgoSchema = SignatureAlgoSchema;
|
|
800
|
+
exports.Uint32ArrayCodec = Uint32ArrayCodec;
|
|
801
|
+
exports.Uint8ArrayCodec = Uint8ArrayCodec;
|
|
802
|
+
exports.WebSocketErrorType = WebSocketErrorType;
|
|
803
|
+
exports.assertDefined = assertDefined;
|
|
804
|
+
exports.assertNotNull = assertNotNull;
|
|
805
|
+
exports.createKeyDerivationInfo = createKeyDerivationInfo;
|
|
806
|
+
exports.createKeygenResultFromSecretShare = createKeygenResultFromSecretShare;
|
|
807
|
+
exports.decapsulateMlKem768 = decapsulateMlKem768;
|
|
808
|
+
exports.deriveAESKey = deriveAESKey;
|
|
809
|
+
exports.encapsulateMlKem768 = encapsulateMlKem768;
|
|
810
|
+
exports.encryptKeyshare = encryptKeyshare;
|
|
811
|
+
exports.fromDynamicSigningAlgorithm = fromDynamicSigningAlgorithm;
|
|
812
|
+
exports.generateMlKem768Keypair = generateMlKem768Keypair;
|
|
813
|
+
exports.getAllSupportedMessages = getAllSupportedMessages;
|
|
814
|
+
exports.getDefined = getDefined;
|
|
815
|
+
exports.getMessageClass = getMessageClass;
|
|
816
|
+
exports.isValidMessageType = isValidMessageType;
|
|
817
|
+
exports.isValidSigningAlgorithm = isValidSigningAlgorithm;
|
|
818
|
+
exports.messageRegistry = messageRegistry;
|
|
819
|
+
exports.parseMessageKey = parseMessageKey;
|
|
820
|
+
exports.signingAlgorithmRegistry = signingAlgorithmRegistry;
|
|
821
|
+
exports.toDynamicSigningAlgorithm = toDynamicSigningAlgorithm;
|
|
822
|
+
//# sourceMappingURL=index.cjs.map
|
|
823
|
+
//# sourceMappingURL=index.cjs.map
|