@avaprotocol/sdk-js 0.6.12 → 0.7.2
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 +55 -0
- package/dist/index.d.mts +12 -6
- package/dist/index.d.ts +12 -6
- package/dist/index.js +24 -48
- package/dist/index.mjs +25 -50
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -81,6 +81,61 @@ To ensure the SDK is functioning correctly, we have a comprehensive test suite.
|
|
|
81
81
|
|
|
82
82
|
This will execute all unit and integration tests. Make sure all tests pass before submitting a pull request or deploying changes.
|
|
83
83
|
|
|
84
|
+
## Version Management
|
|
85
|
+
|
|
86
|
+
This project uses [Changesets](https://github.com/changesets/changesets) to manage versions and changelogs. To contribute changes:
|
|
87
|
+
|
|
88
|
+
1. Make your changes to the codebase.
|
|
89
|
+
2. Run `npm run changeset` to create a new changeset.
|
|
90
|
+
3. Follow the prompts to describe your changes.
|
|
91
|
+
4. Commit the generated changeset file along with your changes.
|
|
92
|
+
|
|
93
|
+
To release a new version:
|
|
94
|
+
|
|
95
|
+
1. Run `npm run version` to update package versions and changelogs.
|
|
96
|
+
2. Review and commit the changes.
|
|
97
|
+
3. Run `npm run release` to publish the new version to npm.
|
|
98
|
+
|
|
99
|
+
For more detailed information on using Changesets, refer to the [Changesets documentation](https://github.com/changesets/changesets/blob/main/docs/intro-to-using-changesets.md).
|
|
100
|
+
|
|
101
|
+
## Release Process
|
|
102
|
+
|
|
103
|
+
This repository uses a two-step workflow process for creating new releases:
|
|
104
|
+
|
|
105
|
+
1. **Record changeset workflow**
|
|
106
|
+
|
|
107
|
+
- Go to the "Actions" tab in GitHub, and run the "Record Changeset" workflow
|
|
108
|
+
- Select the version bump type:
|
|
109
|
+
- `patch` for backwards-compatible bug fixes (0.0.x)
|
|
110
|
+
- `minor` for backwards-compatible features (0.x.0)
|
|
111
|
+
- `major` for breaking changes (x.0.0)
|
|
112
|
+
- Examine the Pull Request created by the workflow, and merge it if everything looks correct. This will record any commits before it as a major, minor, or patch.
|
|
113
|
+
|
|
114
|
+
2. **Create release workflow**
|
|
115
|
+
- Go to the "Actions" tab in GitHub and run the "Create Release" workflow. This will run `npx changeset version` to bump up version in `package.json` based on the recorded changeset files. It will also create a new GitHub Release if the new version is higher than the current version in `package.json`.
|
|
116
|
+
3. **Publish to NPM**
|
|
117
|
+
- After the last step, the version number in `package.json` is updated and a git tag with the new version number is created. Now you can publish the production version to NPM using `npm publish`.
|
|
118
|
+
|
|
119
|
+
### NPM Publishing Dev Versions
|
|
120
|
+
|
|
121
|
+
The NPM publishing of dev versions can be handled manually, since the test cases reference the dist folder and don’t require a new version on NPM. NPM publish on dev tag is only required for testing the new version in a web app.
|
|
122
|
+
|
|
123
|
+
1. Publish a dev version and test it in your local environment:
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
# Update version with dev tag in package.json
|
|
127
|
+
npm version prerelease --preid=dev
|
|
128
|
+
|
|
129
|
+
# Publish to npm with dev tag
|
|
130
|
+
npm publish --tag dev
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
2. Once tested, and a release is created using GitHub Actions, publish the production version to NPM:
|
|
134
|
+
```bash
|
|
135
|
+
# Publish to npm with latest tag
|
|
136
|
+
npm publish
|
|
137
|
+
```
|
|
138
|
+
|
|
84
139
|
### Utility Scripts
|
|
85
140
|
|
|
86
141
|
To generate the key request message for signing, you can run the following command:
|
package/dist/index.d.mts
CHANGED
|
@@ -1457,8 +1457,12 @@ declare class AggregatorClient extends grpc.Client implements IAggregatorClient
|
|
|
1457
1457
|
}
|
|
1458
1458
|
|
|
1459
1459
|
type Environment = "production" | "development" | "staging";
|
|
1460
|
+
declare const AUTH_KEY_HEADER = "authKey";
|
|
1461
|
+
interface RequestOptions {
|
|
1462
|
+
authKey: string;
|
|
1463
|
+
}
|
|
1460
1464
|
interface GetKeyResponse {
|
|
1461
|
-
|
|
1465
|
+
authKey: string;
|
|
1462
1466
|
}
|
|
1463
1467
|
interface ClientOption {
|
|
1464
1468
|
endpoint: string;
|
|
@@ -1492,14 +1496,16 @@ declare class BaseClient {
|
|
|
1492
1496
|
readonly rpcClient: AggregatorClient;
|
|
1493
1497
|
protected metadata: Metadata;
|
|
1494
1498
|
constructor(opts: ClientOption);
|
|
1495
|
-
|
|
1496
|
-
|
|
1499
|
+
isAuthKeyValid(key: string): boolean;
|
|
1500
|
+
authWithAPIKey(apiKey: string, expiredAtEpoch: number): Promise<GetKeyResponse>;
|
|
1497
1501
|
authWithSignature(address: string, signature: string, expiredAtEpoch: number): Promise<GetKeyResponse>;
|
|
1498
|
-
protected _callRPC<TResponse, TRequest>(method: string, request: TRequest | any): Promise<TResponse>;
|
|
1502
|
+
protected _callRPC<TResponse, TRequest>(method: string, request: TRequest | any, options?: RequestOptions): Promise<TResponse>;
|
|
1499
1503
|
}
|
|
1500
1504
|
declare class Client extends BaseClient {
|
|
1501
1505
|
constructor(config: ClientOption);
|
|
1502
|
-
getAddresses(address: string
|
|
1506
|
+
getAddresses(address: string, { authKey }: {
|
|
1507
|
+
authKey: string;
|
|
1508
|
+
}): Promise<GetAddressesResponse>;
|
|
1503
1509
|
createTask({ address, oracleContract, tokenContract, }: {
|
|
1504
1510
|
address: string;
|
|
1505
1511
|
tokenContract: string;
|
|
@@ -1511,4 +1517,4 @@ declare class Client extends BaseClient {
|
|
|
1511
1517
|
deleteTask(id: string): Promise<boolean>;
|
|
1512
1518
|
}
|
|
1513
1519
|
|
|
1514
|
-
export { type BalanceResp, type ClientOption, type CreateTaskResponse, type Environment, type GetAddressesResponse, type GetKeyResponse, type ListTasksResponse, type Task, type TransactionResp, Client as default, getKeyRequestMessage };
|
|
1520
|
+
export { AUTH_KEY_HEADER, type BalanceResp, type ClientOption, type CreateTaskResponse, type Environment, type GetAddressesResponse, type GetKeyResponse, type ListTasksResponse, type RequestOptions, type Task, type TransactionResp, Client as default, getKeyRequestMessage };
|
package/dist/index.d.ts
CHANGED
|
@@ -1457,8 +1457,12 @@ declare class AggregatorClient extends grpc.Client implements IAggregatorClient
|
|
|
1457
1457
|
}
|
|
1458
1458
|
|
|
1459
1459
|
type Environment = "production" | "development" | "staging";
|
|
1460
|
+
declare const AUTH_KEY_HEADER = "authKey";
|
|
1461
|
+
interface RequestOptions {
|
|
1462
|
+
authKey: string;
|
|
1463
|
+
}
|
|
1460
1464
|
interface GetKeyResponse {
|
|
1461
|
-
|
|
1465
|
+
authKey: string;
|
|
1462
1466
|
}
|
|
1463
1467
|
interface ClientOption {
|
|
1464
1468
|
endpoint: string;
|
|
@@ -1492,14 +1496,16 @@ declare class BaseClient {
|
|
|
1492
1496
|
readonly rpcClient: AggregatorClient;
|
|
1493
1497
|
protected metadata: Metadata;
|
|
1494
1498
|
constructor(opts: ClientOption);
|
|
1495
|
-
|
|
1496
|
-
|
|
1499
|
+
isAuthKeyValid(key: string): boolean;
|
|
1500
|
+
authWithAPIKey(apiKey: string, expiredAtEpoch: number): Promise<GetKeyResponse>;
|
|
1497
1501
|
authWithSignature(address: string, signature: string, expiredAtEpoch: number): Promise<GetKeyResponse>;
|
|
1498
|
-
protected _callRPC<TResponse, TRequest>(method: string, request: TRequest | any): Promise<TResponse>;
|
|
1502
|
+
protected _callRPC<TResponse, TRequest>(method: string, request: TRequest | any, options?: RequestOptions): Promise<TResponse>;
|
|
1499
1503
|
}
|
|
1500
1504
|
declare class Client extends BaseClient {
|
|
1501
1505
|
constructor(config: ClientOption);
|
|
1502
|
-
getAddresses(address: string
|
|
1506
|
+
getAddresses(address: string, { authKey }: {
|
|
1507
|
+
authKey: string;
|
|
1508
|
+
}): Promise<GetAddressesResponse>;
|
|
1503
1509
|
createTask({ address, oracleContract, tokenContract, }: {
|
|
1504
1510
|
address: string;
|
|
1505
1511
|
tokenContract: string;
|
|
@@ -1511,4 +1517,4 @@ declare class Client extends BaseClient {
|
|
|
1511
1517
|
deleteTask(id: string): Promise<boolean>;
|
|
1512
1518
|
}
|
|
1513
1519
|
|
|
1514
|
-
export { type BalanceResp, type ClientOption, type CreateTaskResponse, type Environment, type GetAddressesResponse, type GetKeyResponse, type ListTasksResponse, type Task, type TransactionResp, Client as default, getKeyRequestMessage };
|
|
1520
|
+
export { AUTH_KEY_HEADER, type BalanceResp, type ClientOption, type CreateTaskResponse, type Environment, type GetAddressesResponse, type GetKeyResponse, type ListTasksResponse, type RequestOptions, type Task, type TransactionResp, Client as default, getKeyRequestMessage };
|
package/dist/index.js
CHANGED
|
@@ -4182,6 +4182,7 @@ var init_avs_pb = __esm({
|
|
|
4182
4182
|
// src/index.ts
|
|
4183
4183
|
var src_exports = {};
|
|
4184
4184
|
__export(src_exports, {
|
|
4185
|
+
AUTH_KEY_HEADER: () => AUTH_KEY_HEADER,
|
|
4185
4186
|
default: () => Client,
|
|
4186
4187
|
getKeyRequestMessage: () => getKeyRequestMessage
|
|
4187
4188
|
});
|
|
@@ -4511,13 +4512,14 @@ var Task2 = class {
|
|
|
4511
4512
|
constructor(task) {
|
|
4512
4513
|
this.id = task.getId();
|
|
4513
4514
|
this.status = task.getStatus().toString();
|
|
4514
|
-
console.log("task.constructor:", task.toObject());
|
|
4515
4515
|
}
|
|
4516
4516
|
};
|
|
4517
4517
|
var task_default = Task2;
|
|
4518
4518
|
|
|
4519
|
+
// src/types.ts
|
|
4520
|
+
var AUTH_KEY_HEADER = "authKey";
|
|
4521
|
+
|
|
4519
4522
|
// src/index.ts
|
|
4520
|
-
var metadata = new grpc2.Metadata();
|
|
4521
4523
|
var BaseClient = class {
|
|
4522
4524
|
constructor(opts) {
|
|
4523
4525
|
this.endpoint = opts.endpoint;
|
|
@@ -4527,51 +4529,27 @@ var BaseClient = class {
|
|
|
4527
4529
|
);
|
|
4528
4530
|
this.metadata = new import_grpc_js.Metadata();
|
|
4529
4531
|
}
|
|
4530
|
-
|
|
4531
|
-
metadata.add("authkey", jwtToken);
|
|
4532
|
-
}
|
|
4533
|
-
isAuthenticated() {
|
|
4534
|
-
if (!metadata.get("authkey")) {
|
|
4535
|
-
return false;
|
|
4536
|
-
}
|
|
4532
|
+
isAuthKeyValid(key) {
|
|
4537
4533
|
try {
|
|
4538
|
-
const [, payload] =
|
|
4534
|
+
const [, payload] = key.split(".");
|
|
4539
4535
|
const decodedPayload = JSON.parse(atob(payload));
|
|
4540
4536
|
const currentTimestamp = Math.floor(Date.now() / 1e3);
|
|
4541
4537
|
return decodedPayload.exp > currentTimestamp;
|
|
4542
4538
|
} catch (error) {
|
|
4543
|
-
console.error("Error validating
|
|
4539
|
+
console.error("Error validating auth key:", error);
|
|
4544
4540
|
return false;
|
|
4545
4541
|
}
|
|
4546
4542
|
}
|
|
4547
|
-
|
|
4548
|
-
|
|
4549
|
-
|
|
4550
|
-
|
|
4551
|
-
|
|
4552
|
-
|
|
4553
|
-
|
|
4554
|
-
|
|
4555
|
-
// expiredAt || Math.floor(Date.now() / 1000) + DEFAULT_JWT_EXPIRATION;
|
|
4556
|
-
// const result: avsPb.KeyResp = await this._callRPC<
|
|
4557
|
-
// avsPb.KeyResp,
|
|
4558
|
-
// avsPb.GetKeyReq
|
|
4559
|
-
// >("getKey", {
|
|
4560
|
-
// owner: address,
|
|
4561
|
-
// expired_at: expirationTime,
|
|
4562
|
-
// signature: jwtToken,
|
|
4563
|
-
// });
|
|
4564
|
-
// this.jwtToken = result.getKey();
|
|
4565
|
-
// return { key: result.getKey() };
|
|
4566
|
-
// }
|
|
4543
|
+
async authWithAPIKey(apiKey, expiredAtEpoch) {
|
|
4544
|
+
const request = new GetKeyReq();
|
|
4545
|
+
request.setOwner("");
|
|
4546
|
+
request.setExpiredAt(expiredAtEpoch);
|
|
4547
|
+
request.setSignature(apiKey);
|
|
4548
|
+
const result = await this._callRPC("getKey", request);
|
|
4549
|
+
return { authKey: result.getKey() };
|
|
4550
|
+
}
|
|
4567
4551
|
// This flow can be used where the signature is generate from outside, such as in front-end and pass in
|
|
4568
4552
|
async authWithSignature(address, signature, expiredAtEpoch) {
|
|
4569
|
-
console.log(
|
|
4570
|
-
"Authenticating with signature:",
|
|
4571
|
-
signature,
|
|
4572
|
-
"Expired at epoch:",
|
|
4573
|
-
expiredAtEpoch
|
|
4574
|
-
);
|
|
4575
4553
|
const request = new GetKeyReq();
|
|
4576
4554
|
request.setOwner(address);
|
|
4577
4555
|
request.setExpiredAt(expiredAtEpoch);
|
|
@@ -4580,10 +4558,13 @@ var BaseClient = class {
|
|
|
4580
4558
|
"getKey",
|
|
4581
4559
|
request
|
|
4582
4560
|
);
|
|
4583
|
-
|
|
4584
|
-
return { jwtToken: result.getKey() };
|
|
4561
|
+
return { authKey: result.getKey() };
|
|
4585
4562
|
}
|
|
4586
|
-
_callRPC(method, request) {
|
|
4563
|
+
_callRPC(method, request, options) {
|
|
4564
|
+
const metadata = import_lodash.default.cloneDeep(this.metadata);
|
|
4565
|
+
if (options?.authKey) {
|
|
4566
|
+
metadata.set(AUTH_KEY_HEADER, options.authKey);
|
|
4567
|
+
}
|
|
4587
4568
|
return new Promise((resolve, reject) => {
|
|
4588
4569
|
this.rpcClient[method].bind(this.rpcClient)(
|
|
4589
4570
|
request,
|
|
@@ -4600,11 +4581,10 @@ var Client = class extends BaseClient {
|
|
|
4600
4581
|
constructor(config) {
|
|
4601
4582
|
super(config);
|
|
4602
4583
|
}
|
|
4603
|
-
async getAddresses(address) {
|
|
4584
|
+
async getAddresses(address, { authKey }) {
|
|
4604
4585
|
const request = new AddressRequest();
|
|
4605
4586
|
request.setOwner(address);
|
|
4606
|
-
const result = await this._callRPC("getSmartAccountAddress", request);
|
|
4607
|
-
console.log("getAddresses.result:", result);
|
|
4587
|
+
const result = await this._callRPC("getSmartAccountAddress", request, { authKey });
|
|
4608
4588
|
return {
|
|
4609
4589
|
owner: address,
|
|
4610
4590
|
smart_account_address: result.getSmartAccountAddress()
|
|
@@ -4637,11 +4617,9 @@ var Client = class extends BaseClient {
|
|
|
4637
4617
|
import_ethers.ethers.parseUnits("12", 18)
|
|
4638
4618
|
]);
|
|
4639
4619
|
execution.setCallData(callData);
|
|
4640
|
-
console.log("execution:", execution.toObject());
|
|
4641
4620
|
action.setContractExecution(execution);
|
|
4642
4621
|
const request = new CreateTaskReq().setTrigger(trigger).setActionsList([action]).setExpiredAt(Math.floor(Date.now() / 1e3) + 1e6);
|
|
4643
4622
|
const result = await this._callRPC("createTask", request);
|
|
4644
|
-
console.log("createTask.result:", result.toObject());
|
|
4645
4623
|
return {
|
|
4646
4624
|
id: result.getId()
|
|
4647
4625
|
};
|
|
@@ -4649,12 +4627,10 @@ var Client = class extends BaseClient {
|
|
|
4649
4627
|
async listTasks(address) {
|
|
4650
4628
|
const request = new ListTasksReq();
|
|
4651
4629
|
const result = await this._callRPC("listTasks", request);
|
|
4652
|
-
console.log("listTasks.result:", result.toObject());
|
|
4653
4630
|
const tasks = import_lodash.default.map(
|
|
4654
4631
|
result.getTasksList(),
|
|
4655
4632
|
(obj) => new task_default(obj)
|
|
4656
4633
|
);
|
|
4657
|
-
console.log("listTasks.tasks:", tasks);
|
|
4658
4634
|
return {
|
|
4659
4635
|
tasks
|
|
4660
4636
|
};
|
|
@@ -4668,7 +4644,6 @@ var Client = class extends BaseClient {
|
|
|
4668
4644
|
"getTask",
|
|
4669
4645
|
request
|
|
4670
4646
|
);
|
|
4671
|
-
console.log("getTask.result:", result.toObject());
|
|
4672
4647
|
return result.toObject();
|
|
4673
4648
|
}
|
|
4674
4649
|
async cancelTask(id) {
|
|
@@ -4692,5 +4667,6 @@ var Client = class extends BaseClient {
|
|
|
4692
4667
|
};
|
|
4693
4668
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4694
4669
|
0 && (module.exports = {
|
|
4670
|
+
AUTH_KEY_HEADER,
|
|
4695
4671
|
getKeyRequestMessage
|
|
4696
4672
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -4178,7 +4178,7 @@ var init_avs_pb = __esm({
|
|
|
4178
4178
|
import _ from "lodash";
|
|
4179
4179
|
import { ethers } from "ethers";
|
|
4180
4180
|
import * as grpc2 from "@grpc/grpc-js";
|
|
4181
|
-
import { Metadata
|
|
4181
|
+
import { Metadata } from "@grpc/grpc-js";
|
|
4182
4182
|
|
|
4183
4183
|
// src/auth.ts
|
|
4184
4184
|
var getKeyRequestMessage = (address, expiredAt) => {
|
|
@@ -4500,13 +4500,14 @@ var Task2 = class {
|
|
|
4500
4500
|
constructor(task) {
|
|
4501
4501
|
this.id = task.getId();
|
|
4502
4502
|
this.status = task.getStatus().toString();
|
|
4503
|
-
console.log("task.constructor:", task.toObject());
|
|
4504
4503
|
}
|
|
4505
4504
|
};
|
|
4506
4505
|
var task_default = Task2;
|
|
4507
4506
|
|
|
4507
|
+
// src/types.ts
|
|
4508
|
+
var AUTH_KEY_HEADER = "authKey";
|
|
4509
|
+
|
|
4508
4510
|
// src/index.ts
|
|
4509
|
-
var metadata = new grpc2.Metadata();
|
|
4510
4511
|
var BaseClient = class {
|
|
4511
4512
|
constructor(opts) {
|
|
4512
4513
|
this.endpoint = opts.endpoint;
|
|
@@ -4514,53 +4515,29 @@ var BaseClient = class {
|
|
|
4514
4515
|
this.endpoint,
|
|
4515
4516
|
grpc2.credentials.createInsecure()
|
|
4516
4517
|
);
|
|
4517
|
-
this.metadata = new
|
|
4518
|
-
}
|
|
4519
|
-
setAuthKey(jwtToken) {
|
|
4520
|
-
metadata.add("authkey", jwtToken);
|
|
4518
|
+
this.metadata = new Metadata();
|
|
4521
4519
|
}
|
|
4522
|
-
|
|
4523
|
-
if (!metadata.get("authkey")) {
|
|
4524
|
-
return false;
|
|
4525
|
-
}
|
|
4520
|
+
isAuthKeyValid(key) {
|
|
4526
4521
|
try {
|
|
4527
|
-
const [, payload] =
|
|
4522
|
+
const [, payload] = key.split(".");
|
|
4528
4523
|
const decodedPayload = JSON.parse(atob(payload));
|
|
4529
4524
|
const currentTimestamp = Math.floor(Date.now() / 1e3);
|
|
4530
4525
|
return decodedPayload.exp > currentTimestamp;
|
|
4531
4526
|
} catch (error) {
|
|
4532
|
-
console.error("Error validating
|
|
4527
|
+
console.error("Error validating auth key:", error);
|
|
4533
4528
|
return false;
|
|
4534
4529
|
}
|
|
4535
4530
|
}
|
|
4536
|
-
|
|
4537
|
-
|
|
4538
|
-
|
|
4539
|
-
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
|
|
4544
|
-
// expiredAt || Math.floor(Date.now() / 1000) + DEFAULT_JWT_EXPIRATION;
|
|
4545
|
-
// const result: avsPb.KeyResp = await this._callRPC<
|
|
4546
|
-
// avsPb.KeyResp,
|
|
4547
|
-
// avsPb.GetKeyReq
|
|
4548
|
-
// >("getKey", {
|
|
4549
|
-
// owner: address,
|
|
4550
|
-
// expired_at: expirationTime,
|
|
4551
|
-
// signature: jwtToken,
|
|
4552
|
-
// });
|
|
4553
|
-
// this.jwtToken = result.getKey();
|
|
4554
|
-
// return { key: result.getKey() };
|
|
4555
|
-
// }
|
|
4531
|
+
async authWithAPIKey(apiKey, expiredAtEpoch) {
|
|
4532
|
+
const request = new GetKeyReq();
|
|
4533
|
+
request.setOwner("");
|
|
4534
|
+
request.setExpiredAt(expiredAtEpoch);
|
|
4535
|
+
request.setSignature(apiKey);
|
|
4536
|
+
const result = await this._callRPC("getKey", request);
|
|
4537
|
+
return { authKey: result.getKey() };
|
|
4538
|
+
}
|
|
4556
4539
|
// This flow can be used where the signature is generate from outside, such as in front-end and pass in
|
|
4557
4540
|
async authWithSignature(address, signature, expiredAtEpoch) {
|
|
4558
|
-
console.log(
|
|
4559
|
-
"Authenticating with signature:",
|
|
4560
|
-
signature,
|
|
4561
|
-
"Expired at epoch:",
|
|
4562
|
-
expiredAtEpoch
|
|
4563
|
-
);
|
|
4564
4541
|
const request = new GetKeyReq();
|
|
4565
4542
|
request.setOwner(address);
|
|
4566
4543
|
request.setExpiredAt(expiredAtEpoch);
|
|
@@ -4569,10 +4546,13 @@ var BaseClient = class {
|
|
|
4569
4546
|
"getKey",
|
|
4570
4547
|
request
|
|
4571
4548
|
);
|
|
4572
|
-
|
|
4573
|
-
return { jwtToken: result.getKey() };
|
|
4549
|
+
return { authKey: result.getKey() };
|
|
4574
4550
|
}
|
|
4575
|
-
_callRPC(method, request) {
|
|
4551
|
+
_callRPC(method, request, options) {
|
|
4552
|
+
const metadata = _.cloneDeep(this.metadata);
|
|
4553
|
+
if (options?.authKey) {
|
|
4554
|
+
metadata.set(AUTH_KEY_HEADER, options.authKey);
|
|
4555
|
+
}
|
|
4576
4556
|
return new Promise((resolve, reject) => {
|
|
4577
4557
|
this.rpcClient[method].bind(this.rpcClient)(
|
|
4578
4558
|
request,
|
|
@@ -4589,11 +4569,10 @@ var Client = class extends BaseClient {
|
|
|
4589
4569
|
constructor(config) {
|
|
4590
4570
|
super(config);
|
|
4591
4571
|
}
|
|
4592
|
-
async getAddresses(address) {
|
|
4572
|
+
async getAddresses(address, { authKey }) {
|
|
4593
4573
|
const request = new AddressRequest();
|
|
4594
4574
|
request.setOwner(address);
|
|
4595
|
-
const result = await this._callRPC("getSmartAccountAddress", request);
|
|
4596
|
-
console.log("getAddresses.result:", result);
|
|
4575
|
+
const result = await this._callRPC("getSmartAccountAddress", request, { authKey });
|
|
4597
4576
|
return {
|
|
4598
4577
|
owner: address,
|
|
4599
4578
|
smart_account_address: result.getSmartAccountAddress()
|
|
@@ -4626,11 +4605,9 @@ var Client = class extends BaseClient {
|
|
|
4626
4605
|
ethers.parseUnits("12", 18)
|
|
4627
4606
|
]);
|
|
4628
4607
|
execution.setCallData(callData);
|
|
4629
|
-
console.log("execution:", execution.toObject());
|
|
4630
4608
|
action.setContractExecution(execution);
|
|
4631
4609
|
const request = new CreateTaskReq().setTrigger(trigger).setActionsList([action]).setExpiredAt(Math.floor(Date.now() / 1e3) + 1e6);
|
|
4632
4610
|
const result = await this._callRPC("createTask", request);
|
|
4633
|
-
console.log("createTask.result:", result.toObject());
|
|
4634
4611
|
return {
|
|
4635
4612
|
id: result.getId()
|
|
4636
4613
|
};
|
|
@@ -4638,12 +4615,10 @@ var Client = class extends BaseClient {
|
|
|
4638
4615
|
async listTasks(address) {
|
|
4639
4616
|
const request = new ListTasksReq();
|
|
4640
4617
|
const result = await this._callRPC("listTasks", request);
|
|
4641
|
-
console.log("listTasks.result:", result.toObject());
|
|
4642
4618
|
const tasks = _.map(
|
|
4643
4619
|
result.getTasksList(),
|
|
4644
4620
|
(obj) => new task_default(obj)
|
|
4645
4621
|
);
|
|
4646
|
-
console.log("listTasks.tasks:", tasks);
|
|
4647
4622
|
return {
|
|
4648
4623
|
tasks
|
|
4649
4624
|
};
|
|
@@ -4657,7 +4632,6 @@ var Client = class extends BaseClient {
|
|
|
4657
4632
|
"getTask",
|
|
4658
4633
|
request
|
|
4659
4634
|
);
|
|
4660
|
-
console.log("getTask.result:", result.toObject());
|
|
4661
4635
|
return result.toObject();
|
|
4662
4636
|
}
|
|
4663
4637
|
async cancelTask(id) {
|
|
@@ -4680,6 +4654,7 @@ var Client = class extends BaseClient {
|
|
|
4680
4654
|
}
|
|
4681
4655
|
};
|
|
4682
4656
|
export {
|
|
4657
|
+
AUTH_KEY_HEADER,
|
|
4683
4658
|
Client as default,
|
|
4684
4659
|
getKeyRequestMessage
|
|
4685
4660
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@avaprotocol/sdk-js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"description": "A JavaScript/TypeScript SDK designed to simplify integration with Ava Protocol's AVS",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -26,7 +26,9 @@
|
|
|
26
26
|
"gen-protoc": "grpc_tools_node_protoc --js_out=import_style=commonjs,binary:./grpc_codegen/ --grpc_out=grpc_js:./grpc_codegen/ --plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts --ts_out=grpc_js:./grpc_codegen --proto_path=./grpc_codegen grpc_codegen/avs.proto",
|
|
27
27
|
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
28
28
|
"test": "jest --config jest.config.cjs",
|
|
29
|
-
"test:select": "npm run test -- --testNamePattern"
|
|
29
|
+
"test:select": "npm run test -- --testNamePattern",
|
|
30
|
+
"changeset": "changeset",
|
|
31
|
+
"version": "changeset version"
|
|
30
32
|
},
|
|
31
33
|
"dependencies": {
|
|
32
34
|
"@grpc/grpc-js": "^1.11.3",
|
|
@@ -40,6 +42,7 @@
|
|
|
40
42
|
"@babel/core": "^7.26.0",
|
|
41
43
|
"@babel/preset-env": "^7.26.0",
|
|
42
44
|
"@babel/preset-typescript": "^7.26.0",
|
|
45
|
+
"@changesets/cli": "^2.27.9",
|
|
43
46
|
"@jest/globals": "^29.7.0",
|
|
44
47
|
"@types/google-protobuf": "^3.15.12",
|
|
45
48
|
"@types/jest": "^29.5.13",
|