@wormhole-foundation/sdk-cosmwasm-core 0.5.0-alpha.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/core.d.ts +22 -0
- package/dist/cjs/core.d.ts.map +1 -0
- package/dist/cjs/core.js +87 -0
- package/dist/cjs/core.js.map +1 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +22 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/esm/core.d.ts +22 -0
- package/dist/esm/core.d.ts.map +1 -0
- package/dist/esm/core.js +83 -0
- package/dist/esm/core.js.map +1 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/index.js.map +1 -0
- package/package.json +59 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CosmWasmClient } from "@cosmjs/cosmwasm-stargate";
|
|
2
|
+
import { IndexedTx } from "@cosmjs/stargate";
|
|
3
|
+
import { Chain, ChainsConfig, Contracts, Network, VAA, WormholeCore, WormholeMessageId } from "@wormhole-foundation/sdk-connect";
|
|
4
|
+
import { AnyCosmwasmAddress, CosmwasmChains, CosmwasmPlatformType, CosmwasmUnsignedTransaction } from "@wormhole-foundation/sdk-cosmwasm";
|
|
5
|
+
export declare class CosmwasmWormholeCore<N extends Network, C extends CosmwasmChains> implements WormholeCore<N, C> {
|
|
6
|
+
readonly network: N;
|
|
7
|
+
readonly chain: C;
|
|
8
|
+
readonly rpc: CosmWasmClient;
|
|
9
|
+
readonly contracts: Contracts;
|
|
10
|
+
private coreAddress;
|
|
11
|
+
private constructor();
|
|
12
|
+
getGuardianSetIndex(): Promise<number>;
|
|
13
|
+
getMessageFee(): Promise<bigint>;
|
|
14
|
+
static fromRpc<N extends Network>(rpc: CosmWasmClient, config: ChainsConfig<N, CosmwasmPlatformType>): Promise<CosmwasmWormholeCore<N, CosmwasmChains>>;
|
|
15
|
+
publishMessage(sender: AnyCosmwasmAddress, message: Uint8Array, nonce: number, consistencyLevel: number): AsyncGenerator<CosmwasmUnsignedTransaction<N, C>>;
|
|
16
|
+
verifyMessage(sender: AnyCosmwasmAddress, vaa: VAA): AsyncGenerator<never, void, unknown>;
|
|
17
|
+
parseTransaction(txid: string): Promise<WormholeMessageId[]>;
|
|
18
|
+
parseMessages(txid: string): Promise<VAA[]>;
|
|
19
|
+
static parseWormholeMessage(chain: Chain, coreAddress: string, tx: IndexedTx): VAA;
|
|
20
|
+
static parseWormholeMessageId(chain: Chain, coreAddress: string, tx: IndexedTx): WormholeMessageId;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,OAAO,EACL,KAAK,EACL,YAAY,EACZ,SAAS,EACT,OAAO,EAEP,GAAG,EACH,YAAY,EACZ,iBAAiB,EAGlB,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EACL,kBAAkB,EAClB,cAAc,EAEd,oBAAoB,EACpB,2BAA2B,EAC5B,MAAM,mCAAmC,CAAC;AAE3C,qBAAa,oBAAoB,CAAC,CAAC,SAAS,OAAO,EAAE,CAAC,SAAS,cAAc,CAC3E,YAAW,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC;IAK3B,QAAQ,CAAC,OAAO,EAAE,CAAC;IACnB,QAAQ,CAAC,KAAK,EAAE,CAAC;IACjB,QAAQ,CAAC,GAAG,EAAE,cAAc;IAC5B,QAAQ,CAAC,SAAS,EAAE,SAAS;IAN/B,OAAO,CAAC,WAAW,CAAS;IAE5B,OAAO;IAYP,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC;IAItC,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;WAInB,OAAO,CAAC,CAAC,SAAS,OAAO,EACpC,GAAG,EAAE,cAAc,EACnB,MAAM,EAAE,YAAY,CAAC,CAAC,EAAE,oBAAoB,CAAC,GAC5C,OAAO,CAAC,oBAAoB,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC;IAQ5C,cAAc,CACnB,MAAM,EAAE,kBAAkB,EAC1B,OAAO,EAAE,UAAU,EACnB,KAAK,EAAE,MAAM,EACb,gBAAgB,EAAE,MAAM,GACvB,cAAc,CAAC,2BAA2B,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAI7C,aAAa,CAAC,MAAM,EAAE,kBAAkB,EAAE,GAAG,EAAE,GAAG;IAInD,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAM5D,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAMjD,MAAM,CAAC,oBAAoB,CAAC,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,GAAG,GAAG;IAgClF,MAAM,CAAC,sBAAsB,CAC3B,KAAK,EAAE,KAAK,EACZ,WAAW,EAAE,MAAM,EACnB,EAAE,EAAE,SAAS,GACZ,iBAAiB;CASrB"}
|
package/dist/cjs/core.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CosmwasmWormholeCore = void 0;
|
|
4
|
+
const sdk_connect_1 = require("@wormhole-foundation/sdk-connect");
|
|
5
|
+
const sdk_cosmwasm_1 = require("@wormhole-foundation/sdk-cosmwasm");
|
|
6
|
+
class CosmwasmWormholeCore {
|
|
7
|
+
network;
|
|
8
|
+
chain;
|
|
9
|
+
rpc;
|
|
10
|
+
contracts;
|
|
11
|
+
coreAddress;
|
|
12
|
+
constructor(network, chain, rpc, contracts) {
|
|
13
|
+
this.network = network;
|
|
14
|
+
this.chain = chain;
|
|
15
|
+
this.rpc = rpc;
|
|
16
|
+
this.contracts = contracts;
|
|
17
|
+
const coreAddress = this.contracts.coreBridge;
|
|
18
|
+
if (!coreAddress)
|
|
19
|
+
throw new Error(`Wormhole Token Bridge contract for domain ${chain} not found`);
|
|
20
|
+
this.coreAddress = coreAddress;
|
|
21
|
+
}
|
|
22
|
+
getGuardianSetIndex() {
|
|
23
|
+
throw new Error("Method not implemented.");
|
|
24
|
+
}
|
|
25
|
+
getMessageFee() {
|
|
26
|
+
throw new Error("Method not implemented.");
|
|
27
|
+
}
|
|
28
|
+
static async fromRpc(rpc, config) {
|
|
29
|
+
const [network, chain] = await sdk_cosmwasm_1.CosmwasmPlatform.chainFromRpc(rpc);
|
|
30
|
+
const conf = config[chain];
|
|
31
|
+
if (conf.network !== network)
|
|
32
|
+
throw new Error(`Network mismatch: ${conf.network} != ${network}`);
|
|
33
|
+
return new CosmwasmWormholeCore(network, chain, rpc, conf.contracts);
|
|
34
|
+
}
|
|
35
|
+
async *publishMessage(sender, message, nonce, consistencyLevel) {
|
|
36
|
+
throw new Error("Method not implemented.");
|
|
37
|
+
}
|
|
38
|
+
async *verifyMessage(sender, vaa) {
|
|
39
|
+
throw new Error("Not implemented.");
|
|
40
|
+
}
|
|
41
|
+
async parseTransaction(txid) {
|
|
42
|
+
const tx = await this.rpc.getTx(txid);
|
|
43
|
+
if (!tx)
|
|
44
|
+
throw new Error("No transaction found for txid: " + txid);
|
|
45
|
+
return [CosmwasmWormholeCore.parseWormholeMessageId(this.chain, this.coreAddress, tx)];
|
|
46
|
+
}
|
|
47
|
+
async parseMessages(txid) {
|
|
48
|
+
const tx = await this.rpc.getTx(txid);
|
|
49
|
+
if (!tx)
|
|
50
|
+
throw new Error("No transaction found for txid: " + txid);
|
|
51
|
+
return [CosmwasmWormholeCore.parseWormholeMessage(this.chain, this.coreAddress, tx)];
|
|
52
|
+
}
|
|
53
|
+
static parseWormholeMessage(chain, coreAddress, tx) {
|
|
54
|
+
const events = tx.events.filter((ev) => ev.type === "wasm" &&
|
|
55
|
+
ev.attributes[0].key === "_contract_address" &&
|
|
56
|
+
ev.attributes[0].value === coreAddress);
|
|
57
|
+
if (events.length === 0)
|
|
58
|
+
throw new Error("No wormhole message found in tx");
|
|
59
|
+
if (events.length > 1)
|
|
60
|
+
console.error(`Expected single message, found ${events.length}`);
|
|
61
|
+
const [wasm] = events;
|
|
62
|
+
const obj = Object.fromEntries(wasm.attributes.map((attr) => {
|
|
63
|
+
return [attr.key.split(".")[1], attr.value];
|
|
64
|
+
}));
|
|
65
|
+
return (0, sdk_connect_1.createVAA)("Uint8Array", {
|
|
66
|
+
emitterChain: chain,
|
|
67
|
+
emitterAddress: new sdk_connect_1.UniversalAddress(sdk_connect_1.encoding.hex.decode(obj["sender"])),
|
|
68
|
+
sequence: BigInt(obj["sequence"]),
|
|
69
|
+
guardianSet: 0,
|
|
70
|
+
timestamp: Number(obj["block_time"]),
|
|
71
|
+
consistencyLevel: 0,
|
|
72
|
+
nonce: Number(obj["nonce"]),
|
|
73
|
+
signatures: [],
|
|
74
|
+
payload: sdk_connect_1.encoding.hex.decode(obj["message"]),
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
static parseWormholeMessageId(chain, coreAddress, tx) {
|
|
78
|
+
const unsignedVaa = CosmwasmWormholeCore.parseWormholeMessage(chain, coreAddress, tx);
|
|
79
|
+
return {
|
|
80
|
+
chain: unsignedVaa.emitterChain,
|
|
81
|
+
emitter: unsignedVaa.emitterAddress,
|
|
82
|
+
sequence: unsignedVaa.sequence,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.CosmwasmWormholeCore = CosmwasmWormholeCore;
|
|
87
|
+
//# sourceMappingURL=core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../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;YACnC,QAAQ,EAAE,WAAW,CAAC,QAAQ;SAC/B,CAAC;IACJ,CAAC;CACF;AA1GD,oDA0GC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAMA,cAAc,QAAQ,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
const sdk_connect_1 = require("@wormhole-foundation/sdk-connect");
|
|
18
|
+
const sdk_cosmwasm_1 = require("@wormhole-foundation/sdk-cosmwasm");
|
|
19
|
+
const core_1 = require("./core");
|
|
20
|
+
(0, sdk_connect_1.registerProtocol)(sdk_cosmwasm_1._platform, "WormholeCore", core_1.CosmwasmWormholeCore);
|
|
21
|
+
__exportStar(require("./core"), exports);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kEAAoE;AACpE,oEAA8D;AAC9D,iCAA8C;AAE9C,IAAA,8BAAgB,EAAC,wBAAS,EAAE,cAAc,EAAE,2BAAoB,CAAC,CAAC;AAElE,yCAAuB"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CosmWasmClient } from "@cosmjs/cosmwasm-stargate";
|
|
2
|
+
import { IndexedTx } from "@cosmjs/stargate";
|
|
3
|
+
import { Chain, ChainsConfig, Contracts, Network, VAA, WormholeCore, WormholeMessageId } from "@wormhole-foundation/sdk-connect";
|
|
4
|
+
import { AnyCosmwasmAddress, CosmwasmChains, CosmwasmPlatformType, CosmwasmUnsignedTransaction } from "@wormhole-foundation/sdk-cosmwasm";
|
|
5
|
+
export declare class CosmwasmWormholeCore<N extends Network, C extends CosmwasmChains> implements WormholeCore<N, C> {
|
|
6
|
+
readonly network: N;
|
|
7
|
+
readonly chain: C;
|
|
8
|
+
readonly rpc: CosmWasmClient;
|
|
9
|
+
readonly contracts: Contracts;
|
|
10
|
+
private coreAddress;
|
|
11
|
+
private constructor();
|
|
12
|
+
getGuardianSetIndex(): Promise<number>;
|
|
13
|
+
getMessageFee(): Promise<bigint>;
|
|
14
|
+
static fromRpc<N extends Network>(rpc: CosmWasmClient, config: ChainsConfig<N, CosmwasmPlatformType>): Promise<CosmwasmWormholeCore<N, CosmwasmChains>>;
|
|
15
|
+
publishMessage(sender: AnyCosmwasmAddress, message: Uint8Array, nonce: number, consistencyLevel: number): AsyncGenerator<CosmwasmUnsignedTransaction<N, C>>;
|
|
16
|
+
verifyMessage(sender: AnyCosmwasmAddress, vaa: VAA): AsyncGenerator<never, void, unknown>;
|
|
17
|
+
parseTransaction(txid: string): Promise<WormholeMessageId[]>;
|
|
18
|
+
parseMessages(txid: string): Promise<VAA[]>;
|
|
19
|
+
static parseWormholeMessage(chain: Chain, coreAddress: string, tx: IndexedTx): VAA;
|
|
20
|
+
static parseWormholeMessageId(chain: Chain, coreAddress: string, tx: IndexedTx): WormholeMessageId;
|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7C,aAAa,CAAC,MAAM,EAAE,kBAAkB,EAAE,GAAG,EAAE,GAAG;IAInD,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAM5D,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAMjD,MAAM,CAAC,oBAAoB,CAAC,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,GAAG,GAAG;IAgClF,MAAM,CAAC,sBAAsB,CAC3B,KAAK,EAAE,KAAK,EACZ,WAAW,EAAE,MAAM,EACnB,EAAE,EAAE,SAAS,GACZ,iBAAiB;CASrB"}
|
package/dist/esm/core.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { UniversalAddress, createVAA, encoding, } from "@wormhole-foundation/sdk-connect";
|
|
2
|
+
import { CosmwasmPlatform, } from "@wormhole-foundation/sdk-cosmwasm";
|
|
3
|
+
export class CosmwasmWormholeCore {
|
|
4
|
+
network;
|
|
5
|
+
chain;
|
|
6
|
+
rpc;
|
|
7
|
+
contracts;
|
|
8
|
+
coreAddress;
|
|
9
|
+
constructor(network, chain, rpc, contracts) {
|
|
10
|
+
this.network = network;
|
|
11
|
+
this.chain = chain;
|
|
12
|
+
this.rpc = rpc;
|
|
13
|
+
this.contracts = contracts;
|
|
14
|
+
const coreAddress = this.contracts.coreBridge;
|
|
15
|
+
if (!coreAddress)
|
|
16
|
+
throw new Error(`Wormhole Token Bridge contract for domain ${chain} not found`);
|
|
17
|
+
this.coreAddress = coreAddress;
|
|
18
|
+
}
|
|
19
|
+
getGuardianSetIndex() {
|
|
20
|
+
throw new Error("Method not implemented.");
|
|
21
|
+
}
|
|
22
|
+
getMessageFee() {
|
|
23
|
+
throw new Error("Method not implemented.");
|
|
24
|
+
}
|
|
25
|
+
static async fromRpc(rpc, config) {
|
|
26
|
+
const [network, chain] = await CosmwasmPlatform.chainFromRpc(rpc);
|
|
27
|
+
const conf = config[chain];
|
|
28
|
+
if (conf.network !== network)
|
|
29
|
+
throw new Error(`Network mismatch: ${conf.network} != ${network}`);
|
|
30
|
+
return new CosmwasmWormholeCore(network, chain, rpc, conf.contracts);
|
|
31
|
+
}
|
|
32
|
+
async *publishMessage(sender, message, nonce, consistencyLevel) {
|
|
33
|
+
throw new Error("Method not implemented.");
|
|
34
|
+
}
|
|
35
|
+
async *verifyMessage(sender, vaa) {
|
|
36
|
+
throw new Error("Not implemented.");
|
|
37
|
+
}
|
|
38
|
+
async parseTransaction(txid) {
|
|
39
|
+
const tx = await this.rpc.getTx(txid);
|
|
40
|
+
if (!tx)
|
|
41
|
+
throw new Error("No transaction found for txid: " + txid);
|
|
42
|
+
return [CosmwasmWormholeCore.parseWormholeMessageId(this.chain, this.coreAddress, tx)];
|
|
43
|
+
}
|
|
44
|
+
async parseMessages(txid) {
|
|
45
|
+
const tx = await this.rpc.getTx(txid);
|
|
46
|
+
if (!tx)
|
|
47
|
+
throw new Error("No transaction found for txid: " + txid);
|
|
48
|
+
return [CosmwasmWormholeCore.parseWormholeMessage(this.chain, this.coreAddress, tx)];
|
|
49
|
+
}
|
|
50
|
+
static parseWormholeMessage(chain, coreAddress, tx) {
|
|
51
|
+
const events = tx.events.filter((ev) => ev.type === "wasm" &&
|
|
52
|
+
ev.attributes[0].key === "_contract_address" &&
|
|
53
|
+
ev.attributes[0].value === coreAddress);
|
|
54
|
+
if (events.length === 0)
|
|
55
|
+
throw new Error("No wormhole message found in tx");
|
|
56
|
+
if (events.length > 1)
|
|
57
|
+
console.error(`Expected single message, found ${events.length}`);
|
|
58
|
+
const [wasm] = events;
|
|
59
|
+
const obj = Object.fromEntries(wasm.attributes.map((attr) => {
|
|
60
|
+
return [attr.key.split(".")[1], attr.value];
|
|
61
|
+
}));
|
|
62
|
+
return createVAA("Uint8Array", {
|
|
63
|
+
emitterChain: chain,
|
|
64
|
+
emitterAddress: new UniversalAddress(encoding.hex.decode(obj["sender"])),
|
|
65
|
+
sequence: BigInt(obj["sequence"]),
|
|
66
|
+
guardianSet: 0,
|
|
67
|
+
timestamp: Number(obj["block_time"]),
|
|
68
|
+
consistencyLevel: 0,
|
|
69
|
+
nonce: Number(obj["nonce"]),
|
|
70
|
+
signatures: [],
|
|
71
|
+
payload: encoding.hex.decode(obj["message"]),
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
static parseWormholeMessageId(chain, coreAddress, tx) {
|
|
75
|
+
const unsignedVaa = CosmwasmWormholeCore.parseWormholeMessage(chain, coreAddress, tx);
|
|
76
|
+
return {
|
|
77
|
+
chain: unsignedVaa.emitterChain,
|
|
78
|
+
emitter: unsignedVaa.emitterAddress,
|
|
79
|
+
sequence: unsignedVaa.sequence,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../src/core.ts"],"names":[],"mappings":"AAGA,OAAO,EAKL,gBAAgB,EAIhB,SAAS,EACT,QAAQ,GACT,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EAGL,gBAAgB,GAGjB,MAAM,mCAAmC,CAAC;AAE3C,MAAM,OAAO,oBAAoB;IAMpB;IACA;IACA;IACA;IANH,WAAW,CAAS;IAE5B,YACW,OAAU,EACV,KAAQ,EACR,GAAmB,EACnB,SAAoB;QAHpB,YAAO,GAAP,OAAO,CAAG;QACV,UAAK,GAAL,KAAK,CAAG;QACR,QAAG,GAAH,GAAG,CAAgB;QACnB,cAAS,GAAT,SAAS,CAAW;QAE7B,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,UAAW,CAAC;QAC/C,IAAI,CAAC,WAAW;YACd,MAAM,IAAI,KAAK,CAAC,6CAA6C,KAAK,YAAY,CAAC,CAAC;QAElF,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IACD,mBAAmB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,EAAE,IAAI,gBAAgB,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAE,CAAC,CAAC;YACzE,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,UAAU,CAAE,CAAC;YAElC,WAAW,EAAE,CAAC;YACd,SAAS,EAAE,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;YACpC,gBAAgB,EAAE,CAAC;YACnB,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YAC3B,UAAU,EAAE,EAAE;YACd,OAAO,EAAE,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAE,CAAC;SAC9C,CAAC,CAAC;IACL,CAAC;IACD,MAAM,CAAC,sBAAsB,CAC3B,KAAY,EACZ,WAAmB,EACnB,EAAa;QAEb,MAAM,WAAW,GAAG,oBAAoB,CAAC,oBAAoB,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE,CAAC,CAAC;QAEtF,OAAO;YACL,KAAK,EAAE,WAAW,CAAC,YAAY;YAC/B,OAAO,EAAE,WAAW,CAAC,cAAc;YACnC,QAAQ,EAAE,WAAW,CAAC,QAAQ;SAC/B,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAMA,cAAc,QAAQ,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { registerProtocol } from "@wormhole-foundation/sdk-connect";
|
|
2
|
+
import { _platform } from "@wormhole-foundation/sdk-cosmwasm";
|
|
3
|
+
import { CosmwasmWormholeCore } from "./core";
|
|
4
|
+
registerProtocol(_platform, "WormholeCore", CosmwasmWormholeCore);
|
|
5
|
+
export * from "./core";
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AAE9C,gBAAgB,CAAC,SAAS,EAAE,cAAc,EAAE,oBAAoB,CAAC,CAAC;AAElE,cAAc,QAAQ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wormhole-foundation/sdk-cosmwasm-core",
|
|
3
|
+
"version": "0.5.0-alpha.0",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/wormhole-foundation/connect-sdk.git"
|
|
7
|
+
},
|
|
8
|
+
"bugs": {
|
|
9
|
+
"url": "https://github.com/wormhole-foundation/connect-sdk/issues"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/wormhole-foundation/connect-sdk#readme",
|
|
12
|
+
"directories": {
|
|
13
|
+
"test": "tests"
|
|
14
|
+
},
|
|
15
|
+
"license": "Apache-2.0",
|
|
16
|
+
"main": "./dist/cjs/index.js",
|
|
17
|
+
"module": "./dist/esm/index.js",
|
|
18
|
+
"types": "./dist/cjs/index.d.ts",
|
|
19
|
+
"author": "",
|
|
20
|
+
"description": "SDK for EVM chains, used in conjunction with @wormhole-foundation/sdk",
|
|
21
|
+
"files": [
|
|
22
|
+
"dist/cjs",
|
|
23
|
+
"dist/esm"
|
|
24
|
+
],
|
|
25
|
+
"keywords": [
|
|
26
|
+
"wormhole",
|
|
27
|
+
"sdk",
|
|
28
|
+
"typescript",
|
|
29
|
+
"connect",
|
|
30
|
+
"ethereum",
|
|
31
|
+
"moonbeam",
|
|
32
|
+
"celo",
|
|
33
|
+
"polygon",
|
|
34
|
+
"fantom",
|
|
35
|
+
"avalanche",
|
|
36
|
+
"bsc",
|
|
37
|
+
"evm"
|
|
38
|
+
],
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=16"
|
|
41
|
+
},
|
|
42
|
+
"sideEffects": true,
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build:cjs": "tsc -p ./tsconfig.cjs.json",
|
|
45
|
+
"build:esm": "tsc -p ./tsconfig.esm.json",
|
|
46
|
+
"build": "npm run build:cjs && npm run build:esm",
|
|
47
|
+
"rebuild": "npm run clean && npm run build",
|
|
48
|
+
"clean": "rm -rf ./dist && rm -rf ./.turbo",
|
|
49
|
+
"lint": "npm run prettier && eslint --fix",
|
|
50
|
+
"prettier": "prettier --write ./src"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@wormhole-foundation/sdk-connect": "0.5.0-alpha.0",
|
|
54
|
+
"@wormhole-foundation/sdk-cosmwasm": "0.5.0-alpha.0",
|
|
55
|
+
"@cosmjs/cosmwasm-stargate": "^0.32.0",
|
|
56
|
+
"@cosmjs/stargate": "^0.32.0",
|
|
57
|
+
"cosmjs-types": "^0.9.0"
|
|
58
|
+
}
|
|
59
|
+
}
|