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