@getpara/viem-v1-integration 2.0.0-dev.1 → 2.0.0-dev.3
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/cjs/index.js +3 -126
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/viemWalletClient.js +140 -0
- package/dist/esm/index.js +1 -114
- package/dist/esm/package.json +4 -0
- package/dist/esm/viemWalletClient.js +112 -0
- package/package.json +24 -24
- package/dist/cjs/index.js.br +0 -0
- package/dist/cjs/index.js.gz +0 -0
- package/dist/esm/index.js.br +0 -0
- package/dist/esm/index.js.gz +0 -0
package/dist/cjs/index.js
CHANGED
|
@@ -1,27 +1,7 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
-
var __spreadValues = (a, b) => {
|
|
11
|
-
for (var prop in b || (b = {}))
|
|
12
|
-
if (__hasOwnProp.call(b, prop))
|
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
|
14
|
-
if (__getOwnPropSymbols)
|
|
15
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
-
if (__propIsEnum.call(b, prop))
|
|
17
|
-
__defNormalProp(a, prop, b[prop]);
|
|
18
|
-
}
|
|
19
|
-
return a;
|
|
20
|
-
};
|
|
21
|
-
var __export = (target, all) => {
|
|
22
|
-
for (var name in all)
|
|
23
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
24
|
-
};
|
|
25
5
|
var __copyProps = (to, from, except, desc) => {
|
|
26
6
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
27
7
|
for (let key of __getOwnPropNames(from))
|
|
@@ -30,115 +10,12 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
30
10
|
}
|
|
31
11
|
return to;
|
|
32
12
|
};
|
|
33
|
-
var
|
|
34
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
35
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
36
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
37
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
38
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
39
|
-
mod
|
|
40
|
-
));
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
41
14
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
42
|
-
var __async = (__this, __arguments, generator) => {
|
|
43
|
-
return new Promise((resolve, reject) => {
|
|
44
|
-
var fulfilled = (value) => {
|
|
45
|
-
try {
|
|
46
|
-
step(generator.next(value));
|
|
47
|
-
} catch (e) {
|
|
48
|
-
reject(e);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
var rejected = (value) => {
|
|
52
|
-
try {
|
|
53
|
-
step(generator.throw(value));
|
|
54
|
-
} catch (e) {
|
|
55
|
-
reject(e);
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
59
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
// src/index.ts
|
|
64
15
|
var src_exports = {};
|
|
65
|
-
__export(src_exports, {
|
|
66
|
-
createParaAccount: () => createParaAccount,
|
|
67
|
-
createParaViemClient: () => createParaViemClient,
|
|
68
|
-
getViemChain: () => getViemChain
|
|
69
|
-
});
|
|
70
16
|
module.exports = __toCommonJS(src_exports);
|
|
71
|
-
|
|
72
|
-
// src/viemWalletClient.ts
|
|
73
|
-
var import_viem = require("viem");
|
|
74
|
-
var viemChains = __toESM(require("viem/chains"));
|
|
75
|
-
var import_core_sdk = require("@getpara/core-sdk");
|
|
76
|
-
function createParaAccount(para, walletAddress) {
|
|
77
|
-
let currentWallet;
|
|
78
|
-
if (walletAddress) {
|
|
79
|
-
currentWallet = para.findWalletByAddress(walletAddress, { type: ["EVM"] });
|
|
80
|
-
} else {
|
|
81
|
-
const walletId = para.findWalletId(void 0, { type: ["EVM"] });
|
|
82
|
-
currentWallet = para.wallets[walletId];
|
|
83
|
-
}
|
|
84
|
-
return {
|
|
85
|
-
address: currentWallet.address,
|
|
86
|
-
publicKey: currentWallet.publicKey || "0x",
|
|
87
|
-
source: "custom",
|
|
88
|
-
type: "local",
|
|
89
|
-
signMessage: (_0) => __async(this, [_0], function* ({ message }) {
|
|
90
|
-
const hashedMessage = (0, import_viem.hashMessage)(message);
|
|
91
|
-
const res = yield para.signMessage({ walletId: currentWallet.id, messageBase64: (0, import_core_sdk.hexStringToBase64)(hashedMessage) });
|
|
92
|
-
const signature = res.signature;
|
|
93
|
-
return `0x${signature}`;
|
|
94
|
-
}),
|
|
95
|
-
signTransaction: (transaction, args) => __async(this, null, function* () {
|
|
96
|
-
let { serializer } = args || {};
|
|
97
|
-
if (!serializer) {
|
|
98
|
-
serializer = import_viem.serializeTransaction;
|
|
99
|
-
}
|
|
100
|
-
const serializedTx = serializer(transaction, {
|
|
101
|
-
r: "0x",
|
|
102
|
-
s: "0x",
|
|
103
|
-
v: BigInt(0)
|
|
104
|
-
});
|
|
105
|
-
const res = yield para.signTransaction({
|
|
106
|
-
walletId: currentWallet.id,
|
|
107
|
-
rlpEncodedTxBase64: (0, import_core_sdk.hexStringToBase64)(serializedTx.substring(2)),
|
|
108
|
-
chainId: `${transaction.chainId}`
|
|
109
|
-
});
|
|
110
|
-
const signature = res.signature;
|
|
111
|
-
const formattedSig = (0, import_core_sdk.hexToSignature)(`0x${signature}`);
|
|
112
|
-
formattedSig.v += BigInt(27);
|
|
113
|
-
return serializer(transaction, formattedSig);
|
|
114
|
-
}),
|
|
115
|
-
signTypedData: (typedData) => __async(this, null, function* () {
|
|
116
|
-
const res = yield para.signMessage({
|
|
117
|
-
walletId: currentWallet.id,
|
|
118
|
-
messageBase64: (0, import_core_sdk.hexStringToBase64)((0, import_viem.hashTypedData)(typedData))
|
|
119
|
-
});
|
|
120
|
-
const signature = res.signature;
|
|
121
|
-
return `0x${signature}`;
|
|
122
|
-
})
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
function getViemChain(chainId) {
|
|
126
|
-
const chainIdNum = Number(chainId);
|
|
127
|
-
for (const chain of Object.values(viemChains)) {
|
|
128
|
-
if (chain.id === chainIdNum) {
|
|
129
|
-
return chain;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
throw new Error(`chain with id ${chainId} not found`);
|
|
133
|
-
}
|
|
134
|
-
function createParaViemClient(para, params, opts) {
|
|
135
|
-
return (0, import_viem.createWalletClient)(__spreadValues({
|
|
136
|
-
account: (opts == null ? void 0 : opts.noAccount) ? void 0 : createParaAccount(para)
|
|
137
|
-
}, params));
|
|
138
|
-
}
|
|
17
|
+
__reExport(src_exports, require("./viemWalletClient.js"), module.exports);
|
|
139
18
|
// Annotate the CommonJS export names for ESM import in node:
|
|
140
19
|
0 && (module.exports = {
|
|
141
|
-
|
|
142
|
-
createParaViemClient,
|
|
143
|
-
getViemChain
|
|
20
|
+
...require("./viemWalletClient.js")
|
|
144
21
|
});
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __spreadValues = (a, b) => {
|
|
11
|
+
for (var prop in b || (b = {}))
|
|
12
|
+
if (__hasOwnProp.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
if (__getOwnPropSymbols)
|
|
15
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
+
if (__propIsEnum.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
}
|
|
19
|
+
return a;
|
|
20
|
+
};
|
|
21
|
+
var __export = (target, all) => {
|
|
22
|
+
for (var name in all)
|
|
23
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
24
|
+
};
|
|
25
|
+
var __copyProps = (to, from, except, desc) => {
|
|
26
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
27
|
+
for (let key of __getOwnPropNames(from))
|
|
28
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
29
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
30
|
+
}
|
|
31
|
+
return to;
|
|
32
|
+
};
|
|
33
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
34
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
35
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
36
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
37
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
38
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
39
|
+
mod
|
|
40
|
+
));
|
|
41
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
42
|
+
var __async = (__this, __arguments, generator) => {
|
|
43
|
+
return new Promise((resolve, reject) => {
|
|
44
|
+
var fulfilled = (value) => {
|
|
45
|
+
try {
|
|
46
|
+
step(generator.next(value));
|
|
47
|
+
} catch (e) {
|
|
48
|
+
reject(e);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
var rejected = (value) => {
|
|
52
|
+
try {
|
|
53
|
+
step(generator.throw(value));
|
|
54
|
+
} catch (e) {
|
|
55
|
+
reject(e);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
59
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
var viemWalletClient_exports = {};
|
|
63
|
+
__export(viemWalletClient_exports, {
|
|
64
|
+
createParaAccount: () => createParaAccount,
|
|
65
|
+
createParaViemClient: () => createParaViemClient,
|
|
66
|
+
getViemChain: () => getViemChain
|
|
67
|
+
});
|
|
68
|
+
module.exports = __toCommonJS(viemWalletClient_exports);
|
|
69
|
+
var import_viem = require("viem");
|
|
70
|
+
var viemChains = __toESM(require("viem/chains"));
|
|
71
|
+
var import_core_sdk = require("@getpara/core-sdk");
|
|
72
|
+
function createParaAccount(para, walletAddress) {
|
|
73
|
+
let currentWallet;
|
|
74
|
+
if (walletAddress) {
|
|
75
|
+
currentWallet = para.findWalletByAddress(walletAddress, { type: ["EVM"] });
|
|
76
|
+
} else {
|
|
77
|
+
const walletId = para.findWalletId(void 0, { type: ["EVM"] });
|
|
78
|
+
currentWallet = para.wallets[walletId];
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
address: currentWallet.address,
|
|
82
|
+
publicKey: currentWallet.publicKey || "0x",
|
|
83
|
+
source: "custom",
|
|
84
|
+
type: "local",
|
|
85
|
+
signMessage: (_0) => __async(this, [_0], function* ({ message }) {
|
|
86
|
+
const hashedMessage = (0, import_viem.hashMessage)(message);
|
|
87
|
+
const res = yield para.signMessage({ walletId: currentWallet.id, messageBase64: (0, import_core_sdk.hexStringToBase64)(hashedMessage) });
|
|
88
|
+
const signature = res.signature;
|
|
89
|
+
return `0x${signature}`;
|
|
90
|
+
}),
|
|
91
|
+
signTransaction: (transaction, args) => __async(this, null, function* () {
|
|
92
|
+
let { serializer } = args || {};
|
|
93
|
+
if (!serializer) {
|
|
94
|
+
serializer = import_viem.serializeTransaction;
|
|
95
|
+
}
|
|
96
|
+
const serializedTx = serializer(transaction, {
|
|
97
|
+
r: "0x",
|
|
98
|
+
s: "0x",
|
|
99
|
+
v: BigInt(0)
|
|
100
|
+
});
|
|
101
|
+
const res = yield para.signTransaction({
|
|
102
|
+
walletId: currentWallet.id,
|
|
103
|
+
rlpEncodedTxBase64: (0, import_core_sdk.hexStringToBase64)(serializedTx.substring(2)),
|
|
104
|
+
chainId: `${transaction.chainId}`
|
|
105
|
+
});
|
|
106
|
+
const signature = res.signature;
|
|
107
|
+
const formattedSig = (0, import_core_sdk.hexToSignature)(`0x${signature}`);
|
|
108
|
+
formattedSig.v += BigInt(27);
|
|
109
|
+
return serializer(transaction, formattedSig);
|
|
110
|
+
}),
|
|
111
|
+
signTypedData: (typedData) => __async(this, null, function* () {
|
|
112
|
+
const res = yield para.signMessage({
|
|
113
|
+
walletId: currentWallet.id,
|
|
114
|
+
messageBase64: (0, import_core_sdk.hexStringToBase64)((0, import_viem.hashTypedData)(typedData))
|
|
115
|
+
});
|
|
116
|
+
const signature = res.signature;
|
|
117
|
+
return `0x${signature}`;
|
|
118
|
+
})
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function getViemChain(chainId) {
|
|
122
|
+
const chainIdNum = Number(chainId);
|
|
123
|
+
for (const chain of Object.values(viemChains)) {
|
|
124
|
+
if (chain.id === chainIdNum) {
|
|
125
|
+
return chain;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
throw new Error(`chain with id ${chainId} not found`);
|
|
129
|
+
}
|
|
130
|
+
function createParaViemClient(para, params, opts) {
|
|
131
|
+
return (0, import_viem.createWalletClient)(__spreadValues({
|
|
132
|
+
account: (opts == null ? void 0 : opts.noAccount) ? void 0 : createParaAccount(para)
|
|
133
|
+
}, params));
|
|
134
|
+
}
|
|
135
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
136
|
+
0 && (module.exports = {
|
|
137
|
+
createParaAccount,
|
|
138
|
+
createParaViemClient,
|
|
139
|
+
getViemChain
|
|
140
|
+
});
|
package/dist/esm/index.js
CHANGED
|
@@ -1,114 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
-
var __spreadValues = (a, b) => {
|
|
7
|
-
for (var prop in b || (b = {}))
|
|
8
|
-
if (__hasOwnProp.call(b, prop))
|
|
9
|
-
__defNormalProp(a, prop, b[prop]);
|
|
10
|
-
if (__getOwnPropSymbols)
|
|
11
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
-
if (__propIsEnum.call(b, prop))
|
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
|
14
|
-
}
|
|
15
|
-
return a;
|
|
16
|
-
};
|
|
17
|
-
var __async = (__this, __arguments, generator) => {
|
|
18
|
-
return new Promise((resolve, reject) => {
|
|
19
|
-
var fulfilled = (value) => {
|
|
20
|
-
try {
|
|
21
|
-
step(generator.next(value));
|
|
22
|
-
} catch (e) {
|
|
23
|
-
reject(e);
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
var rejected = (value) => {
|
|
27
|
-
try {
|
|
28
|
-
step(generator.throw(value));
|
|
29
|
-
} catch (e) {
|
|
30
|
-
reject(e);
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
34
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
// src/viemWalletClient.ts
|
|
39
|
-
import {
|
|
40
|
-
createWalletClient,
|
|
41
|
-
hashMessage,
|
|
42
|
-
serializeTransaction,
|
|
43
|
-
hashTypedData
|
|
44
|
-
} from "viem";
|
|
45
|
-
import * as viemChains from "viem/chains";
|
|
46
|
-
import { hexStringToBase64, hexToSignature } from "@getpara/core-sdk";
|
|
47
|
-
function createParaAccount(para, walletAddress) {
|
|
48
|
-
let currentWallet;
|
|
49
|
-
if (walletAddress) {
|
|
50
|
-
currentWallet = para.findWalletByAddress(walletAddress, { type: ["EVM"] });
|
|
51
|
-
} else {
|
|
52
|
-
const walletId = para.findWalletId(void 0, { type: ["EVM"] });
|
|
53
|
-
currentWallet = para.wallets[walletId];
|
|
54
|
-
}
|
|
55
|
-
return {
|
|
56
|
-
address: currentWallet.address,
|
|
57
|
-
publicKey: currentWallet.publicKey || "0x",
|
|
58
|
-
source: "custom",
|
|
59
|
-
type: "local",
|
|
60
|
-
signMessage: (_0) => __async(this, [_0], function* ({ message }) {
|
|
61
|
-
const hashedMessage = hashMessage(message);
|
|
62
|
-
const res = yield para.signMessage({ walletId: currentWallet.id, messageBase64: hexStringToBase64(hashedMessage) });
|
|
63
|
-
const signature = res.signature;
|
|
64
|
-
return `0x${signature}`;
|
|
65
|
-
}),
|
|
66
|
-
signTransaction: (transaction, args) => __async(this, null, function* () {
|
|
67
|
-
let { serializer } = args || {};
|
|
68
|
-
if (!serializer) {
|
|
69
|
-
serializer = serializeTransaction;
|
|
70
|
-
}
|
|
71
|
-
const serializedTx = serializer(transaction, {
|
|
72
|
-
r: "0x",
|
|
73
|
-
s: "0x",
|
|
74
|
-
v: BigInt(0)
|
|
75
|
-
});
|
|
76
|
-
const res = yield para.signTransaction({
|
|
77
|
-
walletId: currentWallet.id,
|
|
78
|
-
rlpEncodedTxBase64: hexStringToBase64(serializedTx.substring(2)),
|
|
79
|
-
chainId: `${transaction.chainId}`
|
|
80
|
-
});
|
|
81
|
-
const signature = res.signature;
|
|
82
|
-
const formattedSig = hexToSignature(`0x${signature}`);
|
|
83
|
-
formattedSig.v += BigInt(27);
|
|
84
|
-
return serializer(transaction, formattedSig);
|
|
85
|
-
}),
|
|
86
|
-
signTypedData: (typedData) => __async(this, null, function* () {
|
|
87
|
-
const res = yield para.signMessage({
|
|
88
|
-
walletId: currentWallet.id,
|
|
89
|
-
messageBase64: hexStringToBase64(hashTypedData(typedData))
|
|
90
|
-
});
|
|
91
|
-
const signature = res.signature;
|
|
92
|
-
return `0x${signature}`;
|
|
93
|
-
})
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
function getViemChain(chainId) {
|
|
97
|
-
const chainIdNum = Number(chainId);
|
|
98
|
-
for (const chain of Object.values(viemChains)) {
|
|
99
|
-
if (chain.id === chainIdNum) {
|
|
100
|
-
return chain;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
throw new Error(`chain with id ${chainId} not found`);
|
|
104
|
-
}
|
|
105
|
-
function createParaViemClient(para, params, opts) {
|
|
106
|
-
return createWalletClient(__spreadValues({
|
|
107
|
-
account: (opts == null ? void 0 : opts.noAccount) ? void 0 : createParaAccount(para)
|
|
108
|
-
}, params));
|
|
109
|
-
}
|
|
110
|
-
export {
|
|
111
|
-
createParaAccount,
|
|
112
|
-
createParaViemClient,
|
|
113
|
-
getViemChain
|
|
114
|
-
};
|
|
1
|
+
export * from "./viemWalletClient.js";
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
var __async = (__this, __arguments, generator) => {
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
var fulfilled = (value) => {
|
|
20
|
+
try {
|
|
21
|
+
step(generator.next(value));
|
|
22
|
+
} catch (e) {
|
|
23
|
+
reject(e);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var rejected = (value) => {
|
|
27
|
+
try {
|
|
28
|
+
step(generator.throw(value));
|
|
29
|
+
} catch (e) {
|
|
30
|
+
reject(e);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
34
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
import {
|
|
38
|
+
createWalletClient,
|
|
39
|
+
hashMessage,
|
|
40
|
+
serializeTransaction,
|
|
41
|
+
hashTypedData
|
|
42
|
+
} from "viem";
|
|
43
|
+
import * as viemChains from "viem/chains";
|
|
44
|
+
import { hexStringToBase64, hexToSignature } from "@getpara/core-sdk";
|
|
45
|
+
function createParaAccount(para, walletAddress) {
|
|
46
|
+
let currentWallet;
|
|
47
|
+
if (walletAddress) {
|
|
48
|
+
currentWallet = para.findWalletByAddress(walletAddress, { type: ["EVM"] });
|
|
49
|
+
} else {
|
|
50
|
+
const walletId = para.findWalletId(void 0, { type: ["EVM"] });
|
|
51
|
+
currentWallet = para.wallets[walletId];
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
address: currentWallet.address,
|
|
55
|
+
publicKey: currentWallet.publicKey || "0x",
|
|
56
|
+
source: "custom",
|
|
57
|
+
type: "local",
|
|
58
|
+
signMessage: (_0) => __async(this, [_0], function* ({ message }) {
|
|
59
|
+
const hashedMessage = hashMessage(message);
|
|
60
|
+
const res = yield para.signMessage({ walletId: currentWallet.id, messageBase64: hexStringToBase64(hashedMessage) });
|
|
61
|
+
const signature = res.signature;
|
|
62
|
+
return `0x${signature}`;
|
|
63
|
+
}),
|
|
64
|
+
signTransaction: (transaction, args) => __async(this, null, function* () {
|
|
65
|
+
let { serializer } = args || {};
|
|
66
|
+
if (!serializer) {
|
|
67
|
+
serializer = serializeTransaction;
|
|
68
|
+
}
|
|
69
|
+
const serializedTx = serializer(transaction, {
|
|
70
|
+
r: "0x",
|
|
71
|
+
s: "0x",
|
|
72
|
+
v: BigInt(0)
|
|
73
|
+
});
|
|
74
|
+
const res = yield para.signTransaction({
|
|
75
|
+
walletId: currentWallet.id,
|
|
76
|
+
rlpEncodedTxBase64: hexStringToBase64(serializedTx.substring(2)),
|
|
77
|
+
chainId: `${transaction.chainId}`
|
|
78
|
+
});
|
|
79
|
+
const signature = res.signature;
|
|
80
|
+
const formattedSig = hexToSignature(`0x${signature}`);
|
|
81
|
+
formattedSig.v += BigInt(27);
|
|
82
|
+
return serializer(transaction, formattedSig);
|
|
83
|
+
}),
|
|
84
|
+
signTypedData: (typedData) => __async(this, null, function* () {
|
|
85
|
+
const res = yield para.signMessage({
|
|
86
|
+
walletId: currentWallet.id,
|
|
87
|
+
messageBase64: hexStringToBase64(hashTypedData(typedData))
|
|
88
|
+
});
|
|
89
|
+
const signature = res.signature;
|
|
90
|
+
return `0x${signature}`;
|
|
91
|
+
})
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function getViemChain(chainId) {
|
|
95
|
+
const chainIdNum = Number(chainId);
|
|
96
|
+
for (const chain of Object.values(viemChains)) {
|
|
97
|
+
if (chain.id === chainIdNum) {
|
|
98
|
+
return chain;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
throw new Error(`chain with id ${chainId} not found`);
|
|
102
|
+
}
|
|
103
|
+
function createParaViemClient(para, params, opts) {
|
|
104
|
+
return createWalletClient(__spreadValues({
|
|
105
|
+
account: (opts == null ? void 0 : opts.noAccount) ? void 0 : createParaAccount(para)
|
|
106
|
+
}, params));
|
|
107
|
+
}
|
|
108
|
+
export {
|
|
109
|
+
createParaAccount,
|
|
110
|
+
createParaViemClient,
|
|
111
|
+
getViemChain
|
|
112
|
+
};
|
package/package.json
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpara/viem-v1-integration",
|
|
3
|
-
"version": "2.0.0-dev.
|
|
4
|
-
"main": "dist/cjs/index.js",
|
|
5
|
-
"module": "dist/esm/index.js",
|
|
6
|
-
"types": "dist/types/index.d.ts",
|
|
7
|
-
"typings": "dist/types/index.d.ts",
|
|
8
|
-
"sideEffects": false,
|
|
3
|
+
"version": "2.0.0-dev.3",
|
|
9
4
|
"dependencies": {
|
|
10
|
-
"@getpara/core-sdk": "2.0.0-dev.
|
|
11
|
-
},
|
|
12
|
-
"scripts": {
|
|
13
|
-
"build": "rm -rf dist && node ./scripts/build.mjs && yarn build:types",
|
|
14
|
-
"old-build": "yarn build:cjs && yarn build:esm && yarn build:types",
|
|
15
|
-
"build:cjs": "rm -rf dist/cjs && tsc --module commonjs --outDir dist/cjs && printf '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
|
|
16
|
-
"build:esm": "rm -rf dist/esm && tsc --module es6 --outDir dist/esm && printf '{\"type\":\"module\",\"sideEffects\":false}' > dist/esm/package.json",
|
|
17
|
-
"build:types": "rm -rf dist/types && tsc --module es6 --declarationDir dist/types --emitDeclarationOnly --declaration"
|
|
5
|
+
"@getpara/core-sdk": "2.0.0-dev.3"
|
|
18
6
|
},
|
|
19
7
|
"devDependencies": {
|
|
20
|
-
"typescript": "5.
|
|
8
|
+
"typescript": "^5.8.3",
|
|
21
9
|
"viem": "1.x"
|
|
22
10
|
},
|
|
23
|
-
"
|
|
24
|
-
"
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/types/index.d.ts",
|
|
14
|
+
"import": "./dist/esm/index.js",
|
|
15
|
+
"require": "./dist/cjs/index.js"
|
|
16
|
+
}
|
|
25
17
|
},
|
|
26
18
|
"files": [
|
|
27
19
|
"dist",
|
|
28
20
|
"package.json"
|
|
29
21
|
],
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
22
|
+
"gitHead": "ffe34f7d8df2dd3c2327ca1f35bcc9764e0a68a2",
|
|
23
|
+
"main": "dist/cjs/index.js",
|
|
24
|
+
"module": "dist/esm/index.js",
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"viem": "1.x"
|
|
36
27
|
},
|
|
37
|
-
"
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "rm -rf dist && node ./scripts/build.mjs && yarn build:types",
|
|
30
|
+
"build:cjs": "rm -rf dist/cjs && tsc --module commonjs --outDir dist/cjs && printf '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
|
|
31
|
+
"build:esm": "rm -rf dist/esm && tsc --module es6 --outDir dist/esm && printf '{\"type\":\"module\",\"sideEffects\":false}' > dist/esm/package.json",
|
|
32
|
+
"build:types": "rm -rf dist/types && tsc --module es6 --declarationDir dist/types --emitDeclarationOnly --declaration",
|
|
33
|
+
"old-build": "yarn build:cjs && yarn build:esm && yarn build:types"
|
|
34
|
+
},
|
|
35
|
+
"sideEffects": false,
|
|
36
|
+
"types": "dist/types/index.d.ts",
|
|
37
|
+
"typings": "dist/types/index.d.ts"
|
|
38
38
|
}
|
package/dist/cjs/index.js.br
DELETED
|
Binary file
|
package/dist/cjs/index.js.gz
DELETED
|
Binary file
|
package/dist/esm/index.js.br
DELETED
|
Binary file
|
package/dist/esm/index.js.gz
DELETED
|
Binary file
|