@getpara/viem-v1-integration 1.4.3 → 1.4.4
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 +111 -1
- package/dist/cjs/index.js.br +0 -0
- package/dist/cjs/index.js.gz +0 -0
- package/dist/esm/index.js +78 -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/index.js
CHANGED
|
@@ -1 +1,111 @@
|
|
|
1
|
-
var
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/index.ts
|
|
30
|
+
var src_exports = {};
|
|
31
|
+
__export(src_exports, {
|
|
32
|
+
createParaAccount: () => createParaAccount,
|
|
33
|
+
createParaViemClient: () => createParaViemClient,
|
|
34
|
+
getViemChain: () => getViemChain
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(src_exports);
|
|
37
|
+
|
|
38
|
+
// src/viemWalletClient.ts
|
|
39
|
+
var import_viem = require("viem");
|
|
40
|
+
var viemChains = __toESM(require("viem/chains"));
|
|
41
|
+
var import_core_sdk = require("@getpara/core-sdk");
|
|
42
|
+
function createParaAccount(para, walletAddress) {
|
|
43
|
+
let currentWallet;
|
|
44
|
+
if (walletAddress) {
|
|
45
|
+
currentWallet = para.findWalletByAddress(walletAddress, { type: ["EVM"] });
|
|
46
|
+
} else {
|
|
47
|
+
const walletId = para.findWalletId(void 0, { type: ["EVM"] });
|
|
48
|
+
currentWallet = para.wallets[walletId];
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
address: currentWallet.address,
|
|
52
|
+
publicKey: currentWallet.publicKey || "0x",
|
|
53
|
+
source: "custom",
|
|
54
|
+
type: "local",
|
|
55
|
+
signMessage: async ({ message }) => {
|
|
56
|
+
const hashedMessage = (0, import_viem.hashMessage)(message);
|
|
57
|
+
const res = await para.signMessage({ walletId: currentWallet.id, messageBase64: (0, import_core_sdk.hexStringToBase64)(hashedMessage) });
|
|
58
|
+
const signature = res.signature;
|
|
59
|
+
return `0x${signature}`;
|
|
60
|
+
},
|
|
61
|
+
signTransaction: async (transaction, args) => {
|
|
62
|
+
let { serializer } = args || {};
|
|
63
|
+
if (!serializer) {
|
|
64
|
+
serializer = import_viem.serializeTransaction;
|
|
65
|
+
}
|
|
66
|
+
const serializedTx = serializer(transaction, {
|
|
67
|
+
r: "0x",
|
|
68
|
+
s: "0x",
|
|
69
|
+
v: BigInt(0)
|
|
70
|
+
});
|
|
71
|
+
const res = await para.signTransaction({
|
|
72
|
+
walletId: currentWallet.id,
|
|
73
|
+
rlpEncodedTxBase64: (0, import_core_sdk.hexStringToBase64)(serializedTx.substring(2)),
|
|
74
|
+
chainId: `${transaction.chainId}`
|
|
75
|
+
});
|
|
76
|
+
const signature = res.signature;
|
|
77
|
+
const formattedSig = (0, import_core_sdk.hexToSignature)(`0x${signature}`);
|
|
78
|
+
formattedSig.v += BigInt(27);
|
|
79
|
+
return serializer(transaction, formattedSig);
|
|
80
|
+
},
|
|
81
|
+
signTypedData: async (typedData) => {
|
|
82
|
+
const res = await para.signMessage({
|
|
83
|
+
walletId: currentWallet.id,
|
|
84
|
+
messageBase64: (0, import_core_sdk.hexStringToBase64)((0, import_viem.hashTypedData)(typedData))
|
|
85
|
+
});
|
|
86
|
+
const signature = res.signature;
|
|
87
|
+
return `0x${signature}`;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function getViemChain(chainId) {
|
|
92
|
+
const chainIdNum = Number(chainId);
|
|
93
|
+
for (const chain of Object.values(viemChains)) {
|
|
94
|
+
if (chain.id === chainIdNum) {
|
|
95
|
+
return chain;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
throw new Error(`chain with id ${chainId} not found`);
|
|
99
|
+
}
|
|
100
|
+
function createParaViemClient(para, params, opts) {
|
|
101
|
+
return (0, import_viem.createWalletClient)({
|
|
102
|
+
account: opts?.noAccount ? void 0 : createParaAccount(para),
|
|
103
|
+
...params
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
107
|
+
0 && (module.exports = {
|
|
108
|
+
createParaAccount,
|
|
109
|
+
createParaViemClient,
|
|
110
|
+
getViemChain
|
|
111
|
+
});
|
package/dist/cjs/index.js.br
CHANGED
|
Binary file
|
package/dist/cjs/index.js.gz
CHANGED
|
Binary file
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1,78 @@
|
|
|
1
|
-
|
|
1
|
+
// src/viemWalletClient.ts
|
|
2
|
+
import {
|
|
3
|
+
createWalletClient,
|
|
4
|
+
hashMessage,
|
|
5
|
+
serializeTransaction,
|
|
6
|
+
hashTypedData
|
|
7
|
+
} from "viem";
|
|
8
|
+
import * as viemChains from "viem/chains";
|
|
9
|
+
import { hexStringToBase64, hexToSignature } from "@getpara/core-sdk";
|
|
10
|
+
function createParaAccount(para, walletAddress) {
|
|
11
|
+
let currentWallet;
|
|
12
|
+
if (walletAddress) {
|
|
13
|
+
currentWallet = para.findWalletByAddress(walletAddress, { type: ["EVM"] });
|
|
14
|
+
} else {
|
|
15
|
+
const walletId = para.findWalletId(void 0, { type: ["EVM"] });
|
|
16
|
+
currentWallet = para.wallets[walletId];
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
address: currentWallet.address,
|
|
20
|
+
publicKey: currentWallet.publicKey || "0x",
|
|
21
|
+
source: "custom",
|
|
22
|
+
type: "local",
|
|
23
|
+
signMessage: async ({ message }) => {
|
|
24
|
+
const hashedMessage = hashMessage(message);
|
|
25
|
+
const res = await para.signMessage({ walletId: currentWallet.id, messageBase64: hexStringToBase64(hashedMessage) });
|
|
26
|
+
const signature = res.signature;
|
|
27
|
+
return `0x${signature}`;
|
|
28
|
+
},
|
|
29
|
+
signTransaction: async (transaction, args) => {
|
|
30
|
+
let { serializer } = args || {};
|
|
31
|
+
if (!serializer) {
|
|
32
|
+
serializer = serializeTransaction;
|
|
33
|
+
}
|
|
34
|
+
const serializedTx = serializer(transaction, {
|
|
35
|
+
r: "0x",
|
|
36
|
+
s: "0x",
|
|
37
|
+
v: BigInt(0)
|
|
38
|
+
});
|
|
39
|
+
const res = await para.signTransaction({
|
|
40
|
+
walletId: currentWallet.id,
|
|
41
|
+
rlpEncodedTxBase64: hexStringToBase64(serializedTx.substring(2)),
|
|
42
|
+
chainId: `${transaction.chainId}`
|
|
43
|
+
});
|
|
44
|
+
const signature = res.signature;
|
|
45
|
+
const formattedSig = hexToSignature(`0x${signature}`);
|
|
46
|
+
formattedSig.v += BigInt(27);
|
|
47
|
+
return serializer(transaction, formattedSig);
|
|
48
|
+
},
|
|
49
|
+
signTypedData: async (typedData) => {
|
|
50
|
+
const res = await para.signMessage({
|
|
51
|
+
walletId: currentWallet.id,
|
|
52
|
+
messageBase64: hexStringToBase64(hashTypedData(typedData))
|
|
53
|
+
});
|
|
54
|
+
const signature = res.signature;
|
|
55
|
+
return `0x${signature}`;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function getViemChain(chainId) {
|
|
60
|
+
const chainIdNum = Number(chainId);
|
|
61
|
+
for (const chain of Object.values(viemChains)) {
|
|
62
|
+
if (chain.id === chainIdNum) {
|
|
63
|
+
return chain;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
throw new Error(`chain with id ${chainId} not found`);
|
|
67
|
+
}
|
|
68
|
+
function createParaViemClient(para, params, opts) {
|
|
69
|
+
return createWalletClient({
|
|
70
|
+
account: opts?.noAccount ? void 0 : createParaAccount(para),
|
|
71
|
+
...params
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
export {
|
|
75
|
+
createParaAccount,
|
|
76
|
+
createParaViemClient,
|
|
77
|
+
getViemChain
|
|
78
|
+
};
|
package/dist/esm/index.js.br
CHANGED
|
Binary file
|
package/dist/esm/index.js.gz
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpara/viem-v1-integration",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.4",
|
|
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": "1.4.
|
|
10
|
+
"@getpara/core-sdk": "1.4.4"
|
|
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": "9a4086c4b352fff2143d3b931d288c5ebaf127fb"
|
|
38
38
|
}
|