@getpara/viem-v1-integration 1.4.3 → 1.5.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.
package/dist/cjs/index.js CHANGED
@@ -1 +1,111 @@
1
- var f=Object.create;var o=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var h=(e,n)=>{for(var a in n)o(e,a,{get:n[a],enumerable:!0})},d=(e,n,a,t)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of m(n))!x.call(e,i)&&i!==a&&o(e,i,{get:()=>n[i],enumerable:!(t=y(n,i))||t.enumerable});return e};var S=(e,n,a)=>(a=e!=null?f(p(e)):{},d(n||!e||!e.__esModule?o(a,"default",{value:e,enumerable:!0}):a,e)),C=e=>d(o({},"__esModule",{value:!0}),e);var D={};h(D,{createParaAccount:()=>g,createParaViemClient:()=>z,getViemChain:()=>w});module.exports=C(D);var s=require("viem"),b=S(require("viem/chains")),l=require("@getpara/core-sdk");function g(e,n){let a;if(n)a=e.findWalletByAddress(n,{type:["EVM"]});else{let t=e.findWalletId(void 0,{type:["EVM"]});a=e.wallets[t]}return{address:a.address,publicKey:a.publicKey||"0x",source:"custom",type:"local",signMessage:async({message:t})=>{let i=(0,s.hashMessage)(t);return`0x${(await e.signMessage({walletId:a.id,messageBase64:(0,l.hexStringToBase64)(i)})).signature}`},signTransaction:async(t,i)=>{let{serializer:r}=i||{};r||(r=s.serializeTransaction);let c=r(t,{r:"0x",s:"0x",v:BigInt(0)}),T=(await e.signTransaction({walletId:a.id,rlpEncodedTxBase64:(0,l.hexStringToBase64)(c.substring(2)),chainId:`${t.chainId}`})).signature,u=(0,l.hexToSignature)(`0x${T}`);return u.v+=BigInt(27),r(t,u)},signTypedData:async t=>`0x${(await e.signMessage({walletId:a.id,messageBase64:(0,l.hexStringToBase64)((0,s.hashTypedData)(t))})).signature}`}}function w(e){let n=Number(e);for(let a of Object.values(b))if(a.id===n)return a;throw new Error(`chain with id ${e} not found`)}function z(e,n,a){return(0,s.createWalletClient)({account:a?.noAccount?void 0:g(e),...n})}0&&(module.exports={createParaAccount,createParaViemClient,getViemChain});
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
+ });
Binary file
Binary file
package/dist/esm/index.js CHANGED
@@ -1 +1,78 @@
1
- import{createWalletClient as u,hashMessage as d,serializeTransaction as g,hashTypedData as T}from"viem";import*as f from"viem/chains";import{hexStringToBase64 as r,hexToSignature as y}from"@getpara/core-sdk";function m(a,t){let e;if(t)e=a.findWalletByAddress(t,{type:["EVM"]});else{let n=a.findWalletId(void 0,{type:["EVM"]});e=a.wallets[n]}return{address:e.address,publicKey:e.publicKey||"0x",source:"custom",type:"local",signMessage:async({message:n})=>{let s=d(n);return`0x${(await a.signMessage({walletId:e.id,messageBase64:r(s)})).signature}`},signTransaction:async(n,s)=>{let{serializer:i}=s||{};i||(i=g);let l=i(n,{r:"0x",s:"0x",v:BigInt(0)}),c=(await a.signTransaction({walletId:e.id,rlpEncodedTxBase64:r(l.substring(2)),chainId:`${n.chainId}`})).signature,o=y(`0x${c}`);return o.v+=BigInt(27),i(n,o)},signTypedData:async n=>`0x${(await a.signMessage({walletId:e.id,messageBase64:r(T(n))})).signature}`}}function V(a){let t=Number(a);for(let e of Object.values(f))if(e.id===t)return e;throw new Error(`chain with id ${a} not found`)}function v(a,t,e){return u({account:e?.noAccount?void 0:m(a),...t})}export{m as createParaAccount,v as createParaViemClient,V as getViemChain};
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
+ };
Binary file
Binary file
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@getpara/viem-v1-integration",
3
- "version": "1.4.3",
3
+ "version": "1.5.0",
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.3"
10
+ "@getpara/core-sdk": "1.5.0"
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": "1af7abd51e994057ff4afc90bd13650a47f6b26e"
37
+ "gitHead": "0e3c1401b4f1da60b288cdde7695077c9bcbc48f"
38
38
  }