@getpara/viem-v1-integration 1.2.0 → 1.3.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,17 +1 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./viemWalletClient.js"), exports);
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});
Binary file
Binary file
package/dist/esm/index.js CHANGED
@@ -1 +1 @@
1
- export * from './viemWalletClient.js';
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};
Binary file
Binary file
package/package.json CHANGED
@@ -1,16 +1,17 @@
1
1
  {
2
2
  "name": "@getpara/viem-v1-integration",
3
- "version": "1.2.0",
3
+ "version": "1.3.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.2.0"
10
+ "@getpara/core-sdk": "1.3.0"
11
11
  },
12
12
  "scripts": {
13
- "build": "yarn build:cjs && yarn build:esm && yarn build:types",
13
+ "build": "rm -rf dist && node ./scripts/build.mjs && yarn build:types",
14
+ "old-build": "yarn build:cjs && yarn build:esm && yarn build:types",
14
15
  "build:cjs": "rm -rf dist/cjs && tsc --module commonjs --outDir dist/cjs && printf '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
15
16
  "build:esm": "rm -rf dist/esm && tsc --module es6 --outDir dist/esm && printf '{\"type\":\"module\",\"sideEffects\":false}' > dist/esm/package.json",
16
17
  "build:types": "rm -rf dist/types && tsc --module es6 --declarationDir dist/types --emitDeclarationOnly --declaration"
@@ -33,5 +34,5 @@
33
34
  "types": "./dist/types/index.d.ts"
34
35
  }
35
36
  },
36
- "gitHead": "a9162c59be1456292d46c56787c1d5bf313bf24b"
37
+ "gitHead": "2d421556a0a1497abd08e18dca94f08ec3ad640b"
37
38
  }
