@pushchain/core 0.1.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/README.md +241 -0
- package/package.json +30 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +5 -0
- package/src/index.js.map +1 -0
- package/src/lib/constants/abi/factoryV1.d.ts +81 -0
- package/src/lib/constants/abi/factoryV1.js +255 -0
- package/src/lib/constants/abi/factoryV1.js.map +1 -0
- package/src/lib/constants/abi/feeLocker.evm.d.ts +39 -0
- package/src/lib/constants/abi/feeLocker.evm.js +319 -0
- package/src/lib/constants/abi/feeLocker.evm.js.map +1 -0
- package/src/lib/constants/abi/feeLocker.json +230 -0
- package/src/lib/constants/abi/index.d.ts +5 -0
- package/src/lib/constants/abi/index.js +15 -0
- package/src/lib/constants/abi/index.js.map +1 -0
- package/src/lib/constants/abi/smartAccount.evm.d.ts +110 -0
- package/src/lib/constants/abi/smartAccount.evm.js +212 -0
- package/src/lib/constants/abi/smartAccount.evm.js.map +1 -0
- package/src/lib/constants/abi/smartAccount.svm.d.ts +106 -0
- package/src/lib/constants/abi/smartAccount.svm.js +209 -0
- package/src/lib/constants/abi/smartAccount.svm.js.map +1 -0
- package/src/lib/constants/chain.d.ts +32 -0
- package/src/lib/constants/chain.js +79 -0
- package/src/lib/constants/chain.js.map +1 -0
- package/src/lib/constants/enums.d.ts +30 -0
- package/src/lib/constants/enums.js +40 -0
- package/src/lib/constants/enums.js.map +1 -0
- package/src/lib/constants/index.d.ts +5 -0
- package/src/lib/constants/index.js +10 -0
- package/src/lib/constants/index.js.map +1 -0
- package/src/lib/generated/v1/tx.d.ts +83 -0
- package/src/lib/generated/v1/tx.js +616 -0
- package/src/lib/generated/v1/tx.js.map +1 -0
- package/src/lib/index.d.ts +3 -0
- package/src/lib/index.js +8 -0
- package/src/lib/index.js.map +1 -0
- package/src/lib/orchestrator/orchestrator.d.ts +63 -0
- package/src/lib/orchestrator/orchestrator.js +475 -0
- package/src/lib/orchestrator/orchestrator.js.map +1 -0
- package/src/lib/orchestrator/orchestrator.types.d.ts +44 -0
- package/src/lib/orchestrator/orchestrator.types.js +3 -0
- package/src/lib/orchestrator/orchestrator.types.js.map +1 -0
- package/src/lib/price-fetch/price-fetch.d.ts +13 -0
- package/src/lib/price-fetch/price-fetch.js +115 -0
- package/src/lib/price-fetch/price-fetch.js.map +1 -0
- package/src/lib/push-client/push-client.d.ts +47 -0
- package/src/lib/push-client/push-client.js +132 -0
- package/src/lib/push-client/push-client.js.map +1 -0
- package/src/lib/push-client/push-client.types.d.ts +5 -0
- package/src/lib/push-client/push-client.types.js +3 -0
- package/src/lib/push-client/push-client.types.js.map +1 -0
- package/src/lib/pushChain.d.ts +50 -0
- package/src/lib/pushChain.js +57 -0
- package/src/lib/pushChain.js.map +1 -0
- package/src/lib/universal/account/account.d.ts +51 -0
- package/src/lib/universal/account/account.js +114 -0
- package/src/lib/universal/account/account.js.map +1 -0
- package/src/lib/universal/account/index.d.ts +1 -0
- package/src/lib/universal/account/index.js +5 -0
- package/src/lib/universal/account/index.js.map +1 -0
- package/src/lib/universal/signer/index.d.ts +1 -0
- package/src/lib/universal/signer/index.js +5 -0
- package/src/lib/universal/signer/index.js.map +1 -0
- package/src/lib/universal/signer/signer.d.ts +40 -0
- package/src/lib/universal/signer/signer.js +138 -0
- package/src/lib/universal/signer/signer.js.map +1 -0
- package/src/lib/universal/universal.types.d.ts +52 -0
- package/src/lib/universal/universal.types.js +3 -0
- package/src/lib/universal/universal.types.js.map +1 -0
- package/src/lib/utils.d.ts +53 -0
- package/src/lib/utils.js +58 -0
- package/src/lib/utils.js.map +1 -0
- package/src/lib/vm-client/evm-client.d.ts +173 -0
- package/src/lib/vm-client/evm-client.js +244 -0
- package/src/lib/vm-client/evm-client.js.map +1 -0
- package/src/lib/vm-client/svm-client.d.ts +42 -0
- package/src/lib/vm-client/svm-client.js +136 -0
- package/src/lib/vm-client/svm-client.js.map +1 -0
- package/src/lib/vm-client/vm-client.types.d.ts +49 -0
- package/src/lib/vm-client/vm-client.types.js +3 -0
- package/src/lib/vm-client/vm-client.types.js.map +1 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PriceFetch = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const enums_1 = require("../constants/enums");
|
|
6
|
+
const chain_1 = require("../constants/chain");
|
|
7
|
+
const evm_client_1 = require("../vm-client/evm-client");
|
|
8
|
+
// Minimal ABI for Chainlink AggregatorV3Interface
|
|
9
|
+
const aggregatorV3InterfaceABI = [
|
|
10
|
+
{
|
|
11
|
+
inputs: [],
|
|
12
|
+
name: 'decimals',
|
|
13
|
+
outputs: [{ internalType: 'uint8', name: '', type: 'uint8' }],
|
|
14
|
+
stateMutability: 'view',
|
|
15
|
+
type: 'function',
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
inputs: [],
|
|
19
|
+
name: 'latestRoundData',
|
|
20
|
+
outputs: [
|
|
21
|
+
{ internalType: 'uint80', name: 'roundId', type: 'uint80' },
|
|
22
|
+
{ internalType: 'int256', name: 'answer', type: 'int256' },
|
|
23
|
+
{ internalType: 'uint256', name: 'startedAt', type: 'uint256' },
|
|
24
|
+
{ internalType: 'uint256', name: 'updatedAt', type: 'uint256' },
|
|
25
|
+
{ internalType: 'uint80', name: 'answeredInRound', type: 'uint80' },
|
|
26
|
+
],
|
|
27
|
+
stateMutability: 'view',
|
|
28
|
+
type: 'function',
|
|
29
|
+
},
|
|
30
|
+
];
|
|
31
|
+
// Configure feed addresses per chain
|
|
32
|
+
const FEED_ADDRESS = {
|
|
33
|
+
[enums_1.CHAIN.ETHEREUM_SEPOLIA]: {
|
|
34
|
+
NATIVE_USD: '0x694AA1769357215DE4FAC081bf1f309aDC325306',
|
|
35
|
+
USDC_USD: '0xA2F78ab2355fe2f984D808B5CeE7FD0A93D5270E',
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
class PriceFetch {
|
|
39
|
+
constructor(rpcUrl = {}) {
|
|
40
|
+
this.rpcUrl = rpcUrl;
|
|
41
|
+
}
|
|
42
|
+
getPrice(chain) {
|
|
43
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
const rpcUrl = this.rpcUrl[chain] || chain_1.CHAIN_INFO[chain].defaultRPC;
|
|
45
|
+
const vm = chain_1.CHAIN_INFO[chain].vm;
|
|
46
|
+
switch (vm) {
|
|
47
|
+
case enums_1.VM.EVM: {
|
|
48
|
+
const priceFeedAddress = FEED_ADDRESS[chain];
|
|
49
|
+
if (!priceFeedAddress) {
|
|
50
|
+
throw new Error(`Price Conversion functionality not available for ${chain}`);
|
|
51
|
+
}
|
|
52
|
+
const evmClient = new evm_client_1.EvmClient({ rpcUrl });
|
|
53
|
+
const ethUsdPrice = yield this.fetchPrice(priceFeedAddress.NATIVE_USD, evmClient);
|
|
54
|
+
const usdcUsdPrice = yield this.fetchPrice(priceFeedAddress.USDC_USD, evmClient);
|
|
55
|
+
return (ethUsdPrice / usdcUsdPrice) * BigInt(1e8);
|
|
56
|
+
}
|
|
57
|
+
case enums_1.VM.SVM: {
|
|
58
|
+
if (chain === enums_1.CHAIN.SOLANA_DEVNET) {
|
|
59
|
+
const url = 'https://api.coingecko.com/api/v3/simple/price?ids=solana&vs_currencies=usd';
|
|
60
|
+
const response = yield fetch(url);
|
|
61
|
+
if (!response.ok) {
|
|
62
|
+
throw new Error(`CoinGecko API error: ${response.status} ${response.statusText}`);
|
|
63
|
+
}
|
|
64
|
+
const data = (yield response.json());
|
|
65
|
+
return BigInt(data.solana.usd * 1e8);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
throw new Error('Cannot fetch price in USD');
|
|
69
|
+
}
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
default: {
|
|
73
|
+
throw new Error(`Unsupported VM ${vm}`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
*
|
|
80
|
+
* @param address Chainlink oracle feed address
|
|
81
|
+
* @param vmClient EVM client instance
|
|
82
|
+
* @returns price scaled to 8 decimals (10^8)
|
|
83
|
+
*/
|
|
84
|
+
fetchPrice(address, vmClient) {
|
|
85
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
const [, raw] = (yield vmClient.readContract({
|
|
87
|
+
address: address,
|
|
88
|
+
abi: aggregatorV3InterfaceABI,
|
|
89
|
+
functionName: 'latestRoundData',
|
|
90
|
+
args: [],
|
|
91
|
+
}));
|
|
92
|
+
const decimals = yield vmClient.readContract({
|
|
93
|
+
address: address,
|
|
94
|
+
abi: aggregatorV3InterfaceABI,
|
|
95
|
+
functionName: 'decimals',
|
|
96
|
+
});
|
|
97
|
+
const rawBigInt = BigInt(raw);
|
|
98
|
+
const actualDecimals = Number(decimals);
|
|
99
|
+
// Normalize to 8 decimals (10^8)
|
|
100
|
+
let normalizedPrice;
|
|
101
|
+
if (actualDecimals === 8) {
|
|
102
|
+
normalizedPrice = rawBigInt;
|
|
103
|
+
}
|
|
104
|
+
else if (actualDecimals > 8) {
|
|
105
|
+
normalizedPrice = rawBigInt / BigInt(Math.pow(10, (actualDecimals - 8)));
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
normalizedPrice = rawBigInt * BigInt(Math.pow(10, (8 - actualDecimals)));
|
|
109
|
+
}
|
|
110
|
+
return normalizedPrice;
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
exports.PriceFetch = PriceFetch;
|
|
115
|
+
//# sourceMappingURL=price-fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"price-fetch.js","sourceRoot":"","sources":["../../../../../../packages/core/src/lib/price-fetch/price-fetch.ts"],"names":[],"mappings":";;;;AAAA,8CAA+C;AAC/C,8CAAgD;AAChD,wDAAoD;A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uFC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { MsgDeployNMSC, MsgExecutePayload, MsgMintPush } from '../generated/v1/tx';
|
|
2
|
+
import { Any } from 'cosmjs-types/google/protobuf/any';
|
|
3
|
+
import { TxBody, TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx';
|
|
4
|
+
import { DeliverTxResponse } from '@cosmjs/stargate';
|
|
5
|
+
import { EvmClient } from '../vm-client/evm-client';
|
|
6
|
+
import { PushClientOptions } from './push-client.types';
|
|
7
|
+
export declare class PushClient extends EvmClient {
|
|
8
|
+
pushChainInfo: {
|
|
9
|
+
chainId: string;
|
|
10
|
+
vm: import("../constants/enums").VM;
|
|
11
|
+
lockerContract?: string;
|
|
12
|
+
defaultRPC: string;
|
|
13
|
+
} & {
|
|
14
|
+
denom: string;
|
|
15
|
+
tendermintRpc: string;
|
|
16
|
+
prefix: string;
|
|
17
|
+
factoryAddress: `0x${string}`;
|
|
18
|
+
pushDecimals: bigint;
|
|
19
|
+
usdcDecimals: bigint;
|
|
20
|
+
pushToUsdcNumerator: bigint;
|
|
21
|
+
pushToUsdcDenominator: bigint;
|
|
22
|
+
};
|
|
23
|
+
private signerPrivateKey;
|
|
24
|
+
constructor(clientOptions: PushClientOptions);
|
|
25
|
+
/**
|
|
26
|
+
* Converts nPUSH (1e18) to USDC (1e8), fixed rate: 1 PUSH = 0.1 USDC
|
|
27
|
+
*/
|
|
28
|
+
pushToUSDC(amount: bigint): bigint;
|
|
29
|
+
/**
|
|
30
|
+
* Converts USDC (1e8) to nPUSH (1e18), fixed rate: 1 PUSH = 0.1 USDC
|
|
31
|
+
*/
|
|
32
|
+
usdcToPush(amount: bigint): bigint;
|
|
33
|
+
createMsgDeployNMSC(input: MsgDeployNMSC): Any;
|
|
34
|
+
createMsgMintPush(input: MsgMintPush): Any;
|
|
35
|
+
createMsgExecutePayload(input: MsgExecutePayload): Any;
|
|
36
|
+
createCosmosTxBody(messages: Any[], memo?: string): Promise<TxBody>;
|
|
37
|
+
getSignerAddress(): {
|
|
38
|
+
evmAddress: `0x${string}`;
|
|
39
|
+
cosmosAddress: string;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Signs a Cosmos tx using a temporary account.
|
|
43
|
+
* In prod, signer should be passed in instead.
|
|
44
|
+
*/
|
|
45
|
+
signCosmosTx(txBody: TxBody): Promise<TxRaw>;
|
|
46
|
+
broadcastCosmosTx(txRaw: TxRaw): Promise<DeliverTxResponse>;
|
|
47
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PushClient = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const viem_1 = require("viem");
|
|
6
|
+
const tx_1 = require("../generated/v1/tx");
|
|
7
|
+
const tx_2 = require("cosmjs-types/cosmos/tx/v1beta1/tx");
|
|
8
|
+
const protobufjs_1 = require("protobufjs");
|
|
9
|
+
const proto_signing_1 = require("@cosmjs/proto-signing");
|
|
10
|
+
const stargate_1 = require("@cosmjs/stargate");
|
|
11
|
+
const crypto_1 = require("@cosmjs/crypto");
|
|
12
|
+
const tendermint_rpc_1 = require("@cosmjs/tendermint-rpc");
|
|
13
|
+
const auth_1 = require("cosmjs-types/cosmos/auth/v1beta1/auth");
|
|
14
|
+
const accounts_1 = require("viem/accounts");
|
|
15
|
+
const encoding_1 = require("@cosmjs/encoding");
|
|
16
|
+
const evm_client_1 = require("../vm-client/evm-client");
|
|
17
|
+
const chain_1 = require("../constants/chain");
|
|
18
|
+
const enums_1 = require("../constants/enums");
|
|
19
|
+
class PushClient extends evm_client_1.EvmClient {
|
|
20
|
+
constructor(clientOptions) {
|
|
21
|
+
super(clientOptions);
|
|
22
|
+
this.pushChainInfo =
|
|
23
|
+
clientOptions.network === enums_1.NETWORK.MAINNET
|
|
24
|
+
? chain_1.PUSH_CHAIN_INFO[enums_1.CHAIN.PUSH_MAINNET]
|
|
25
|
+
: clientOptions.network === enums_1.NETWORK.TESTNET
|
|
26
|
+
? chain_1.PUSH_CHAIN_INFO[enums_1.CHAIN.PUSH_TESTNET]
|
|
27
|
+
: chain_1.PUSH_CHAIN_INFO[enums_1.CHAIN.PUSH_LOCALNET];
|
|
28
|
+
this.signerPrivateKey = (0, accounts_1.generatePrivateKey)();
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Converts nPUSH (1e18) to USDC (1e8), fixed rate: 1 PUSH = 0.1 USDC
|
|
32
|
+
*/
|
|
33
|
+
pushToUSDC(amount) {
|
|
34
|
+
return ((amount * this.pushChainInfo.pushToUsdcNumerator) /
|
|
35
|
+
this.pushChainInfo.pushToUsdcDenominator);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Converts USDC (1e8) to nPUSH (1e18), fixed rate: 1 PUSH = 0.1 USDC
|
|
39
|
+
*/
|
|
40
|
+
usdcToPush(amount) {
|
|
41
|
+
return ((amount * this.pushChainInfo.pushToUsdcDenominator) /
|
|
42
|
+
this.pushChainInfo.pushToUsdcNumerator);
|
|
43
|
+
}
|
|
44
|
+
// --- Msg Creators ---
|
|
45
|
+
createMsgDeployNMSC(input) {
|
|
46
|
+
return {
|
|
47
|
+
typeUrl: '/crosschain.v1.MsgDeployNMSC',
|
|
48
|
+
value: tx_1.MsgDeployNMSC.encode(tx_1.MsgDeployNMSC.fromPartial(input)).finish(),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
createMsgMintPush(input) {
|
|
52
|
+
return {
|
|
53
|
+
typeUrl: '/crosschain.v1.MsgMintPush',
|
|
54
|
+
value: tx_1.MsgMintPush.encode(tx_1.MsgMintPush.fromPartial(input)).finish(),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
createMsgExecutePayload(input) {
|
|
58
|
+
return {
|
|
59
|
+
typeUrl: '/crosschain.v1.MsgExecutePayload',
|
|
60
|
+
value: tx_1.MsgExecutePayload.encode(tx_1.MsgExecutePayload.fromPartial(input)).finish(),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
// --- Tx Builder ---
|
|
64
|
+
createCosmosTxBody(messages, memo) {
|
|
65
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
return tx_2.TxBody.fromPartial({ messages, memo });
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
// --- Tx Signer ---
|
|
70
|
+
getSignerAddress() {
|
|
71
|
+
const account = (0, accounts_1.privateKeyToAccount)(this.signerPrivateKey);
|
|
72
|
+
return {
|
|
73
|
+
evmAddress: account.address,
|
|
74
|
+
cosmosAddress: (0, encoding_1.toBech32)(this.pushChainInfo.prefix, (0, viem_1.hexToBytes)(account.address)),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Signs a Cosmos tx using a temporary account.
|
|
79
|
+
* In prod, signer should be passed in instead.
|
|
80
|
+
*/
|
|
81
|
+
signCosmosTx(txBody) {
|
|
82
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
const account = (0, accounts_1.privateKeyToAccount)(this.signerPrivateKey);
|
|
84
|
+
const sender = (0, encoding_1.toBech32)(this.pushChainInfo.prefix, (0, viem_1.hexToBytes)(account.address));
|
|
85
|
+
// 🔍 Get on-chain account info
|
|
86
|
+
const tmClient = yield tendermint_rpc_1.Tendermint34Client.connect(this.pushChainInfo.tendermintRpc);
|
|
87
|
+
const status = yield tmClient.status();
|
|
88
|
+
const chainId = status.nodeInfo.network;
|
|
89
|
+
const queryClient = stargate_1.QueryClient.withExtensions(tmClient, stargate_1.setupAuthExtension);
|
|
90
|
+
let baseAccount = null;
|
|
91
|
+
try {
|
|
92
|
+
const accountResp = yield queryClient.auth.account(sender);
|
|
93
|
+
baseAccount = auth_1.BaseAccount.decode(accountResp.value);
|
|
94
|
+
}
|
|
95
|
+
catch (err) {
|
|
96
|
+
// Ignore
|
|
97
|
+
}
|
|
98
|
+
// 📦 Encode pubkey
|
|
99
|
+
const uncompressedPubKey = (0, viem_1.hexToBytes)(account.publicKey);
|
|
100
|
+
const compressedPubKey = crypto_1.Secp256k1.compressPubkey(uncompressedPubKey);
|
|
101
|
+
const pubkeyEncoded = {
|
|
102
|
+
typeUrl: '/os.crypto.v1.ethsecp256k1.PubKey',
|
|
103
|
+
value: protobufjs_1.Writer.create().uint32(10).bytes(compressedPubKey).finish(),
|
|
104
|
+
};
|
|
105
|
+
const authInfoBytes = (0, proto_signing_1.makeAuthInfoBytes)([
|
|
106
|
+
{
|
|
107
|
+
pubkey: pubkeyEncoded,
|
|
108
|
+
sequence: baseAccount ? Number(baseAccount.sequence) : 0,
|
|
109
|
+
},
|
|
110
|
+
], [], 100000000000, // gas
|
|
111
|
+
undefined, undefined);
|
|
112
|
+
const txBodyBytes = tx_2.TxBody.encode(txBody).finish();
|
|
113
|
+
const signDoc = (0, proto_signing_1.makeSignDoc)(txBodyBytes, authInfoBytes, chainId, baseAccount ? Number(baseAccount.accountNumber) : 0);
|
|
114
|
+
const digest = (0, viem_1.keccak256)(tx_2.SignDoc.encode(signDoc).finish());
|
|
115
|
+
const signature = yield account.sign({ hash: digest });
|
|
116
|
+
return tx_2.TxRaw.fromPartial({
|
|
117
|
+
bodyBytes: txBodyBytes,
|
|
118
|
+
authInfoBytes,
|
|
119
|
+
signatures: [(0, viem_1.hexToBytes)(signature)],
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
broadcastCosmosTx(txRaw) {
|
|
124
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
const client = yield stargate_1.StargateClient.connect(this.pushChainInfo.tendermintRpc);
|
|
126
|
+
const result = yield client.broadcastTx(tx_2.TxRaw.encode(txRaw).finish());
|
|
127
|
+
return result;
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
exports.PushClient = PushClient;
|
|
132
|
+
//# sourceMappingURL=push-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"push-client.js","sourceRoot":"","sources":["../../../../../../packages/core/src/lib/push-client/push-client.ts"],"names":[],"mappings":";;;;AAAA,+BAA6C;AAC7C,2CAI4B;AAE5B,0DAA2E;AAC3E,2CAAoC;AACpC,yDAAuE;AACvE,+CAK0B;AAC1B,2CAA2C;AAC3C,2DAA4D;AAC5D,gEAAoE;AACpE,4CAAwE;AACxE,+CAA4C;AAC5C,wDAAoD;AAEpD,8CAAqD;AACrD,8CAAoD;AAEpD,MAAa,UAAW,SAAQ,sBAAS;IAGvC,YAAY,aAAgC;QAC1C,KAAK,CAAC,aAAa,CAAC,CAAC;QACrB,IAAI,CAAC,aAAa;YAChB,aAAa,CAAC,OAAO,KAAK,eAAO,CAAC,OAAO;gBACvC,CAAC,CAAC,uBAAe,CAAC,aAAK,CAAC,YAAY,CAAC;gBACrC,CAAC,CAAC,aAAa,CAAC,OAAO,KAAK,eAAO,CAAC,OAAO;oBAC3C,CAAC,CAAC,uBAAe,CAAC,aAAK,CAAC,YAAY,CAAC;oBACrC,CAAC,CAAC,uBAAe,CAAC,aAAK,CAAC,aAAa,CAAC,CAAC;QAE3C,IAAI,CAAC,gBAAgB,GAAG,IAAA,6BAAkB,GAAE,CAAC;IAC/C,CAAC;IAED;;OAEG;IACH,UAAU,CAAC,MAAc;QACvB,OAAO,CACL,CAAC,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,mBAAmB,CAAC;YACjD,IAAI,CAAC,aAAa,CAAC,qBAAqB,CACzC,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,UAAU,CAAC,MAAc;QACvB,OAAO,CACL,CAAC,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,qBAAqB,CAAC;YACnD,IAAI,CAAC,aAAa,CAAC,mBAAmB,CACvC,CAAC;IACJ,CAAC;IAED,uBAAuB;IAEvB,mBAAmB,CAAC,KAAoB;QACtC,OAAO;YACL,OAAO,EAAE,8BAA8B;YACvC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AC,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC;YACnD,MAAM,OAAO,GAAG,IAAA,2BAAW,EACzB,WAAW,EACX,aAAa,EACb,OAAO,EACP,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CACpD,CAAC;YAEF,MAAM,MAAM,GAAG,IAAA,gBAAS,EAAC,YAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;YAC3D,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;YAEvD,OAAO,UAAK,CAAC,WAAW,CAAC;gBACvB,SAAS,EAAE,WAAW;gBACtB,aAAa;gBACb,UAAU,EAAE,CAAC,IAAA,iBAAU,EAAC,SAAS,CAAC,CAAC;aACpC,CAAC,CAAC;QACL,CAAC;KAAA;IAEK,iBAAiB,CAAC,KAAY;;YAClC,MAAM,MAAM,GAAG,MAAM,yBAAc,CAAC,OAAO,CACzC,IAAI,CAAC,aAAa,CAAC,aAAa,CACjC,CAAC;YACF,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,UAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;YACtE,OAAO,MAAM,CAAC;QAChB,CAAC;KAAA;CACF;AA1JD,gCA0JC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"push-client.types.js","sourceRoot":"","sources":["../../../../../../packages/core/src/lib/push-client/push-client.types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { CHAIN, NETWORK } from './constants/enums';
|
|
2
|
+
import { Orchestrator } from './orchestrator/orchestrator';
|
|
3
|
+
import { UniversalSigner } from './universal/universal.types';
|
|
4
|
+
import { Utils } from './utils';
|
|
5
|
+
import * as viem from 'viem';
|
|
6
|
+
/**
|
|
7
|
+
* @class PushChain
|
|
8
|
+
*
|
|
9
|
+
* Entry point to interact with Push Chain in your application.
|
|
10
|
+
* Provides access to cross-chain execution, utilities, and signer abstraction.
|
|
11
|
+
*/
|
|
12
|
+
export declare class PushChain {
|
|
13
|
+
/**
|
|
14
|
+
* @static
|
|
15
|
+
* Utility functions for encoding, hashing, and data formatting.
|
|
16
|
+
*/
|
|
17
|
+
static utils: typeof Utils;
|
|
18
|
+
/**
|
|
19
|
+
* @static
|
|
20
|
+
* Exposes viem utilities to the SDK user for convenience.
|
|
21
|
+
*/
|
|
22
|
+
static viem: typeof viem;
|
|
23
|
+
private orchestartor;
|
|
24
|
+
/**
|
|
25
|
+
* Executes a transaction on Push Chain
|
|
26
|
+
*/
|
|
27
|
+
sendTransaction: Orchestrator['execute'];
|
|
28
|
+
/**
|
|
29
|
+
* Computes the NMSC address for the universal signer on Push
|
|
30
|
+
*/
|
|
31
|
+
getNMSCAddress: Orchestrator['getNMSCAddress'];
|
|
32
|
+
private constructor();
|
|
33
|
+
/**
|
|
34
|
+
* @method initialize
|
|
35
|
+
* Initializes the PushChain SDK with a universal signer and optional config.
|
|
36
|
+
*
|
|
37
|
+
* @param universalSigner
|
|
38
|
+
* @param options - Optional settings to configure the SDK instance.
|
|
39
|
+
* - network: PushChain network to target (e.g., TESTNET, MAINNET).
|
|
40
|
+
* - rpcUrl: Custom RPC URLs mapped by chain IDs.
|
|
41
|
+
* - printTraces: Whether to print internal trace logs for debugging.
|
|
42
|
+
*
|
|
43
|
+
* @returns An initialized instance of PushChain.
|
|
44
|
+
*/
|
|
45
|
+
static initialize: (universalSigner: UniversalSigner, options?: {
|
|
46
|
+
network?: NETWORK;
|
|
47
|
+
rpcUrl?: Partial<Record<CHAIN, string>>;
|
|
48
|
+
printTraces?: boolean;
|
|
49
|
+
}) => Promise<PushChain>;
|
|
50
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.PushChain = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const enums_1 = require("./constants/enums");
|
|
7
|
+
const orchestrator_1 = require("./orchestrator/orchestrator");
|
|
8
|
+
const signer_1 = require("./universal/signer");
|
|
9
|
+
const utils_1 = require("./utils");
|
|
10
|
+
const viem = tslib_1.__importStar(require("viem"));
|
|
11
|
+
/**
|
|
12
|
+
* @class PushChain
|
|
13
|
+
*
|
|
14
|
+
* Entry point to interact with Push Chain in your application.
|
|
15
|
+
* Provides access to cross-chain execution, utilities, and signer abstraction.
|
|
16
|
+
*/
|
|
17
|
+
class PushChain {
|
|
18
|
+
constructor(orchestartor) {
|
|
19
|
+
this.orchestartor = orchestartor;
|
|
20
|
+
// Ensure context is preserved when methods are called externally
|
|
21
|
+
this.sendTransaction = this.orchestartor.execute.bind(this.orchestartor);
|
|
22
|
+
this.getNMSCAddress = this.orchestartor.getNMSCAddress.bind(this.orchestartor);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.PushChain = PushChain;
|
|
26
|
+
_a = PushChain;
|
|
27
|
+
/**
|
|
28
|
+
* @static
|
|
29
|
+
* Utility functions for encoding, hashing, and data formatting.
|
|
30
|
+
*/
|
|
31
|
+
PushChain.utils = utils_1.Utils;
|
|
32
|
+
/**
|
|
33
|
+
* @static
|
|
34
|
+
* Exposes viem utilities to the SDK user for convenience.
|
|
35
|
+
*/
|
|
36
|
+
PushChain.viem = viem;
|
|
37
|
+
/**
|
|
38
|
+
* @method initialize
|
|
39
|
+
* Initializes the PushChain SDK with a universal signer and optional config.
|
|
40
|
+
*
|
|
41
|
+
* @param universalSigner
|
|
42
|
+
* @param options - Optional settings to configure the SDK instance.
|
|
43
|
+
* - network: PushChain network to target (e.g., TESTNET, MAINNET).
|
|
44
|
+
* - rpcUrl: Custom RPC URLs mapped by chain IDs.
|
|
45
|
+
* - printTraces: Whether to print internal trace logs for debugging.
|
|
46
|
+
*
|
|
47
|
+
* @returns An initialized instance of PushChain.
|
|
48
|
+
*/
|
|
49
|
+
PushChain.initialize = (universalSigner, options) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
50
|
+
const orchestartor = new orchestrator_1.Orchestrator(
|
|
51
|
+
/**
|
|
52
|
+
* Ensures the signer conforms to the UniversalSigner interface.
|
|
53
|
+
*/
|
|
54
|
+
(0, signer_1.createUniversalSigner)(universalSigner), (options === null || options === void 0 ? void 0 : options.network) || enums_1.NETWORK.TESTNET, (options === null || options === void 0 ? void 0 : options.rpcUrl) || {}, (options === null || options === void 0 ? void 0 : options.printTraces) || false);
|
|
55
|
+
return new _a(orchestartor);
|
|
56
|
+
});
|
|
57
|
+
//# sourceMappingURL=pushChain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pushChain.js","sourceRoot":"","sources":["../../../../../packages/core/src/lib/pushChain.ts"],"names":[],"mappings":";;;;;AAAA,6CAAmD;AACnD,8DAA2D;AAC3D,+CAA2D;AAE3D,mCAAgC;AAChC,mDAA6B;AAE7B;;;;;GAKG;AACH,MAAa,SAAS;IAyBpB,YAAoB,YAA0B;QAC5C,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QAEjC,iEAAiE;QACjE,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACzE,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,YAAY,CAAC,cAAc,CAAC,IAAI,CACzD,IAAI,CAAC,YAAY,CAClB,CAAC;IACJ,CAAC;;AAjCH,8BAkEC;;AAjEC;;;GAGG;AACW,eAAK,GAAG,aAAK,AAAR,CAAS;AAE5B;;;GAGG;AACI,cAAI,GAAG,IAAI,AAAP,CAAQ;AAwBnB;;;;;;;;;;;GAWG;AACI,oBAAU,GAAG,CAClB,eAAgC,EAChC,OAIC,EACD,EAAE;IACF,MAAM,YAAY,GAAG,IAAI,2BAAY;IACnC;;OAEG;IACH,IAAA,8BAAqB,EAAC,eAAe,CAAC,EACtC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,KAAI,eAAO,CAAC,OAAO,EACnC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,KAAI,EAAE,EACrB,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,KAAI,KAAK,CAC9B,CAAC;IACF,OAAO,IAAI,EAAS,CAAC,YAAY,CAAC,CAAC;AACrC,CAAC,CAAA,AAlBgB,CAkBf"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { UniversalAccount } from '../universal.types';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a `UniversalAccount` object for working with SDK.
|
|
4
|
+
* Useful for signing or tracking account-specific state in a cross-chain context.
|
|
5
|
+
*
|
|
6
|
+
* @param {Object} params - The account configuration object.
|
|
7
|
+
* @param {string} params.address - The account address.
|
|
8
|
+
* @param {CHAIN} params.chain - The chain the account is associated with.
|
|
9
|
+
* @returns {UniversalAccount} A normalized account object with chain and chainId set.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const account = createUniversalAccount({ address: "0xabc..." });
|
|
13
|
+
* // → { chain: "ETHEREUM_SEPOLIA", chainId: "11155111", address: "0xAbC..." }
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const solanaAcc = createUniversalAccount({
|
|
17
|
+
* address: "solana123",
|
|
18
|
+
* chain: CHAIN.SOLANA_TESTNET
|
|
19
|
+
* });
|
|
20
|
+
* // → { chain: "SOLANA_TESTNET", chainId: "...", address: "solana123" }
|
|
21
|
+
*/
|
|
22
|
+
export declare function createUniversalAccount({ chain, address, }: UniversalAccount): UniversalAccount;
|
|
23
|
+
/**
|
|
24
|
+
* Converts a UniversalAccount into a CAIP-10 style address string.
|
|
25
|
+
*
|
|
26
|
+
* Format: `namespace:chainId:address`
|
|
27
|
+
* Namespace is derived from the chain's VM type using VM_NAMESPACE.
|
|
28
|
+
*
|
|
29
|
+
* @param {UniversalAccount} account - The account to convert.
|
|
30
|
+
* @returns {string} A CAIP-10 formatted string.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* Utils.account.toChainAgnostic({
|
|
34
|
+
* chain: CHAIN.ETHEREUM_SEPOLIA,
|
|
35
|
+
* address: '0xabc'
|
|
36
|
+
* })
|
|
37
|
+
* // → 'eip155:11155111:0xabc'
|
|
38
|
+
*/
|
|
39
|
+
export declare function toChainAgnostic(account: UniversalAccount): string;
|
|
40
|
+
/**
|
|
41
|
+
* Converts a CAIP-10 formatted string into a UniversalAccount.
|
|
42
|
+
*
|
|
43
|
+
* @param {string} caip - A CAIP-10 address string (e.g., 'eip155:1:0xabc...').
|
|
44
|
+
* @returns {UniversalAccount} The resolved account.
|
|
45
|
+
* @throws {Error} If the CAIP string is invalid or unsupported.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* Utils.account.toUniversal('eip155:11155111:0xabc...')
|
|
49
|
+
* // → { chain: CHAIN.ETHEREUM_SEPOLIA, address: '0xabc...' }
|
|
50
|
+
*/
|
|
51
|
+
export declare function toUniversal(caip: string): UniversalAccount;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createUniversalAccount = createUniversalAccount;
|
|
4
|
+
exports.toChainAgnostic = toChainAgnostic;
|
|
5
|
+
exports.toUniversal = toUniversal;
|
|
6
|
+
const viem_1 = require("viem");
|
|
7
|
+
const chain_1 = require("../../constants/chain");
|
|
8
|
+
const enums_1 = require("../../constants/enums");
|
|
9
|
+
/**
|
|
10
|
+
* Formats a blockchain address based on the virtual machine type of the provided chain.
|
|
11
|
+
*
|
|
12
|
+
* - For EVM chains, it converts the address to its checksummed format.
|
|
13
|
+
* - For non-EVM chains (e.g., Solana), the original address is returned as-is. - Can be changed in future
|
|
14
|
+
* @param {CHAIN} chain - A fully qualified chain identifier (e.g., CHAIN.ETHEREUM_MAINNET).
|
|
15
|
+
* @param {string} address - The raw address string to normalize.
|
|
16
|
+
* @returns {string} - A VM-compliant formatted address.
|
|
17
|
+
*
|
|
18
|
+
* @throws {Error} If an invalid EVM address is provided.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // EVM address gets checksummed
|
|
22
|
+
* formatAddress(CHAIN.ETHEREUM_SEPOLIA, "0xabcd...") // → "0xAbCd..."
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // Non-EVM address is returned as-is
|
|
26
|
+
* formatAddress(CHAIN.SOLANA_DEVNET, "solanaAddress123") // → "solanaAddress123"
|
|
27
|
+
*/
|
|
28
|
+
function formatAddress(chain, address) {
|
|
29
|
+
if (chain_1.CHAIN_INFO[chain].vm === enums_1.VM.EVM) {
|
|
30
|
+
try {
|
|
31
|
+
return (0, viem_1.getAddress)(address.toLowerCase());
|
|
32
|
+
}
|
|
33
|
+
catch (_a) {
|
|
34
|
+
throw new Error('Invalid EVM address format');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return address;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Creates a `UniversalAccount` object for working with SDK.
|
|
41
|
+
* Useful for signing or tracking account-specific state in a cross-chain context.
|
|
42
|
+
*
|
|
43
|
+
* @param {Object} params - The account configuration object.
|
|
44
|
+
* @param {string} params.address - The account address.
|
|
45
|
+
* @param {CHAIN} params.chain - The chain the account is associated with.
|
|
46
|
+
* @returns {UniversalAccount} A normalized account object with chain and chainId set.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* const account = createUniversalAccount({ address: "0xabc..." });
|
|
50
|
+
* // → { chain: "ETHEREUM_SEPOLIA", chainId: "11155111", address: "0xAbC..." }
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* const solanaAcc = createUniversalAccount({
|
|
54
|
+
* address: "solana123",
|
|
55
|
+
* chain: CHAIN.SOLANA_TESTNET
|
|
56
|
+
* });
|
|
57
|
+
* // → { chain: "SOLANA_TESTNET", chainId: "...", address: "solana123" }
|
|
58
|
+
*/
|
|
59
|
+
function createUniversalAccount({ chain, address, }) {
|
|
60
|
+
return {
|
|
61
|
+
chain,
|
|
62
|
+
address: formatAddress(chain, address),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Converts a UniversalAccount into a CAIP-10 style address string.
|
|
67
|
+
*
|
|
68
|
+
* Format: `namespace:chainId:address`
|
|
69
|
+
* Namespace is derived from the chain's VM type using VM_NAMESPACE.
|
|
70
|
+
*
|
|
71
|
+
* @param {UniversalAccount} account - The account to convert.
|
|
72
|
+
* @returns {string} A CAIP-10 formatted string.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* Utils.account.toChainAgnostic({
|
|
76
|
+
* chain: CHAIN.ETHEREUM_SEPOLIA,
|
|
77
|
+
* address: '0xabc'
|
|
78
|
+
* })
|
|
79
|
+
* // → 'eip155:11155111:0xabc'
|
|
80
|
+
*/
|
|
81
|
+
function toChainAgnostic(account) {
|
|
82
|
+
const { chain, address } = account;
|
|
83
|
+
const chainMeta = chain_1.CHAIN_INFO[chain];
|
|
84
|
+
if (!chainMeta) {
|
|
85
|
+
throw new Error(`Unrecognized chain: ${chain}`);
|
|
86
|
+
}
|
|
87
|
+
const { chainId, vm } = chainMeta;
|
|
88
|
+
const namespace = chain_1.VM_NAMESPACE[vm];
|
|
89
|
+
return `${namespace}:${chainId}:${formatAddress(chain, address)}`;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Converts a CAIP-10 formatted string into a UniversalAccount.
|
|
93
|
+
*
|
|
94
|
+
* @param {string} caip - A CAIP-10 address string (e.g., 'eip155:1:0xabc...').
|
|
95
|
+
* @returns {UniversalAccount} The resolved account.
|
|
96
|
+
* @throws {Error} If the CAIP string is invalid or unsupported.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* Utils.account.toUniversal('eip155:11155111:0xabc...')
|
|
100
|
+
* // → { chain: CHAIN.ETHEREUM_SEPOLIA, address: '0xabc...' }
|
|
101
|
+
*/
|
|
102
|
+
function toUniversal(caip) {
|
|
103
|
+
var _a, _b;
|
|
104
|
+
const [namespace, chainId, rawAddress] = caip.split(':');
|
|
105
|
+
const chain = ((_b = (_a = Object.entries(chain_1.CHAIN_INFO).find(([, info]) => info.chainId === chainId && chain_1.VM_NAMESPACE[info.vm] === namespace)) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : null);
|
|
106
|
+
if (!chain) {
|
|
107
|
+
throw new Error(`Unsupported or unknown CAIP address: ${caip}`);
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
chain,
|
|
111
|
+
address: formatAddress(chain, rawAddress),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=account.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account.js","sourceRoot":"","sources":["../../../../../../../packages/core/src/lib/universal/account/account.ts"],"names":[],"mappings":";;AAuDA,wDAQC;AAkBD,0CAYC;AAaD,kCAgBC;AA1HD,+BAAkC;AAClC,iDAAiE;AACjE,iDAAkD;AAGlD;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAS,aAAa,CAAC,KAAY,EAAE,OAAe;IAClD,IAAI,kBAAU,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,UAAE,CAAC,GAAG,EAAE,CAAC;QACpC,IAAI,CAAC;YACH,OAAO,IAAA,iBAAU,EAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;QAC3C,CAAC;QAAC,WAAM,CAAC;YACP,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AA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CAAC;IAED,OAAO;QACL,KAAK;QACL,OAAO,EAAE,aAAa,CAAC,KAAK,EAAE,UAAU,CAAC;KAC1C,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './account';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/core/src/lib/universal/account/index.ts"],"names":[],"mappings":";;;AAAA,oDAA0B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './signer';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/core/src/lib/universal/signer/index.ts"],"names":[],"mappings":";;;AAAA,mDAAyB"}
|