@dedot/api 0.1.1-next.77a2d8eb.4 → 0.2.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.
@@ -274,5 +274,8 @@ class BaseSubstrateClient extends index_js_2.JsonRpcClient {
274
274
  at(hash) {
275
275
  throw new Error('Unimplemented!');
276
276
  }
277
+ setSigner(signer) {
278
+ this._options.signer = signer;
279
+ }
277
280
  }
278
281
  exports.BaseSubstrateClient = BaseSubstrateClient;
@@ -26,7 +26,7 @@ class BaseSubmittableExtrinsic extends codecs_1.Extrinsic {
26
26
  payloadOptions: options,
27
27
  });
28
28
  await extra.init();
29
- const { signer } = options || {};
29
+ const signer = this.#getSigner(options);
30
30
  let signature, alteredTx;
31
31
  if ((0, utils_js_1.isKeyringPair)(fromAccount)) {
32
32
  signature = (0, utils_1.u8aToHex)((0, utils_js_1.signRaw)(fromAccount, extra.toRawPayload(this.callHex).data));
@@ -96,5 +96,8 @@ class BaseSubmittableExtrinsic extends codecs_1.Extrinsic {
96
96
  throw new utils_1.DedotError('Call data does not match, signer is not allowed to change tx call data.');
97
97
  }
98
98
  }
99
+ #getSigner(options) {
100
+ return options?.signer || this.api.options.signer;
101
+ }
99
102
  }
100
103
  exports.BaseSubmittableExtrinsic = BaseSubmittableExtrinsic;
@@ -1,3 +1,4 @@
1
+ import { Signer } from '@polkadot/types/types';
1
2
  import { BlockHash, Hash, Metadata, PortableRegistry, RuntimeVersion } from '@dedot/codecs';
2
3
  import type { JsonRpcProvider } from '@dedot/providers';
3
4
  import { type IStorage } from '@dedot/storage';
@@ -68,4 +69,5 @@ export declare abstract class BaseSubstrateClient<Rv extends RpcVersion, ChainAp
68
69
  protected callAt(hash?: BlockHash): ChainApi[Rv]['call'];
69
70
  get tx(): ChainApi[Rv]['tx'];
70
71
  at<ChainApiAt extends GenericSubstrateApi = ChainApi[Rv]>(hash: BlockHash): Promise<ISubstrateClientAt<ChainApiAt>>;
72
+ setSigner(signer?: Signer): void;
71
73
  }
@@ -270,4 +270,7 @@ export class BaseSubstrateClient extends JsonRpcClient {
270
270
  at(hash) {
271
271
  throw new Error('Unimplemented!');
272
272
  }
273
+ setSigner(signer) {
274
+ this._options.signer = signer;
275
+ }
273
276
  }
@@ -23,7 +23,7 @@ export class BaseSubmittableExtrinsic extends Extrinsic {
23
23
  payloadOptions: options,
24
24
  });
25
25
  await extra.init();
26
- const { signer } = options || {};
26
+ const signer = this.#getSigner(options);
27
27
  let signature, alteredTx;
28
28
  if (isKeyringPair(fromAccount)) {
29
29
  signature = u8aToHex(signRaw(fromAccount, extra.toRawPayload(this.callHex).data));
@@ -93,4 +93,7 @@ export class BaseSubmittableExtrinsic extends Extrinsic {
93
93
  throw new DedotError('Call data does not match, signer is not allowed to change tx call data.');
94
94
  }
95
95
  }
96
+ #getSigner(options) {
97
+ return options?.signer || this.api.options.signer;
98
+ }
96
99
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dedot/api",
3
- "version": "0.1.1-next.77a2d8eb.4+77a2d8e",
3
+ "version": "0.2.0",
4
4
  "description": "A delightful JavaScript/TypeScript client for Polkadot & Substrate",
5
5
  "author": "Thang X. Vu <thang@coongcrafts.io>",
6
6
  "homepage": "https://github.com/dedotdev/dedot/tree/main/packages/api",
@@ -13,13 +13,13 @@
13
13
  "type": "module",
14
14
  "sideEffects": false,
15
15
  "dependencies": {
16
- "@dedot/codecs": "0.1.1-next.77a2d8eb.4+77a2d8e",
17
- "@dedot/providers": "0.1.1-next.77a2d8eb.4+77a2d8e",
18
- "@dedot/runtime-specs": "0.1.1-next.77a2d8eb.4+77a2d8e",
19
- "@dedot/shape": "0.1.1-next.77a2d8eb.4+77a2d8e",
20
- "@dedot/storage": "0.1.1-next.77a2d8eb.4+77a2d8e",
21
- "@dedot/types": "0.1.1-next.77a2d8eb.4+77a2d8e",
22
- "@dedot/utils": "0.1.1-next.77a2d8eb.4+77a2d8e"
16
+ "@dedot/codecs": "0.2.0",
17
+ "@dedot/providers": "0.2.0",
18
+ "@dedot/runtime-specs": "0.2.0",
19
+ "@dedot/shape": "0.2.0",
20
+ "@dedot/storage": "0.2.0",
21
+ "@dedot/types": "0.2.0",
22
+ "@dedot/utils": "0.2.0"
23
23
  },
24
24
  "scripts": {
25
25
  "build": "tsc --project tsconfig.build.json && tsc --project tsconfig.build.cjs.json",
@@ -48,7 +48,7 @@
48
48
  "devDependencies": {
49
49
  "@polkadot/types": "^12.2.1"
50
50
  },
51
- "gitHead": "77a2d8eb1aa950c978c1057657ef39b9061b3969",
51
+ "gitHead": "f29e8784997251518df1e33ef782f1d87207b126",
52
52
  "module": "./index.js",
53
53
  "types": "./index.d.ts"
54
54
  }
package/types.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { Signer } from '@polkadot/types/types';
1
2
  import { BlockHash, Hash, Metadata, PortableRegistry } from '@dedot/codecs';
2
3
  import type { ConnectionStatus, JsonRpcProvider, ProviderEvent } from '@dedot/providers';
3
4
  import type { AnyShape } from '@dedot/shape';
@@ -55,6 +56,10 @@ export interface ApiOptions extends JsonRpcClientOptions {
55
56
  * @default blake2_256
56
57
  */
57
58
  hasher?: HashFn;
59
+ /**
60
+ * A signer instance to use for signing transactions
61
+ */
62
+ signer?: Signer;
58
63
  }
59
64
  export type ApiEvent = ProviderEvent | 'ready' | 'runtimeUpgraded';
60
65
  export interface SubstrateRuntimeVersion {
@@ -109,6 +114,12 @@ export interface ISubstrateClient<ChainApi extends GenericSubstrateApi = Generic
109
114
  * This is helpful when you want to check runtime version to prepare for runtime upgrade
110
115
  */
111
116
  getRuntimeVersion(): Promise<SubstrateRuntimeVersion>;
117
+ /**
118
+ * Update the signer instance for signing transactions
119
+ *
120
+ * @param signer
121
+ */
122
+ setSigner(signer?: Signer): void;
112
123
  }
113
124
  /**
114
125
  * A generic interface for broadcasting transactions