@getpara/viem-v1-integration 1.8.0 → 2.0.0-alpha.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 +126 -3
- package/dist/cjs/index.js.br +0 -0
- package/dist/cjs/index.js.gz +0 -0
- package/dist/esm/index.js +114 -1
- package/dist/esm/index.js.br +0 -0
- package/dist/esm/index.js.gz +0 -0
- package/package.json +3 -3
- package/dist/cjs/package.json +0 -3
- package/dist/cjs/viemWalletClient.js +0 -140
- package/dist/esm/package.json +0 -4
- package/dist/esm/viemWalletClient.js +0 -112
package/dist/cjs/index.js
CHANGED
|
@@ -1,7 +1,27 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
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
|
+
};
|
|
5
25
|
var __copyProps = (to, from, except, desc) => {
|
|
6
26
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
27
|
for (let key of __getOwnPropNames(from))
|
|
@@ -10,12 +30,115 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
10
30
|
}
|
|
11
31
|
return to;
|
|
12
32
|
};
|
|
13
|
-
var
|
|
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
|
+
));
|
|
14
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
|
+
|
|
63
|
+
// src/index.ts
|
|
15
64
|
var src_exports = {};
|
|
65
|
+
__export(src_exports, {
|
|
66
|
+
createParaAccount: () => createParaAccount,
|
|
67
|
+
createParaViemClient: () => createParaViemClient,
|
|
68
|
+
getViemChain: () => getViemChain
|
|
69
|
+
});
|
|
16
70
|
module.exports = __toCommonJS(src_exports);
|
|
17
|
-
|
|
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
|
+
}
|
|
18
139
|
// Annotate the CommonJS export names for ESM import in node:
|
|
19
140
|
0 && (module.exports = {
|
|
20
|
-
|
|
141
|
+
createParaAccount,
|
|
142
|
+
createParaViemClient,
|
|
143
|
+
getViemChain
|
|
21
144
|
});
|
|
Binary file
|
|
Binary file
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1,114 @@
|
|
|
1
|
-
|
|
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
|
+
|
|
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
|
+
};
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpara/viem-v1-integration",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-alpha.3",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
7
7
|
"typings": "dist/types/index.d.ts",
|
|
8
8
|
"sideEffects": false,
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@getpara/core-sdk": "
|
|
10
|
+
"@getpara/core-sdk": "2.0.0-alpha.3"
|
|
11
11
|
},
|
|
12
12
|
"scripts": {
|
|
13
13
|
"build": "rm -rf dist && node ./scripts/build.mjs && yarn build:types",
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"types": "./dist/types/index.d.ts"
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "77a1e04b06258842ca9c81e3db2a2b0092517659"
|
|
38
38
|
}
|
package/dist/cjs/package.json
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
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/package.json
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
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
|
-
};
|