@@ -1 +0,0 @@
1
- {"type":"commonjs"}
@@ -1,103 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.createParaViemClient = exports.getViemChain = exports.createParaAccount = void 0;
36
- const viem_1 = require("viem");
37
- const viemChains = __importStar(require("viem/chains"));
38
- const core_sdk_1 = require("@getpara/core-sdk");
39
- function createParaAccount(para, walletAddress) {
40
- let currentWallet;
41
- if (walletAddress) {
42
- currentWallet = para.findWalletByAddress(walletAddress, { type: ['EVM'] });
43
- }
44
- else {
45
- const walletId = para.findWalletId(undefined, { type: ['EVM'] });
46
- currentWallet = para.wallets[walletId];
47
- }
48
- return {
49
- address: currentWallet.address,
50
- publicKey: currentWallet.publicKey || '0x',
51
- source: 'custom',
52
- type: 'local',
53
- signMessage: ({ message }) => __awaiter(this, void 0, void 0, function* () {
54
- const hashedMessage = (0, viem_1.hashMessage)(message);
55
- const res = yield para.signMessage({ walletId: currentWallet.id, messageBase64: (0, core_sdk_1.hexStringToBase64)(hashedMessage) });
56
- const signature = res.signature;
57
- return `0x${signature}`;
58
- }),
59
- signTransaction: (transaction, args) => __awaiter(this, void 0, void 0, function* () {
60
- let { serializer } = args || {};
61
- if (!serializer) {
62
- serializer = viem_1.serializeTransaction;
63
- }
64
- const serializedTx = serializer(transaction, {
65
- r: '0x',
66
- s: '0x',
67
- v: BigInt(0),
68
- });
69
- const res = yield para.signTransaction({
70
- walletId: currentWallet.id,
71
- rlpEncodedTxBase64: (0, core_sdk_1.hexStringToBase64)(serializedTx.substring(2)),
72
- chainId: `${transaction.chainId}`,
73
- });
74
- const signature = res.signature;
75
- const formattedSig = (0, core_sdk_1.hexToSignature)(`0x${signature}`);
76
- formattedSig.v += BigInt(27);
77
- return serializer(transaction, formattedSig);
78
- }),
79
- signTypedData: (typedData) => __awaiter(this, void 0, void 0, function* () {
80
- const res = yield para.signMessage({
81
- walletId: currentWallet.id,
82
- messageBase64: (0, core_sdk_1.hexStringToBase64)((0, viem_1.hashTypedData)(typedData)),
83
- });
84
- const signature = res.signature;
85
- return `0x${signature}`;
86
- }),
87
- };
88
- }
89
- exports.createParaAccount = createParaAccount;
90
- function getViemChain(chainId) {
91
- const chainIdNum = Number(chainId);
92
- for (const chain of Object.values(viemChains)) {
93
- if (chain.id === chainIdNum) {
94
- return chain;
95
- }
96
- }
97
- throw new Error(`chain with id ${chainId} not found`);
98
- }
99
- exports.getViemChain = getViemChain;
100
- function createParaViemClient(para, params, opts) {
101
- return (0, viem_1.createWalletClient)(Object.assign({ account: (opts === null || opts === void 0 ? void 0 : opts.noAccount) ? undefined : createParaAccount(para) }, params));
102
- }
103
- exports.createParaViemClient = createParaViemClient;
@@ -1 +0,0 @@
1
- {"type":"module","sideEffects":false}
@@ -1,74 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { createWalletClient, hashMessage, serializeTransaction, hashTypedData, } from 'viem';
11
- import * as viemChains from 'viem/chains';
12
- import { hexStringToBase64, hexToSignature } from '@getpara/core-sdk';
13
- export function createParaAccount(para, walletAddress) {
14
- let currentWallet;
15
- if (walletAddress) {
16
- currentWallet = para.findWalletByAddress(walletAddress, { type: ['EVM'] });
17
- }
18
- else {
19
- const walletId = para.findWalletId(undefined, { type: ['EVM'] });
20
- currentWallet = para.wallets[walletId];
21
- }
22
- return {
23
- address: currentWallet.address,
24
- publicKey: currentWallet.publicKey || '0x',
25
- source: 'custom',
26
- type: 'local',
27
- signMessage: ({ message }) => __awaiter(this, void 0, void 0, function* () {
28
- const hashedMessage = hashMessage(message);
29
- const res = yield para.signMessage({ walletId: currentWallet.id, messageBase64: hexStringToBase64(hashedMessage) });
30
- const signature = res.signature;
31
- return `0x${signature}`;
32
- }),
33
- signTransaction: (transaction, args) => __awaiter(this, void 0, void 0, function* () {
34
- let { serializer } = args || {};
35
- if (!serializer) {
36
- serializer = serializeTransaction;
37
- }
38
- const serializedTx = serializer(transaction, {
39
- r: '0x',
40
- s: '0x',
41
- v: BigInt(0),
42
- });
43
- const res = yield para.signTransaction({
44
- walletId: currentWallet.id,
45
- rlpEncodedTxBase64: hexStringToBase64(serializedTx.substring(2)),
46
- chainId: `${transaction.chainId}`,
47
- });
48
- const signature = res.signature;
49
- const formattedSig = hexToSignature(`0x${signature}`);
50
- formattedSig.v += BigInt(27);
51
- return serializer(transaction, formattedSig);
52
- }),
53
- signTypedData: (typedData) => __awaiter(this, void 0, void 0, function* () {
54
- const res = yield para.signMessage({
55
- walletId: currentWallet.id,
56
- messageBase64: hexStringToBase64(hashTypedData(typedData)),
57
- });
58
- const signature = res.signature;
59
- return `0x${signature}`;
60
- }),
61
- };
62
- }
63
- export function getViemChain(chainId) {
64
- const chainIdNum = Number(chainId);
65
- for (const chain of Object.values(viemChains)) {
66
- if (chain.id === chainIdNum) {
67
- return chain;
68
- }
69
- }
70
- throw new Error(`chain with id ${chainId} not found`);
71
- }
72
- export function createParaViemClient(para, params, opts) {
73
- return createWalletClient(Object.assign({ account: (opts === null || opts === void 0 ? void 0 : opts.noAccount) ? undefined : createParaAccount(para) }, params));
74
- }