@zhoujun_aptos/octopus-ts-sdk-min 0.1.0
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/README.md +108 -0
- package/dist/aes256gcm.d.ts +16 -0
- package/dist/aes256gcm.d.ts.map +1 -0
- package/dist/aes256gcm.js +98 -0
- package/dist/aes256gcm.js.map +1 -0
- package/dist/elgamal.d.ts +31 -0
- package/dist/elgamal.d.ts.map +1 -0
- package/dist/elgamal.js +96 -0
- package/dist/elgamal.js.map +1 -0
- package/dist/enc/index.d.ts +35 -0
- package/dist/enc/index.d.ts.map +1 -0
- package/dist/enc/index.js +171 -0
- package/dist/enc/index.js.map +1 -0
- package/dist/enc/simple_elgamal_ristretto255.d.ts +27 -0
- package/dist/enc/simple_elgamal_ristretto255.d.ts.map +1 -0
- package/dist/enc/simple_elgamal_ristretto255.js +135 -0
- package/dist/enc/simple_elgamal_ristretto255.js.map +1 -0
- package/dist/group.d.ts +37 -0
- package/dist/group.d.ts.map +1 -0
- package/dist/group.js +150 -0
- package/dist/group.js.map +1 -0
- package/dist/ibe/index.d.ts +46 -0
- package/dist/ibe/index.d.ts.map +1 -0
- package/dist/ibe/index.js +238 -0
- package/dist/ibe/index.js.map +1 -0
- package/dist/ibe/otp_hmac_boneh_franklin_bls12381_short_pk.d.ts +37 -0
- package/dist/ibe/otp_hmac_boneh_franklin_bls12381_short_pk.d.ts.map +1 -0
- package/dist/ibe/otp_hmac_boneh_franklin_bls12381_short_pk.js +131 -0
- package/dist/ibe/otp_hmac_boneh_franklin_bls12381_short_pk.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +47 -0
- package/dist/index.js.map +1 -0
- package/dist/shamir_gf256.d.ts +61 -0
- package/dist/shamir_gf256.d.ts.map +1 -0
- package/dist/shamir_gf256.js +295 -0
- package/dist/shamir_gf256.js.map +1 -0
- package/dist/sig/index.d.ts +35 -0
- package/dist/sig/index.d.ts.map +1 -0
- package/dist/sig/index.js +171 -0
- package/dist/sig/index.js.map +1 -0
- package/dist/sig/schnorr_ristretto255.d.ts +28 -0
- package/dist/sig/schnorr_ristretto255.d.ts.map +1 -0
- package/dist/sig/schnorr_ristretto255.js +135 -0
- package/dist/sig/schnorr_ristretto255.js.map +1 -0
- package/dist/silent_setup_encryption.d.ts +82 -0
- package/dist/silent_setup_encryption.d.ts.map +1 -0
- package/dist/silent_setup_encryption.js +285 -0
- package/dist/silent_setup_encryption.js.map +1 -0
- package/dist/utils.d.ts +9 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +100 -0
- package/dist/utils.js.map +1 -0
- package/dist/worker_config.d.ts +17 -0
- package/dist/worker_config.d.ts.map +1 -0
- package/dist/worker_config.js +84 -0
- package/dist/worker_config.js.map +1 -0
- package/dist/worker_task.d.ts +15 -0
- package/dist/worker_task.d.ts.map +1 -0
- package/dist/worker_task.js +59 -0
- package/dist/worker_task.js.map +1 -0
- package/package.json +35 -0
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.RequestForDecryptionKey = exports.Decryptor = exports.Encryptor = exports.Ciphertext = exports.DecryptionContext = exports.EncryptionContext = void 0;
|
|
37
|
+
const ts_sdk_1 = require("@aptos-labs/ts-sdk");
|
|
38
|
+
const WorkerConfig = __importStar(require("./worker_config"));
|
|
39
|
+
const Utils = __importStar(require("./utils"));
|
|
40
|
+
const ShamirGF256 = __importStar(require("./shamir_gf256"));
|
|
41
|
+
const IBE = __importStar(require("./ibe"));
|
|
42
|
+
const worker_task_1 = require("./worker_task");
|
|
43
|
+
const utils_1 = require("@noble/curves/utils");
|
|
44
|
+
const AES256GCM = __importStar(require("./aes256gcm"));
|
|
45
|
+
class EncryptionContext {
|
|
46
|
+
workers;
|
|
47
|
+
threshold;
|
|
48
|
+
moduleAddr;
|
|
49
|
+
moduleName;
|
|
50
|
+
constructor({ workers, threshold, moduleAddr, moduleName }) {
|
|
51
|
+
this.workers = workers;
|
|
52
|
+
this.threshold = threshold;
|
|
53
|
+
this.moduleAddr = moduleAddr;
|
|
54
|
+
this.moduleName = moduleName;
|
|
55
|
+
}
|
|
56
|
+
serialize(serializer) {
|
|
57
|
+
serializer.serializeVector(this.workers);
|
|
58
|
+
serializer.serializeU64(this.threshold);
|
|
59
|
+
serializer.serialize(this.moduleAddr);
|
|
60
|
+
serializer.serializeStr(this.moduleName);
|
|
61
|
+
}
|
|
62
|
+
toBytes() {
|
|
63
|
+
const serializer = new ts_sdk_1.Serializer();
|
|
64
|
+
this.serialize(serializer);
|
|
65
|
+
return serializer.toUint8Array();
|
|
66
|
+
}
|
|
67
|
+
async loadEncryptor(aptos) {
|
|
68
|
+
const workerConfigs = await Promise.all(this.workers.map(async (worker) => {
|
|
69
|
+
const config = await WorkerConfig.view(aptos, worker);
|
|
70
|
+
return config;
|
|
71
|
+
}));
|
|
72
|
+
const ibePublicKeys = workerConfigs.map(config => config.ibeMpk);
|
|
73
|
+
return new Encryptor(this, workerConfigs, ibePublicKeys);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.EncryptionContext = EncryptionContext;
|
|
77
|
+
class DecryptionContext {
|
|
78
|
+
workers;
|
|
79
|
+
threshold;
|
|
80
|
+
moduleAddr;
|
|
81
|
+
moduleName;
|
|
82
|
+
domain;
|
|
83
|
+
constructor({ workers, threshold, moduleAddr, moduleName, domain }) {
|
|
84
|
+
this.workers = workers;
|
|
85
|
+
this.threshold = threshold;
|
|
86
|
+
this.moduleAddr = moduleAddr;
|
|
87
|
+
this.moduleName = moduleName;
|
|
88
|
+
this.domain = domain;
|
|
89
|
+
}
|
|
90
|
+
static deserialize(deserializer) {
|
|
91
|
+
const workers = deserializer.deserializeVector(ts_sdk_1.AccountAddress);
|
|
92
|
+
const threshold = Number(deserializer.deserializeU64());
|
|
93
|
+
const moduleAddr = deserializer.deserialize(ts_sdk_1.AccountAddress);
|
|
94
|
+
const moduleName = deserializer.deserializeStr();
|
|
95
|
+
const domain = deserializer.deserializeBytes();
|
|
96
|
+
return new DecryptionContext({ workers, threshold, moduleAddr, moduleName, domain });
|
|
97
|
+
}
|
|
98
|
+
serialize(serializer) {
|
|
99
|
+
serializer.serializeVector(this.workers);
|
|
100
|
+
serializer.serializeU64(this.threshold);
|
|
101
|
+
serializer.serialize(this.moduleAddr);
|
|
102
|
+
serializer.serializeStr(this.moduleName);
|
|
103
|
+
serializer.serializeBytes(this.domain);
|
|
104
|
+
}
|
|
105
|
+
toBytes() {
|
|
106
|
+
const serializer = new ts_sdk_1.Serializer();
|
|
107
|
+
this.serialize(serializer);
|
|
108
|
+
return serializer.toUint8Array();
|
|
109
|
+
}
|
|
110
|
+
toHex() {
|
|
111
|
+
return (0, utils_1.bytesToHex)(this.toBytes());
|
|
112
|
+
}
|
|
113
|
+
async loadDecryptor({ aptos, userAddr, publicKey, signature }) {
|
|
114
|
+
const decKeyLoadResults = await Promise.all(this.workers.map(async (worker) => {
|
|
115
|
+
const config = await WorkerConfig.view(aptos, worker);
|
|
116
|
+
const task = worker_task_1.WorkerTask.newSilentSetupDecryptionKey(this, userAddr, publicKey, signature);
|
|
117
|
+
const controller = new AbortController();
|
|
118
|
+
const timeoutId = setTimeout(() => controller.abort(), 5000);
|
|
119
|
+
var response = null;
|
|
120
|
+
try {
|
|
121
|
+
response = await fetch(config.endpoint, {
|
|
122
|
+
method: "POST",
|
|
123
|
+
body: task.toHex(),
|
|
124
|
+
signal: controller.signal
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
clearTimeout(timeoutId);
|
|
129
|
+
}
|
|
130
|
+
if (response == null) {
|
|
131
|
+
return new WorkerTimedOut();
|
|
132
|
+
}
|
|
133
|
+
const responseBody = await response.text();
|
|
134
|
+
if (response.status !== 200) {
|
|
135
|
+
return new WorkerRejected(response.status, responseBody);
|
|
136
|
+
}
|
|
137
|
+
try {
|
|
138
|
+
return IBE.IdentityPrivateKey.fromHex(responseBody);
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
return new CouldNotParseDecryptionKey(responseBody);
|
|
142
|
+
}
|
|
143
|
+
}));
|
|
144
|
+
const numSharesCollected = decKeyLoadResults.filter((loadResult) => loadResult instanceof IBE.IdentityPrivateKey).length;
|
|
145
|
+
if (numSharesCollected < this.threshold) {
|
|
146
|
+
const workerResults = this.workers.map((worker, i) => {
|
|
147
|
+
const result = decKeyLoadResults[i];
|
|
148
|
+
return `${worker}: ${result instanceof IBE.IdentityPrivateKey ? 'Success' : result.toDisplayString()}`;
|
|
149
|
+
}).join(', ');
|
|
150
|
+
throw new Error(`Failed to collect enough shares to decrypt. Collected ${numSharesCollected} shares, but needed ${this.threshold} shares. Worker results: ${workerResults}`);
|
|
151
|
+
}
|
|
152
|
+
const decKeys = decKeyLoadResults.map((loadResult) => loadResult instanceof IBE.IdentityPrivateKey ? loadResult : null);
|
|
153
|
+
return new Decryptor(this, decKeys);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
exports.DecryptionContext = DecryptionContext;
|
|
157
|
+
class Ciphertext {
|
|
158
|
+
decryptionContext;
|
|
159
|
+
aesCiph;
|
|
160
|
+
ibeCiphs;
|
|
161
|
+
constructor(decryptionContext, aesCiph, ibeCiphs) {
|
|
162
|
+
this.decryptionContext = decryptionContext;
|
|
163
|
+
this.aesCiph = aesCiph;
|
|
164
|
+
this.ibeCiphs = ibeCiphs;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
exports.Ciphertext = Ciphertext;
|
|
168
|
+
class Encryptor {
|
|
169
|
+
domain;
|
|
170
|
+
workerConfigs;
|
|
171
|
+
ibePublicKeys;
|
|
172
|
+
constructor(domain, workerConfigs, ibePublicKeys) {
|
|
173
|
+
this.domain = domain;
|
|
174
|
+
this.workerConfigs = workerConfigs;
|
|
175
|
+
this.ibePublicKeys = ibePublicKeys;
|
|
176
|
+
}
|
|
177
|
+
encrypt({ domain, plaintext }) {
|
|
178
|
+
const decCtxt = new DecryptionContext({
|
|
179
|
+
workers: this.domain.workers,
|
|
180
|
+
threshold: this.domain.threshold,
|
|
181
|
+
moduleAddr: this.domain.moduleAddr,
|
|
182
|
+
moduleName: this.domain.moduleName,
|
|
183
|
+
domain: domain,
|
|
184
|
+
});
|
|
185
|
+
const aesKey = Utils.randBytes(32);
|
|
186
|
+
const aesKeyShares = ShamirGF256.split(aesKey, this.domain.workers.length, this.domain.threshold);
|
|
187
|
+
const aesCiph = AES256GCM.encrypt(aesKey, plaintext);
|
|
188
|
+
const ibeCiphs = aesKeyShares.map((share, idx) => IBE.encrypt(this.ibePublicKeys[idx], decCtxt.toBytes(), share.payload));
|
|
189
|
+
return new Ciphertext(decCtxt, aesCiph, ibeCiphs);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
exports.Encryptor = Encryptor;
|
|
193
|
+
class Decryptor {
|
|
194
|
+
ibeDecryptionKeys;
|
|
195
|
+
decryptionContext;
|
|
196
|
+
constructor(decryptionContext, ibeDecryptionKeys) {
|
|
197
|
+
this.decryptionContext = decryptionContext;
|
|
198
|
+
this.ibeDecryptionKeys = ibeDecryptionKeys;
|
|
199
|
+
}
|
|
200
|
+
decrypt(ciphertext) {
|
|
201
|
+
if (ciphertext.decryptionContext.toHex() !== this.decryptionContext.toHex()) {
|
|
202
|
+
throw new Error("Ciphertext does not match decryption domain");
|
|
203
|
+
}
|
|
204
|
+
const aesKeyShares = ciphertext.ibeCiphs.map((ibeCiph, idx) => {
|
|
205
|
+
if (this.ibeDecryptionKeys[idx] == null)
|
|
206
|
+
return null;
|
|
207
|
+
const sharePayload = IBE.decrypt(this.ibeDecryptionKeys[idx], ibeCiph);
|
|
208
|
+
return new ShamirGF256.Share(idx + 1, sharePayload);
|
|
209
|
+
}).filter((share) => share != null);
|
|
210
|
+
const aesKey = ShamirGF256.combine(aesKeyShares);
|
|
211
|
+
return AES256GCM.decrypt(aesKey, ciphertext.aesCiph);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
exports.Decryptor = Decryptor;
|
|
215
|
+
class WorkerTimedOut {
|
|
216
|
+
toDisplayString() {
|
|
217
|
+
return 'Timed out';
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
class WorkerRejected {
|
|
221
|
+
statusCode;
|
|
222
|
+
responseBody;
|
|
223
|
+
constructor(statusCode, responseBody) {
|
|
224
|
+
this.statusCode = statusCode;
|
|
225
|
+
this.responseBody = responseBody;
|
|
226
|
+
}
|
|
227
|
+
toDisplayString() {
|
|
228
|
+
return `Rejected: ${this.statusCode} ${this.responseBody}`;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
class CouldNotParseDecryptionKey {
|
|
232
|
+
originalHex;
|
|
233
|
+
constructor(originalHex) {
|
|
234
|
+
this.originalHex = originalHex;
|
|
235
|
+
}
|
|
236
|
+
toDisplayString() {
|
|
237
|
+
return `Could not parse decryption key: ${this.originalHex}`;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* A message from a user to a MPC worker to request a decryption key.
|
|
242
|
+
*/
|
|
243
|
+
class RequestForDecryptionKey {
|
|
244
|
+
decryptionContext;
|
|
245
|
+
userAddr;
|
|
246
|
+
publicKey;
|
|
247
|
+
signature;
|
|
248
|
+
constructor(decryptionContext, userAddr, publicKey, signature) {
|
|
249
|
+
this.decryptionContext = decryptionContext;
|
|
250
|
+
this.userAddr = userAddr;
|
|
251
|
+
this.publicKey = publicKey;
|
|
252
|
+
this.signature = signature;
|
|
253
|
+
}
|
|
254
|
+
static deserialize(deserializer) {
|
|
255
|
+
const decryptionContext = DecryptionContext.deserialize(deserializer);
|
|
256
|
+
const userAddr = deserializer.deserialize(ts_sdk_1.AccountAddress);
|
|
257
|
+
const publicKey = deserializer.deserialize(ts_sdk_1.Ed25519PublicKey);
|
|
258
|
+
const signature = deserializer.deserialize(ts_sdk_1.Ed25519Signature);
|
|
259
|
+
return new RequestForDecryptionKey(decryptionContext, userAddr, publicKey, signature);
|
|
260
|
+
}
|
|
261
|
+
static fromBytes(bytes) {
|
|
262
|
+
const deserializer = new ts_sdk_1.Deserializer(bytes);
|
|
263
|
+
const ret = RequestForDecryptionKey.deserialize(deserializer);
|
|
264
|
+
return ret;
|
|
265
|
+
}
|
|
266
|
+
static fromHex(hex) {
|
|
267
|
+
return RequestForDecryptionKey.fromBytes((0, utils_1.hexToBytes)(hex));
|
|
268
|
+
}
|
|
269
|
+
serialize(serializer) {
|
|
270
|
+
this.decryptionContext.serialize(serializer);
|
|
271
|
+
serializer.serialize(this.userAddr);
|
|
272
|
+
serializer.serialize(this.publicKey);
|
|
273
|
+
serializer.serialize(this.signature);
|
|
274
|
+
}
|
|
275
|
+
toBytes() {
|
|
276
|
+
const serializer = new ts_sdk_1.Serializer();
|
|
277
|
+
this.serialize(serializer);
|
|
278
|
+
return serializer.toUint8Array();
|
|
279
|
+
}
|
|
280
|
+
toHex() {
|
|
281
|
+
return (0, utils_1.bytesToHex)(this.toBytes());
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
exports.RequestForDecryptionKey = RequestForDecryptionKey;
|
|
285
|
+
//# sourceMappingURL=silent_setup_encryption.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"silent_setup_encryption.js","sourceRoot":"","sources":["../src/silent_setup_encryption.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAyH;AACzH,8DAAgD;AAChD,+CAAiC;AACjC,4DAA8C;AAC9C,2CAA6B;AAC7B,+CAA2C;AAC3C,+CAA6D;AAC7D,uDAAyC;AAEzC,MAAa,iBAAiB;IAC1B,OAAO,CAAmB;IAC1B,SAAS,CAAS;IAClB,UAAU,CAAiB;IAC3B,UAAU,CAAS;IAEnB,YAAY,EAAC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAiG;QACpJ,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IACjC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,QAAQ,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;IAC1F,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,KAAiB;QAC9B,MAAM,YAAY,GAAG,IAAI,qBAAY,CAAC,KAAK,CAAC,CAAC;QAC7C,MAAM,GAAG,GAAG,uBAAuB,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;QAC9D,OAAO,GAAG,CAAC;IACf,CAAC;IAED,MAAM,CAAC,OAAO,CAAC,GAAW;QACtB,OAAO,uBAAuB,CAAC,SAAS,CAAC,IAAA,kBAAU,EAAC,GAAG,CAAC,CAAC,CAAC;IAC9D,CAAC;IAED,SAAS,CAAC,UAAsB;QAC5B,IAAI,CAAC,iBAAiB,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QAC7C,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACpC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACrC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACzC,CAAC;IAED,OAAO;QACH,MAAM,UAAU,GAAG,IAAI,mBAAU,EAAE,CAAC;QACpC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QAC3B,OAAO,UAAU,CAAC,YAAY,EAAE,CAAC;IACrC,CAAC;IAED,KAAK;QACD,OAAO,IAAA,kBAAU,EAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;IACtC,CAAC;CACJ;AA/CD,0DA+CC"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const CONTRACT_ADDRESS_HEX: string;
|
|
2
|
+
export declare function randBytes(length: number): Uint8Array;
|
|
3
|
+
export declare function xorBytes(blinder: Uint8Array<ArrayBufferLike>, plaintext: Uint8Array<ArrayBufferLike>): Uint8Array;
|
|
4
|
+
export declare function concatBytes(a: Uint8Array, b: Uint8Array): Uint8Array;
|
|
5
|
+
export declare function kdf(seed: Uint8Array, dst: Uint8Array, targetLength: number): Uint8Array;
|
|
6
|
+
export declare function hmac_sha3_256(key: Uint8Array, message: Uint8Array): Uint8Array;
|
|
7
|
+
export declare function sha3_256(message: Uint8Array): Uint8Array;
|
|
8
|
+
export declare function sha3_512(message: Uint8Array): Uint8Array;
|
|
9
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,oBAAoB,EAAE,MAA6E,CAAC;AAGjH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAUpD;AAED,wBAAgB,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC,eAAe,CAAC,EAAE,SAAS,EAAE,UAAU,CAAC,eAAe,CAAC,GAAG,UAAU,CAKjH;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,UAAU,CAKpE;AA6BD,wBAAgB,GAAG,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,GAAG,UAAU,CAavF;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,GAAG,UAAU,CAc9E;AAED,wBAAgB,QAAQ,CAAC,OAAO,EAAE,UAAU,GAAG,UAAU,CAIxD;AAED,wBAAgB,QAAQ,CAAC,OAAO,EAAE,UAAU,GAAG,UAAU,CAIxD"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CONTRACT_ADDRESS_HEX = void 0;
|
|
4
|
+
exports.randBytes = randBytes;
|
|
5
|
+
exports.xorBytes = xorBytes;
|
|
6
|
+
exports.concatBytes = concatBytes;
|
|
7
|
+
exports.kdf = kdf;
|
|
8
|
+
exports.hmac_sha3_256 = hmac_sha3_256;
|
|
9
|
+
exports.sha3_256 = sha3_256;
|
|
10
|
+
exports.sha3_512 = sha3_512;
|
|
11
|
+
const ts_sdk_1 = require("@aptos-labs/ts-sdk");
|
|
12
|
+
const crypto_1 = require("crypto");
|
|
13
|
+
exports.CONTRACT_ADDRESS_HEX = "0x114f3ad54703b5afb48d596103253fdfeed121e131edb83a25dfed6cb92b73ed";
|
|
14
|
+
// Browser-compatible random bytes function (fallback)
|
|
15
|
+
function randBytes(length) {
|
|
16
|
+
if (typeof crypto !== 'undefined' && crypto.getRandomValues) {
|
|
17
|
+
return crypto.getRandomValues(new Uint8Array(length));
|
|
18
|
+
}
|
|
19
|
+
// Fallback for environments without crypto.getRandomValues
|
|
20
|
+
const bytes = new Uint8Array(length);
|
|
21
|
+
for (let i = 0; i < length; i++) {
|
|
22
|
+
bytes[i] = Math.floor(Math.random() * 256);
|
|
23
|
+
}
|
|
24
|
+
return bytes;
|
|
25
|
+
}
|
|
26
|
+
function xorBytes(blinder, plaintext) {
|
|
27
|
+
if (blinder.length != plaintext.length) {
|
|
28
|
+
throw new Error("Blinder and plaintext must be the same length");
|
|
29
|
+
}
|
|
30
|
+
return new Uint8Array(blinder.map((byte, index) => byte ^ plaintext[index]));
|
|
31
|
+
}
|
|
32
|
+
function concatBytes(a, b) {
|
|
33
|
+
const result = new Uint8Array(a.length + b.length);
|
|
34
|
+
result.set(a, 0);
|
|
35
|
+
result.set(b, a.length);
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
class KeyBlockDeriveInput {
|
|
39
|
+
seed;
|
|
40
|
+
dst;
|
|
41
|
+
targetLength;
|
|
42
|
+
blockIndex;
|
|
43
|
+
constructor(seed, dst, targetLength, blockIndex) {
|
|
44
|
+
this.seed = seed;
|
|
45
|
+
this.dst = dst;
|
|
46
|
+
this.targetLength = targetLength;
|
|
47
|
+
this.blockIndex = blockIndex;
|
|
48
|
+
}
|
|
49
|
+
serialize(serializer) {
|
|
50
|
+
serializer.serializeBytes(this.seed);
|
|
51
|
+
serializer.serializeBytes(this.dst);
|
|
52
|
+
serializer.serializeU64(this.targetLength);
|
|
53
|
+
serializer.serializeU64(this.blockIndex);
|
|
54
|
+
}
|
|
55
|
+
toBytes() {
|
|
56
|
+
const serializer = new ts_sdk_1.Serializer();
|
|
57
|
+
this.serialize(serializer);
|
|
58
|
+
return serializer.toUint8Array();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function kdf(seed, dst, targetLength) {
|
|
62
|
+
if (seed.length < 32) {
|
|
63
|
+
throw new Error("Seed must be at least 32 bytes");
|
|
64
|
+
}
|
|
65
|
+
let blockPreImage = new KeyBlockDeriveInput(seed, dst, targetLength, 0);
|
|
66
|
+
let output = new Uint8Array(0);
|
|
67
|
+
while (targetLength > 0) {
|
|
68
|
+
let blockOutput = new Uint8Array(sha3_256(blockPreImage.toBytes()).slice(0, Math.min(32, targetLength)));
|
|
69
|
+
output = concatBytes(output, blockOutput);
|
|
70
|
+
targetLength -= blockOutput.length;
|
|
71
|
+
blockPreImage.blockIndex++;
|
|
72
|
+
}
|
|
73
|
+
return output;
|
|
74
|
+
}
|
|
75
|
+
function hmac_sha3_256(key, message) {
|
|
76
|
+
if (key.length !== 32) {
|
|
77
|
+
throw new Error("Key must be 32 bytes");
|
|
78
|
+
}
|
|
79
|
+
key = concatBytes(key, new Uint8Array(32));
|
|
80
|
+
let ipad = new Uint8Array(64);
|
|
81
|
+
let opad = new Uint8Array(64);
|
|
82
|
+
for (let i = 0; i < 64; i++) {
|
|
83
|
+
ipad[i] = 0x36;
|
|
84
|
+
opad[i] = 0x5c;
|
|
85
|
+
}
|
|
86
|
+
const innerInput = concatBytes(xorBytes(ipad, key), message);
|
|
87
|
+
const outerInput = concatBytes(xorBytes(opad, key), sha3_256(innerInput));
|
|
88
|
+
return sha3_256(outerInput);
|
|
89
|
+
}
|
|
90
|
+
function sha3_256(message) {
|
|
91
|
+
const hash = (0, crypto_1.createHash)("sha3-256");
|
|
92
|
+
hash.update(message);
|
|
93
|
+
return new Uint8Array(hash.digest());
|
|
94
|
+
}
|
|
95
|
+
function sha3_512(message) {
|
|
96
|
+
const hash = (0, crypto_1.createHash)("sha3-512");
|
|
97
|
+
hash.update(message);
|
|
98
|
+
return new Uint8Array(hash.digest());
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAMA,8BAUC;AAED,4BAKC;AAED,kCAKC;AA6BD,kBAaC;AAED,sCAcC;AAED,4BAIC;AAED,4BAIC;AApGD,+CAAgD;AAChD,mCAAoC;AAEvB,QAAA,oBAAoB,GAAW,oEAAoE,CAAC;AAEjH,sDAAsD;AACtD,SAAgB,SAAS,CAAC,MAAc;IACpC,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,eAAe,EAAE,CAAC;QAC1D,OAAO,MAAM,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;IAC1D,CAAC;IACD,2DAA2D;IAC3D,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IACrC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC9B,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,SAAgB,QAAQ,CAAC,OAAoC,EAAE,SAAsC;IACjG,IAAI,OAAO,CAAC,MAAM,IAAI,SAAS,CAAC,MAAM,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;I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1B,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;QACf,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IACnB,CAAC;IACD,MAAM,UAAU,GAAG,WAAW,CAAC,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC;IAC7D,MAAM,UAAU,GAAG,WAAW,CAAC,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC;IAC1E,OAAO,QAAQ,CAAC,UAAU,CAAC,CAAC;AAChC,CAAC;AAED,SAAgB,QAAQ,CAAC,OAAmB;IACxC,MAAM,IAAI,GAAG,IAAA,mBAAU,EAAC,UAAU,CAAC,CAAC;IACpC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACrB,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,CAAe,CAAC;AACvD,CAAC;AAED,SAAgB,QAAQ,CAAC,OAAmB;IACxC,MAAM,IAAI,GAAG,IAAA,mBAAU,EAAC,UAAU,CAAC,CAAC;IACpC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACrB,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,CAAe,CAAC;AACvD,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AccountAddress, Aptos, Deserializer } from "@aptos-labs/ts-sdk";
|
|
2
|
+
import * as Enc from "./enc";
|
|
3
|
+
import * as Sig from "./sig";
|
|
4
|
+
import * as IBE from "./ibe";
|
|
5
|
+
export declare class WorkerConfig {
|
|
6
|
+
expiryTimeMicrosecs: number;
|
|
7
|
+
endpoint: string;
|
|
8
|
+
encEk: Enc.EncryptionKey;
|
|
9
|
+
sigVk: Sig.VerifyingKey;
|
|
10
|
+
ibeMpk: IBE.MasterPublicKey;
|
|
11
|
+
constructor(expiryTimeMicrosecs: number, endpoint: string, encEk: Enc.EncryptionKey, sigVk: Sig.VerifyingKey, ibeMpk: IBE.MasterPublicKey);
|
|
12
|
+
static deserialize(deserializer: Deserializer): WorkerConfig;
|
|
13
|
+
static fromBytes(bytes: Uint8Array): WorkerConfig;
|
|
14
|
+
static fromHex(hex: string): WorkerConfig;
|
|
15
|
+
}
|
|
16
|
+
export declare function view(aptos: Aptos, worker: AccountAddress): Promise<WorkerConfig>;
|
|
17
|
+
//# sourceMappingURL=worker_config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker_config.d.ts","sourceRoot":"","sources":["../src/worker_config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGzE,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAC7B,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAC7B,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAE7B,qBAAa,YAAY;IACrB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,GAAG,CAAC,aAAa,CAAC;IACzB,KAAK,EAAE,GAAG,CAAC,YAAY,CAAC;IACxB,MAAM,EAAE,GAAG,CAAC,eAAe,CAAC;gBAEhB,mBAAmB,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,CAAC,aAAa,EAAE,KAAK,EAAE,GAAG,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,CAAC,eAAe;IAQzI,MAAM,CAAC,WAAW,CAAC,YAAY,EAAE,YAAY,GAAG,YAAY;IAS5D,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,YAAY;IAKjD,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY;CAG5C;AAED,wBAAsB,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC,CAStF"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.WorkerConfig = void 0;
|
|
37
|
+
exports.view = view;
|
|
38
|
+
const ts_sdk_1 = require("@aptos-labs/ts-sdk");
|
|
39
|
+
const utils_1 = require("@noble/curves/utils");
|
|
40
|
+
const _1 = require(".");
|
|
41
|
+
const Enc = __importStar(require("./enc"));
|
|
42
|
+
const Sig = __importStar(require("./sig"));
|
|
43
|
+
const IBE = __importStar(require("./ibe"));
|
|
44
|
+
class WorkerConfig {
|
|
45
|
+
expiryTimeMicrosecs;
|
|
46
|
+
endpoint;
|
|
47
|
+
encEk;
|
|
48
|
+
sigVk;
|
|
49
|
+
ibeMpk;
|
|
50
|
+
constructor(expiryTimeMicrosecs, endpoint, encEk, sigVk, ibeMpk) {
|
|
51
|
+
this.expiryTimeMicrosecs = expiryTimeMicrosecs;
|
|
52
|
+
this.endpoint = endpoint;
|
|
53
|
+
this.encEk = encEk;
|
|
54
|
+
this.sigVk = sigVk;
|
|
55
|
+
this.ibeMpk = ibeMpk;
|
|
56
|
+
}
|
|
57
|
+
static deserialize(deserializer) {
|
|
58
|
+
const expiryTimeMicrosecs = Number(deserializer.deserializeU64());
|
|
59
|
+
const endpoint = deserializer.deserializeStr();
|
|
60
|
+
const encEk = Enc.EncryptionKey.deserialize(deserializer);
|
|
61
|
+
const sigVk = Sig.VerifyingKey.deserialize(deserializer);
|
|
62
|
+
const ibeMpk = IBE.MasterPublicKey.deserialize(deserializer);
|
|
63
|
+
return new WorkerConfig(expiryTimeMicrosecs, endpoint, encEk, sigVk, ibeMpk);
|
|
64
|
+
}
|
|
65
|
+
static fromBytes(bytes) {
|
|
66
|
+
const deserializer = new ts_sdk_1.Deserializer(bytes);
|
|
67
|
+
return WorkerConfig.deserialize(deserializer);
|
|
68
|
+
}
|
|
69
|
+
static fromHex(hex) {
|
|
70
|
+
return WorkerConfig.fromBytes((0, utils_1.hexToBytes)(hex));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.WorkerConfig = WorkerConfig;
|
|
74
|
+
async function view(aptos, worker) {
|
|
75
|
+
const configBcsMoveVals = await aptos.view({
|
|
76
|
+
payload: {
|
|
77
|
+
function: `${_1.Utils.CONTRACT_ADDRESS_HEX}::worker_config::get_bcs`,
|
|
78
|
+
typeArguments: [],
|
|
79
|
+
functionArguments: [worker]
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
return WorkerConfig.fromHex(configBcsMoveVals[0].toString().slice(2));
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=worker_config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker_config.js","sourceRoot":"","sources":["../src/worker_config.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,oBASC;AAlDD,+CAAyE;AACzE,+CAAiD;AACjD,wBAA0B;AAC1B,2CAA6B;AAC7B,2CAA6B;AAC7B,2CAA6B;AAE7B,MAAa,YAAY;IACrB,mBAAmB,CAAS;IAC5B,QAAQ,CAAS;IACjB,KAAK,CAAoB;IACzB,KAAK,CAAmB;IACxB,MAAM,CAAsB;IAE5B,YAAY,mBAA2B,EAAE,QAAgB,EAAE,KAAwB,EAAE,KAAuB,EAAE,MAA2B;QACrI,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAC;QAC/C,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,YAA0B;QACzC,MAAM,mBAAmB,GAAG,MAAM,CAAC,YAAY,CAAC,cAAc,EAAE,CAAC,CAAC;QAClE,MAAM,QAAQ,GAAG,YAAY,CAAC,cAAc,EAAE,CAAC;QAC/C,MAAM,KAAK,GAAG,GAAG,CAAC,aAAa,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;QAC1D,MAAM,KAAK,GAAG,GAAG,CAAC,YAAY,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;QACzD,MAAM,MAAM,GAAG,GAAG,CAAC,eAAe,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;QAC7D,OAAO,IAAI,YAAY,CAAC,mBAAmB,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;IACjF,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,KAAiB;QAC9B,MAAM,YAAY,GAAG,IAAI,qBAAY,CAAC,KAAK,CAAC,CAAC;QAC7C,OAAO,YAAY,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;IAClD,CAAC;IAED,MAAM,CAAC,OAAO,CAAC,GAAW;QACtB,OAAO,YAAY,CAAC,SAAS,CAAC,IAAA,kBAAU,EAAC,GAAG,CAAC,CAAC,CAAC;IACnD,CAAC;CACJ;AAhCD,oCAgCC;AAEM,KAAK,UAAU,IAAI,CAAC,KAAY,EAAE,MAAsB;IAC3D,MAAM,iBAAiB,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC;QACvC,OAAO,EAAE;YACL,QAAQ,EAAE,GAAG,QAAK,CAAC,oBAAoB,0BAA0B;YACjE,aAAa,EAAE,EAAE;YACjB,iBAAiB,EAAE,CAAC,MAAM,CAAC;SAC9B;KACJ,CAAC,CAAC;IACH,OAAO,YAAY,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3E,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AccountAddress, Deserializer, Ed25519PublicKey, Ed25519Signature, Serializer } from '@aptos-labs/ts-sdk';
|
|
2
|
+
import { SilentSetupEncryption } from '.';
|
|
3
|
+
export declare class WorkerTask {
|
|
4
|
+
taskType: number;
|
|
5
|
+
inner: SilentSetupEncryption.RequestForDecryptionKey;
|
|
6
|
+
constructor(taskType: number, inner: SilentSetupEncryption.RequestForDecryptionKey);
|
|
7
|
+
static newSilentSetupDecryptionKey(decryptionContext: SilentSetupEncryption.DecryptionContext, userAddr: AccountAddress, publicKey: Ed25519PublicKey, signature: Ed25519Signature): WorkerTask;
|
|
8
|
+
static decode(deserializer: Deserializer): WorkerTask;
|
|
9
|
+
static fromBytes(bytes: Uint8Array): WorkerTask;
|
|
10
|
+
static fromHex(hex: string): WorkerTask;
|
|
11
|
+
serialize(serializer: Serializer): void;
|
|
12
|
+
toBytes(): Uint8Array;
|
|
13
|
+
toHex(): string;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=worker_task.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker_task.d.ts","sourceRoot":"","sources":["../src/worker_task.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAElH,OAAO,EAAE,qBAAqB,EAAE,MAAM,GAAG,CAAC;AAQ1C,qBAAa,UAAU;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,qBAAqB,CAAC,uBAAuB,CAAC;gBAEzC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,qBAAqB,CAAC,uBAAuB;IAKlF,MAAM,CAAC,2BAA2B,CAAC,iBAAiB,EAAE,qBAAqB,CAAC,iBAAiB,EAAE,QAAQ,EAAE,cAAc,EAAE,SAAS,EAAE,gBAAgB,EAAE,SAAS,EAAE,gBAAgB,GAAG,UAAU;IAI9L,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,YAAY,GAAG,UAAU;IAWrD,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU;IAK/C,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU;IAIvC,SAAS,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI;IASvC,OAAO,IAAI,UAAU;IAMrB,KAAK,IAAI,MAAM;CAGlB"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WorkerTask = void 0;
|
|
4
|
+
const ts_sdk_1 = require("@aptos-labs/ts-sdk");
|
|
5
|
+
const utils_1 = require("@noble/curves/utils");
|
|
6
|
+
const _1 = require(".");
|
|
7
|
+
// const TYPE_DKG_V0 = 1;
|
|
8
|
+
// const TYPE_SHUFFLE = 2;
|
|
9
|
+
// const TYPE_SCALAR_MUL = 3;
|
|
10
|
+
// const TYPE_SCALAR_MUL_OFFCHAIN = 4;
|
|
11
|
+
const TYPE_SILENT_SETUP_DECRYPTION_KEY = 5;
|
|
12
|
+
class WorkerTask {
|
|
13
|
+
taskType;
|
|
14
|
+
inner;
|
|
15
|
+
constructor(taskType, inner) {
|
|
16
|
+
this.taskType = taskType;
|
|
17
|
+
this.inner = inner;
|
|
18
|
+
}
|
|
19
|
+
static newSilentSetupDecryptionKey(decryptionContext, userAddr, publicKey, signature) {
|
|
20
|
+
return new WorkerTask(TYPE_SILENT_SETUP_DECRYPTION_KEY, new _1.SilentSetupEncryption.RequestForDecryptionKey(decryptionContext, userAddr, publicKey, signature));
|
|
21
|
+
}
|
|
22
|
+
static decode(deserializer) {
|
|
23
|
+
const taskType = deserializer.deserializeU8();
|
|
24
|
+
let inner;
|
|
25
|
+
if (taskType === TYPE_SILENT_SETUP_DECRYPTION_KEY) {
|
|
26
|
+
inner = _1.SilentSetupEncryption.RequestForDecryptionKey.deserialize(deserializer);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
throw new Error(`Invalid task type: ${taskType}`);
|
|
30
|
+
}
|
|
31
|
+
return new WorkerTask(taskType, inner);
|
|
32
|
+
}
|
|
33
|
+
static fromBytes(bytes) {
|
|
34
|
+
const deserializer = new ts_sdk_1.Deserializer(bytes);
|
|
35
|
+
return WorkerTask.decode(deserializer);
|
|
36
|
+
}
|
|
37
|
+
static fromHex(hex) {
|
|
38
|
+
return WorkerTask.fromBytes((0, utils_1.hexToBytes)(hex));
|
|
39
|
+
}
|
|
40
|
+
serialize(serializer) {
|
|
41
|
+
serializer.serializeU8(this.taskType);
|
|
42
|
+
if (this.taskType === TYPE_SILENT_SETUP_DECRYPTION_KEY) {
|
|
43
|
+
this.inner.serialize(serializer);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
throw new Error(`Invalid task type: ${this.taskType}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
toBytes() {
|
|
50
|
+
const serializer = new ts_sdk_1.Serializer();
|
|
51
|
+
this.serialize(serializer);
|
|
52
|
+
return serializer.toUint8Array();
|
|
53
|
+
}
|
|
54
|
+
toHex() {
|
|
55
|
+
return (0, utils_1.bytesToHex)(this.toBytes());
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.WorkerTask = WorkerTask;
|
|
59
|
+
//# sourceMappingURL=worker_task.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker_task.js","sourceRoot":"","sources":["../src/worker_task.ts"],"names":[],"mappings":";;;AAAA,+CAAkH;AAClH,+CAA6D;AAC7D,wBAA0C;AAE1C,yBAAyB;AACzB,0BAA0B;AAC1B,6BAA6B;AAC7B,sCAAsC;AACtC,MAAM,gCAAgC,GAAG,CAAC,CAAC;AAE3C,MAAa,UAAU;IACnB,QAAQ,CAAS;IACjB,KAAK,CAAgD;IAErD,YAAY,QAAgB,EAAE,KAAoD;QAC9E,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;IAED,MAAM,CAAC,2BAA2B,CAAC,iBAA0D,EAAE,QAAwB,EAAE,SAA2B,EAAE,SAA2B;QAC7K,OAAO,IAAI,UAAU,CAAC,gCAAgC,EAAE,IAAI,wBAAqB,CAAC,uBAAuB,CAAC,iBAAiB,EAAE,QAA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,EAAE,CAAC;IACrC,CAAC;IAED,KAAK;QACD,OAAO,IAAA,kBAAU,EAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;IACtC,CAAC;CACJ;AAnDD,gCAmDC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zhoujun_aptos/octopus-ts-sdk-min",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "octopus-ts-sdk-min",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"dev": "tsc --watch",
|
|
10
|
+
"clean": "rm -rf dist",
|
|
11
|
+
"prepublishOnly": "npm run clean && npm run build",
|
|
12
|
+
"test": "vitest",
|
|
13
|
+
"test:run": "vitest run",
|
|
14
|
+
"test:coverage": "vitest run --coverage"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"octopus"
|
|
18
|
+
],
|
|
19
|
+
"author": "zhoujun_aptos",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@aptos-labs/ts-sdk": "^3.1.3",
|
|
23
|
+
"@noble/ciphers": "^1.3.0",
|
|
24
|
+
"@noble/curves": "^1.3.0",
|
|
25
|
+
"@noble/hashes": "^1.4.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/node": "^20.10.0",
|
|
29
|
+
"typescript": "^5.8.3",
|
|
30
|
+
"vitest": "^1.0.0"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist/**/*"
|
|
34
|
+
]
|
|
35
|
+
}
|