@avaprotocol/sdk-js 0.6.4 → 0.6.6
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/.env.example +7 -0
- package/dist/index.cjs +67 -90
- package/dist/index.d.cts +524 -89
- package/dist/index.d.ts +524 -89
- package/dist/index.js +71 -88
- package/grpc_codegen/avs.proto +297 -0
- package/grpc_codegen/avs.ts +3720 -0
- package/grpc_codegen/avs_grpc_pb.d.ts +665 -0
- package/grpc_codegen/avs_grpc_pb.js +349 -0
- package/grpc_codegen/avs_pb.d.ts +958 -0
- package/grpc_codegen/avs_pb.js +7545 -0
- package/jest.config.cjs +21 -0
- package/package.json +5 -8
- package/scripts/signMessage.js +27 -0
- package/src/__tests__/Client.e2e.test.ts +172 -0
- package/src/auth.js +7 -0
- package/src/auth.ts +3 -0
- package/src/config.js +22 -0
- package/src/config.ts +27 -0
- package/src/index.ts +131 -0
- package/src/rpc-client.ts +7 -0
- package/src/types.js +2 -0
- package/src/types.ts +47 -0
- package/tsconfig.json +20 -0
package/.env.example
ADDED
package/dist/index.cjs
CHANGED
|
@@ -32,7 +32,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
32
32
|
|
|
33
33
|
// grpc_codegen/avs_pb.js
|
|
34
34
|
var avs_pb_exports = {};
|
|
35
|
-
|
|
35
|
+
__export(avs_pb_exports, {
|
|
36
|
+
CreateTaskReq: () => CreateTaskReq,
|
|
37
|
+
CreateTaskResp: () => CreateTaskResp,
|
|
38
|
+
GetKeyReq: () => GetKeyReq,
|
|
39
|
+
KeyResp: () => KeyResp,
|
|
40
|
+
Task: () => Task,
|
|
41
|
+
UpdateChecksReq: () => UpdateChecksReq,
|
|
42
|
+
UpdateChecksResp: () => UpdateChecksResp
|
|
43
|
+
});
|
|
44
|
+
var jspb, goog, global, google_protobuf_timestamp_pb, google_protobuf_wrappers_pb, Task, CreateTaskReq, CreateTaskResp, GetKeyReq, KeyResp, UpdateChecksReq, UpdateChecksResp;
|
|
36
45
|
var init_avs_pb = __esm({
|
|
37
46
|
"grpc_codegen/avs_pb.js"() {
|
|
38
47
|
"use strict";
|
|
@@ -4093,19 +4102,35 @@ var init_avs_pb = __esm({
|
|
|
4093
4102
|
JAVASCRIPT: 0
|
|
4094
4103
|
};
|
|
4095
4104
|
goog.object.extend(exports, proto.aggregator);
|
|
4105
|
+
({ Task, CreateTaskReq, CreateTaskResp, GetKeyReq, KeyResp, UpdateChecksReq, UpdateChecksResp } = proto.aggregator);
|
|
4096
4106
|
}
|
|
4097
4107
|
});
|
|
4098
4108
|
|
|
4099
4109
|
// src/index.ts
|
|
4100
4110
|
var src_exports = {};
|
|
4101
4111
|
__export(src_exports, {
|
|
4102
|
-
|
|
4103
|
-
Client: () => Client,
|
|
4112
|
+
default: () => Client,
|
|
4104
4113
|
getKeyRequestMessage: () => getKeyRequestMessage
|
|
4105
4114
|
});
|
|
4106
4115
|
module.exports = __toCommonJS(src_exports);
|
|
4107
4116
|
var grpc2 = __toESM(require("@grpc/grpc-js"), 1);
|
|
4108
|
-
|
|
4117
|
+
|
|
4118
|
+
// src/config.ts
|
|
4119
|
+
var DEFAULT_JWT_EXPIRATION = 24 * 60 * 60;
|
|
4120
|
+
var configs = {
|
|
4121
|
+
development: {
|
|
4122
|
+
AVS_RPC_URL: process.env.AVS_RPC_URL || "localhost:2206"
|
|
4123
|
+
},
|
|
4124
|
+
staging: {
|
|
4125
|
+
AVS_RPC_URL: "aggregator-holesky.avaprotocol.org:2206"
|
|
4126
|
+
},
|
|
4127
|
+
production: {
|
|
4128
|
+
AVS_RPC_URL: "aggregator.avaprotocol.org:2206"
|
|
4129
|
+
}
|
|
4130
|
+
};
|
|
4131
|
+
function getRpcEndpoint(env) {
|
|
4132
|
+
return configs[env].AVS_RPC_URL;
|
|
4133
|
+
}
|
|
4109
4134
|
|
|
4110
4135
|
// src/auth.ts
|
|
4111
4136
|
var getKeyRequestMessage = (address, expiredAt) => {
|
|
@@ -4288,7 +4313,7 @@ function serialize_google_protobuf_BoolValue(arg) {
|
|
|
4288
4313
|
function deserialize_google_protobuf_BoolValue(buffer_arg) {
|
|
4289
4314
|
return google_protobuf_wrappers_pb2.BoolValue.deserializeBinary(new Uint8Array(buffer_arg));
|
|
4290
4315
|
}
|
|
4291
|
-
var AggregatorService =
|
|
4316
|
+
var AggregatorService = {
|
|
4292
4317
|
// Auth
|
|
4293
4318
|
getKey: {
|
|
4294
4319
|
path: "/aggregator.Aggregator/GetKey",
|
|
@@ -4415,20 +4440,20 @@ var AggregatorService = exports.AggregatorService = {
|
|
|
4415
4440
|
responseDeserialize: deserialize_aggregator_UpdateChecksResp
|
|
4416
4441
|
}
|
|
4417
4442
|
};
|
|
4418
|
-
|
|
4443
|
+
var AggregatorClient = grpc.makeGenericClientConstructor(AggregatorService);
|
|
4419
4444
|
|
|
4420
4445
|
// src/index.ts
|
|
4421
4446
|
init_avs_pb();
|
|
4422
|
-
var
|
|
4447
|
+
var metadata = new grpc2.Metadata();
|
|
4423
4448
|
var BaseClient = class {
|
|
4424
|
-
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
|
-
config.endpoint,
|
|
4449
|
+
constructor(opts) {
|
|
4450
|
+
this.env = opts.env || "production";
|
|
4451
|
+
this.rpcClient = new AggregatorClient(
|
|
4452
|
+
getRpcEndpoint(this.env),
|
|
4453
|
+
// TODO: switch to the TLS after we're able to update all the operator
|
|
4430
4454
|
grpc2.credentials.createInsecure()
|
|
4431
4455
|
);
|
|
4456
|
+
console.log("this.rpcClient:", this.rpcClient);
|
|
4432
4457
|
}
|
|
4433
4458
|
// async authWithJwtToken(
|
|
4434
4459
|
// address: string,
|
|
@@ -4436,21 +4461,21 @@ var BaseClient = class {
|
|
|
4436
4461
|
// expiredAt?: number
|
|
4437
4462
|
// ): Promise<KeyExchangeResp> {
|
|
4438
4463
|
// console.log("Authenticating with JWT token: ", jwtToken);
|
|
4464
|
+
// // Use the provided expiredAt or set it to 24 hours from now if not provided
|
|
4439
4465
|
// const expirationTime =
|
|
4440
4466
|
// expiredAt || Math.floor(Date.now() / 1000) + DEFAULT_JWT_EXPIRATION;
|
|
4441
|
-
// const
|
|
4442
|
-
//
|
|
4443
|
-
//
|
|
4444
|
-
//
|
|
4445
|
-
//
|
|
4446
|
-
//
|
|
4447
|
-
//
|
|
4448
|
-
//
|
|
4449
|
-
//
|
|
4450
|
-
//
|
|
4451
|
-
// console.log("response:", response.getKey());
|
|
4452
|
-
// return { key: response.getKey() };
|
|
4467
|
+
// const result: avsPb.KeyResp = await this._callRPC<
|
|
4468
|
+
// avsPb.KeyResp,
|
|
4469
|
+
// avsPb.GetKeyReq
|
|
4470
|
+
// >("getKey", {
|
|
4471
|
+
// owner: address,
|
|
4472
|
+
// expired_at: expirationTime,
|
|
4473
|
+
// signature: jwtToken,
|
|
4474
|
+
// });
|
|
4475
|
+
// this.authkey = result.getKey();
|
|
4476
|
+
// return { key: result.getKey() };
|
|
4453
4477
|
// }
|
|
4478
|
+
// This flow can be used where the signature is generate from outside, such as in front-end and pass in
|
|
4454
4479
|
async authWithSignature(address, signature, expiredAtEpoch) {
|
|
4455
4480
|
console.log(
|
|
4456
4481
|
"Authenticating with signature:",
|
|
@@ -4458,52 +4483,29 @@ var BaseClient = class {
|
|
|
4458
4483
|
"Expired at epoch:",
|
|
4459
4484
|
expiredAtEpoch
|
|
4460
4485
|
);
|
|
4461
|
-
const request = new (
|
|
4462
|
-
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
|
|
4486
|
+
const request = new GetKeyReq();
|
|
4487
|
+
request.setOwner(address);
|
|
4488
|
+
request.setExpiredAt(expiredAtEpoch);
|
|
4489
|
+
request.setSignature(signature);
|
|
4490
|
+
let result = await this._callRPC(
|
|
4491
|
+
"getKey",
|
|
4492
|
+
request
|
|
4493
|
+
);
|
|
4494
|
+
console.log("result:", result);
|
|
4495
|
+
this.authkey = result.getKey();
|
|
4496
|
+
return { key: result.getKey() };
|
|
4466
4497
|
}
|
|
4467
|
-
// protected async sendRequest<TResponse, TRequest extends object = {}>(
|
|
4468
|
-
// method: string,
|
|
4469
|
-
// request: TRequest = {} as TRequest,
|
|
4470
|
-
// metadata?: Metadata
|
|
4471
|
-
// ): Promise<TResponse> {
|
|
4472
|
-
// if (metadata === undefined) {
|
|
4473
|
-
// metadata = new grpc.Metadata();
|
|
4474
|
-
// }
|
|
4475
|
-
// if (!this.adminToken) {
|
|
4476
|
-
// throw new Error(
|
|
4477
|
-
// "Authentication required. Please call authWithJwtToken() or authWithSignature() before making requests."
|
|
4478
|
-
// );
|
|
4479
|
-
// }
|
|
4480
|
-
// metadata.add("adminToken", this.adminToken);
|
|
4481
|
-
// return this._callRPC<TResponse, TRequest>(
|
|
4482
|
-
// method as (
|
|
4483
|
-
// request: TRequest,
|
|
4484
|
-
// metadata: grpc.Metadata | undefined,
|
|
4485
|
-
// callback: (error: grpc.ServiceError | null, response: TResponse) => void
|
|
4486
|
-
// ),
|
|
4487
|
-
// request,
|
|
4488
|
-
// metadata
|
|
4489
|
-
// );
|
|
4490
|
-
// }
|
|
4491
4498
|
isAuthenticated() {
|
|
4492
|
-
return !!this.
|
|
4499
|
+
return !!this.authkey;
|
|
4493
4500
|
}
|
|
4494
|
-
_callRPC(
|
|
4501
|
+
_callRPC(method, request) {
|
|
4495
4502
|
return new Promise((resolve, reject) => {
|
|
4496
|
-
|
|
4497
|
-
method.call(
|
|
4498
|
-
this.rpcClient,
|
|
4503
|
+
this.rpcClient[method].bind(this.rpcClient)(
|
|
4499
4504
|
request,
|
|
4500
|
-
|
|
4505
|
+
metadata,
|
|
4501
4506
|
(error, response) => {
|
|
4502
|
-
if (error)
|
|
4503
|
-
|
|
4504
|
-
} else {
|
|
4505
|
-
resolve(response);
|
|
4506
|
-
}
|
|
4507
|
+
if (error) reject(error);
|
|
4508
|
+
else resolve(response);
|
|
4507
4509
|
}
|
|
4508
4510
|
);
|
|
4509
4511
|
});
|
|
@@ -4513,33 +4515,8 @@ var Client = class extends BaseClient {
|
|
|
4513
4515
|
constructor(config) {
|
|
4514
4516
|
super(config);
|
|
4515
4517
|
}
|
|
4516
|
-
async listTask() {
|
|
4517
|
-
console.log("Listing tasks");
|
|
4518
|
-
const request = new (void 0)();
|
|
4519
|
-
const response = await this._callRPC(
|
|
4520
|
-
"listTasks",
|
|
4521
|
-
request
|
|
4522
|
-
);
|
|
4523
|
-
console.log("response:", response);
|
|
4524
|
-
return response;
|
|
4525
|
-
}
|
|
4526
|
-
async getSmartWalletAddress(address) {
|
|
4527
|
-
const request = new (void 0)().setOwner(address);
|
|
4528
|
-
const response = await this._callRPC(
|
|
4529
|
-
"getSmartAccountAddress",
|
|
4530
|
-
request
|
|
4531
|
-
);
|
|
4532
|
-
return response;
|
|
4533
|
-
}
|
|
4534
|
-
async getTask(taskId) {
|
|
4535
|
-
const request = new (void 0)().setBytes(taskId);
|
|
4536
|
-
const response = await this._callRPC("getTask", request);
|
|
4537
|
-
return response;
|
|
4538
|
-
}
|
|
4539
4518
|
};
|
|
4540
4519
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4541
4520
|
0 && (module.exports = {
|
|
4542
|
-
BaseClient,
|
|
4543
|
-
Client,
|
|
4544
4521
|
getKeyRequestMessage
|
|
4545
4522
|
});
|