pmxtjs 2.49.10 → 2.50.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/dist/esm/generated/src/apis/DefaultApi.d.ts +28 -0
- package/dist/esm/generated/src/apis/DefaultApi.js +28 -0
- package/dist/esm/index.d.ts +4 -3
- package/dist/esm/index.js +4 -3
- package/dist/esm/pmxt/client.d.ts +37 -25
- package/dist/esm/pmxt/client.js +117 -202
- package/dist/esm/pmxt/constants.d.ts +4 -0
- package/dist/esm/pmxt/constants.js +6 -0
- package/dist/esm/pmxt/hosted-routing.js +1 -0
- package/dist/esm/pmxt/hosted-typed-data.d.ts +1 -1
- package/dist/esm/pmxt/hosted-typed-data.js +53 -12
- package/dist/esm/pmxt/models.d.ts +1 -0
- package/dist/esm/pmxt/router.js +12 -3
- package/dist/esm/pmxt/signers.d.ts +7 -0
- package/dist/esm/pmxt/signers.js +30 -8
- package/dist/generated/src/apis/DefaultApi.d.ts +28 -0
- package/dist/generated/src/apis/DefaultApi.js +28 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.js +6 -1
- package/dist/pmxt/client.d.ts +37 -25
- package/dist/pmxt/client.js +116 -200
- package/dist/pmxt/constants.d.ts +4 -0
- package/dist/pmxt/constants.js +7 -1
- package/dist/pmxt/hosted-routing.js +1 -0
- package/dist/pmxt/hosted-typed-data.d.ts +1 -1
- package/dist/pmxt/hosted-typed-data.js +53 -12
- package/dist/pmxt/models.d.ts +1 -0
- package/dist/pmxt/router.js +12 -3
- package/dist/pmxt/signers.d.ts +7 -0
- package/dist/pmxt/signers.js +31 -8
- package/generated/docs/DefaultApi.md +56 -56
- package/generated/package.json +1 -1
- package/generated/src/apis/DefaultApi.ts +28 -0
- package/index.ts +12 -3
- package/package.json +2 -2
- package/pmxt/client.ts +123 -219
- package/pmxt/constants.ts +7 -0
- package/pmxt/hosted-routing.ts +1 -0
- package/pmxt/hosted-typed-data.ts +67 -17
- package/pmxt/models.ts +3 -0
- package/pmxt/router.ts +14 -3
- package/pmxt/signers.ts +28 -7
package/pmxt/signers.ts
CHANGED
|
@@ -38,6 +38,33 @@ export interface Signer {
|
|
|
38
38
|
const ETHERS_INSTALL_HINT =
|
|
39
39
|
"hosted trading requires the optional 'ethers' peer dependency. Install with: npm install ethers";
|
|
40
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Load ethers lazily in BOTH module systems. The CJS build has native
|
|
43
|
+
* `require`; the ESM build does not — bare `require("ethers")` there threw
|
|
44
|
+
* ReferenceError, which callers swallowed, silently dropping the signer and
|
|
45
|
+
* killing every hosted write with "hosted write requires a signer".
|
|
46
|
+
*/
|
|
47
|
+
export function loadEthers(installHint: string = ETHERS_INSTALL_HINT): any {
|
|
48
|
+
if (typeof require === "function") {
|
|
49
|
+
try {
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
51
|
+
return require("ethers");
|
|
52
|
+
} catch {
|
|
53
|
+
throw new Error(installHint);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// ESM: synthesize a require. getBuiltinModule is sync-safe in both
|
|
57
|
+
// module systems (Node >= 20.16).
|
|
58
|
+
const nodeModule = (globalThis as any).process?.getBuiltinModule?.("node:module");
|
|
59
|
+
const req = nodeModule?.createRequire?.(`${process.cwd()}/__pmxt_resolver__.js`);
|
|
60
|
+
if (!req) throw new Error(installHint);
|
|
61
|
+
try {
|
|
62
|
+
return req("ethers");
|
|
63
|
+
} catch {
|
|
64
|
+
throw new Error(installHint);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
41
68
|
/**
|
|
42
69
|
* Built-in signer backed by an ethers `Wallet`.
|
|
43
70
|
*
|
|
@@ -49,13 +76,7 @@ export class EthersSigner implements Signer {
|
|
|
49
76
|
readonly address: string;
|
|
50
77
|
|
|
51
78
|
constructor(privateKey: string) {
|
|
52
|
-
|
|
53
|
-
try {
|
|
54
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
55
|
-
ethers = require("ethers");
|
|
56
|
-
} catch {
|
|
57
|
-
throw new Error(ETHERS_INSTALL_HINT);
|
|
58
|
-
}
|
|
79
|
+
const ethers = loadEthers();
|
|
59
80
|
this._wallet = new ethers.Wallet(privateKey);
|
|
60
81
|
this.address = this._wallet.address;
|
|
61
82
|
}
|