@avaprotocol/sdk-js 0.7.1 → 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 CHANGED
@@ -103,6 +103,7 @@ For more detailed information on using Changesets, refer to the [Changesets docu
103
103
  This repository uses a two-step workflow process for creating new releases:
104
104
 
105
105
  1. **Record changeset workflow**
106
+
106
107
  - Go to the "Actions" tab in GitHub, and run the "Record Changeset" workflow
107
108
  - Select the version bump type:
108
109
  - `patch` for backwards-compatible bug fixes (0.0.x)
@@ -112,15 +113,19 @@ This repository uses a two-step workflow process for creating new releases:
112
113
 
113
114
  2. **Create release workflow**
114
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
115
120
 
116
- ### NPM Publishing
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.
117
122
 
118
- The NPM publishing should 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.
119
123
  1. Publish a dev version and test it in your local environment:
124
+
120
125
  ```bash
121
126
  # Update version with dev tag in package.json
122
127
  npm version prerelease --preid=dev
123
-
128
+
124
129
  # Publish to npm with dev tag
125
130
  npm publish --tag dev
126
131
  ```
@@ -131,8 +136,6 @@ The NPM publishing should be handled manually, since the test cases reference th
131
136
  npm publish
132
137
  ```
133
138
 
134
- > **Note**: Make sure to run these workflows in order. The Version Bump workflow must complete successfully before running the Create Release workflow.
135
-
136
139
  ### Utility Scripts
137
140
 
138
141
  To generate the key request message for signing, you can run the following command:
package/dist/index.d.mts CHANGED
@@ -1458,8 +1458,11 @@ declare class AggregatorClient extends grpc.Client implements IAggregatorClient
1458
1458
 
1459
1459
  type Environment = "production" | "development" | "staging";
1460
1460
  declare const AUTH_KEY_HEADER = "authKey";
1461
+ interface RequestOptions {
1462
+ authKey: string;
1463
+ }
1461
1464
  interface GetKeyResponse {
1462
- key: string;
1465
+ authKey: string;
1463
1466
  }
1464
1467
  interface ClientOption {
1465
1468
  endpoint: string;
@@ -1493,16 +1496,16 @@ declare class BaseClient {
1493
1496
  readonly rpcClient: AggregatorClient;
1494
1497
  protected metadata: Metadata;
1495
1498
  constructor(opts: ClientOption);
1496
- setAuthKey(key: string): void;
1497
- getAuthKey(): string | undefined;
1498
- isAuthenticated(): boolean;
1499
+ isAuthKeyValid(key: string): boolean;
1499
1500
  authWithAPIKey(apiKey: string, expiredAtEpoch: number): Promise<GetKeyResponse>;
1500
1501
  authWithSignature(address: string, signature: string, expiredAtEpoch: number): Promise<GetKeyResponse>;
1501
- 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>;
1502
1503
  }
1503
1504
  declare class Client extends BaseClient {
1504
1505
  constructor(config: ClientOption);
1505
- getAddresses(address: string): Promise<GetAddressesResponse>;
1506
+ getAddresses(address: string, { authKey }: {
1507
+ authKey: string;
1508
+ }): Promise<GetAddressesResponse>;
1506
1509
  createTask({ address, oracleContract, tokenContract, }: {
1507
1510
  address: string;
1508
1511
  tokenContract: string;
@@ -1514,4 +1517,4 @@ declare class Client extends BaseClient {
1514
1517
  deleteTask(id: string): Promise<boolean>;
1515
1518
  }
1516
1519
 
1517
- export { AUTH_KEY_HEADER, 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
@@ -1458,8 +1458,11 @@ declare class AggregatorClient extends grpc.Client implements IAggregatorClient
1458
1458
 
1459
1459
  type Environment = "production" | "development" | "staging";
1460
1460
  declare const AUTH_KEY_HEADER = "authKey";
1461
+ interface RequestOptions {
1462
+ authKey: string;
1463
+ }
1461
1464
  interface GetKeyResponse {
1462
- key: string;
1465
+ authKey: string;
1463
1466
  }
1464
1467
  interface ClientOption {
1465
1468
  endpoint: string;
@@ -1493,16 +1496,16 @@ declare class BaseClient {
1493
1496
  readonly rpcClient: AggregatorClient;
1494
1497
  protected metadata: Metadata;
1495
1498
  constructor(opts: ClientOption);
1496
- setAuthKey(key: string): void;
1497
- getAuthKey(): string | undefined;
1498
- isAuthenticated(): boolean;
1499
+ isAuthKeyValid(key: string): boolean;
1499
1500
  authWithAPIKey(apiKey: string, expiredAtEpoch: number): Promise<GetKeyResponse>;
1500
1501
  authWithSignature(address: string, signature: string, expiredAtEpoch: number): Promise<GetKeyResponse>;
1501
- 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>;
1502
1503
  }
1503
1504
  declare class Client extends BaseClient {
1504
1505
  constructor(config: ClientOption);
1505
- getAddresses(address: string): Promise<GetAddressesResponse>;
1506
+ getAddresses(address: string, { authKey }: {
1507
+ authKey: string;
1508
+ }): Promise<GetAddressesResponse>;
1506
1509
  createTask({ address, oracleContract, tokenContract, }: {
1507
1510
  address: string;
1508
1511
  tokenContract: string;
@@ -1514,4 +1517,4 @@ declare class Client extends BaseClient {
1514
1517
  deleteTask(id: string): Promise<boolean>;
1515
1518
  }
1516
1519
 
1517
- export { AUTH_KEY_HEADER, 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
@@ -4529,25 +4529,14 @@ var BaseClient = class {
4529
4529
  );
4530
4530
  this.metadata = new import_grpc_js.Metadata();
4531
4531
  }
4532
- setAuthKey(key) {
4533
- this.metadata.add(AUTH_KEY_HEADER, key);
4534
- }
4535
- getAuthKey() {
4536
- const authKey = this.metadata.get(AUTH_KEY_HEADER);
4537
- return authKey?.[0]?.toString();
4538
- }
4539
- isAuthenticated() {
4540
- const authKey = this.getAuthKey();
4541
- if (!authKey) {
4542
- return false;
4543
- }
4532
+ isAuthKeyValid(key) {
4544
4533
  try {
4545
- const [, payload] = authKey.split(".");
4534
+ const [, payload] = key.split(".");
4546
4535
  const decodedPayload = JSON.parse(atob(payload));
4547
4536
  const currentTimestamp = Math.floor(Date.now() / 1e3);
4548
4537
  return decodedPayload.exp > currentTimestamp;
4549
4538
  } catch (error) {
4550
- console.error("Error validating JWT token:", error);
4539
+ console.error("Error validating auth key:", error);
4551
4540
  return false;
4552
4541
  }
4553
4542
  }
@@ -4557,8 +4546,7 @@ var BaseClient = class {
4557
4546
  request.setExpiredAt(expiredAtEpoch);
4558
4547
  request.setSignature(apiKey);
4559
4548
  const result = await this._callRPC("getKey", request);
4560
- this.setAuthKey(result.getKey());
4561
- return { key: result.getKey() };
4549
+ return { authKey: result.getKey() };
4562
4550
  }
4563
4551
  // This flow can be used where the signature is generate from outside, such as in front-end and pass in
4564
4552
  async authWithSignature(address, signature, expiredAtEpoch) {
@@ -4570,14 +4558,17 @@ var BaseClient = class {
4570
4558
  "getKey",
4571
4559
  request
4572
4560
  );
4573
- this.setAuthKey(result.getKey());
4574
- return { key: result.getKey() };
4561
+ return { authKey: result.getKey() };
4575
4562
  }
4576
- _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
+ }
4577
4568
  return new Promise((resolve, reject) => {
4578
4569
  this.rpcClient[method].bind(this.rpcClient)(
4579
4570
  request,
4580
- this.metadata,
4571
+ metadata,
4581
4572
  (error, response) => {
4582
4573
  if (error) reject(error);
4583
4574
  else resolve(response);
@@ -4590,10 +4581,10 @@ var Client = class extends BaseClient {
4590
4581
  constructor(config) {
4591
4582
  super(config);
4592
4583
  }
4593
- async getAddresses(address) {
4584
+ async getAddresses(address, { authKey }) {
4594
4585
  const request = new AddressRequest();
4595
4586
  request.setOwner(address);
4596
- const result = await this._callRPC("getSmartAccountAddress", request);
4587
+ const result = await this._callRPC("getSmartAccountAddress", request, { authKey });
4597
4588
  return {
4598
4589
  owner: address,
4599
4590
  smart_account_address: result.getSmartAccountAddress()
package/dist/index.mjs CHANGED
@@ -4517,25 +4517,14 @@ var BaseClient = class {
4517
4517
  );
4518
4518
  this.metadata = new Metadata();
4519
4519
  }
4520
- setAuthKey(key) {
4521
- this.metadata.add(AUTH_KEY_HEADER, key);
4522
- }
4523
- getAuthKey() {
4524
- const authKey = this.metadata.get(AUTH_KEY_HEADER);
4525
- return authKey?.[0]?.toString();
4526
- }
4527
- isAuthenticated() {
4528
- const authKey = this.getAuthKey();
4529
- if (!authKey) {
4530
- return false;
4531
- }
4520
+ isAuthKeyValid(key) {
4532
4521
  try {
4533
- const [, payload] = authKey.split(".");
4522
+ const [, payload] = key.split(".");
4534
4523
  const decodedPayload = JSON.parse(atob(payload));
4535
4524
  const currentTimestamp = Math.floor(Date.now() / 1e3);
4536
4525
  return decodedPayload.exp > currentTimestamp;
4537
4526
  } catch (error) {
4538
- console.error("Error validating JWT token:", error);
4527
+ console.error("Error validating auth key:", error);
4539
4528
  return false;
4540
4529
  }
4541
4530
  }
@@ -4545,8 +4534,7 @@ var BaseClient = class {
4545
4534
  request.setExpiredAt(expiredAtEpoch);
4546
4535
  request.setSignature(apiKey);
4547
4536
  const result = await this._callRPC("getKey", request);
4548
- this.setAuthKey(result.getKey());
4549
- return { key: result.getKey() };
4537
+ return { authKey: result.getKey() };
4550
4538
  }
4551
4539
  // This flow can be used where the signature is generate from outside, such as in front-end and pass in
4552
4540
  async authWithSignature(address, signature, expiredAtEpoch) {
@@ -4558,14 +4546,17 @@ var BaseClient = class {
4558
4546
  "getKey",
4559
4547
  request
4560
4548
  );
4561
- this.setAuthKey(result.getKey());
4562
- return { key: result.getKey() };
4549
+ return { authKey: result.getKey() };
4563
4550
  }
4564
- _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
+ }
4565
4556
  return new Promise((resolve, reject) => {
4566
4557
  this.rpcClient[method].bind(this.rpcClient)(
4567
4558
  request,
4568
- this.metadata,
4559
+ metadata,
4569
4560
  (error, response) => {
4570
4561
  if (error) reject(error);
4571
4562
  else resolve(response);
@@ -4578,10 +4569,10 @@ var Client = class extends BaseClient {
4578
4569
  constructor(config) {
4579
4570
  super(config);
4580
4571
  }
4581
- async getAddresses(address) {
4572
+ async getAddresses(address, { authKey }) {
4582
4573
  const request = new AddressRequest();
4583
4574
  request.setOwner(address);
4584
- const result = await this._callRPC("getSmartAccountAddress", request);
4575
+ const result = await this._callRPC("getSmartAccountAddress", request, { authKey });
4585
4576
  return {
4586
4577
  owner: address,
4587
4578
  smart_account_address: result.getSmartAccountAddress()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@avaprotocol/sdk-js",
3
- "version": "0.7.1",
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",