@wormhole-foundation/sdk-stacks-core 3.8.7
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 +33 -0
- package/dist/cjs/core.d.ts.map +1 -0
- package/dist/cjs/core.js +160 -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/cjs/package.json +1 -0
- package/dist/esm/core.d.ts +33 -0
- package/dist/esm/core.d.ts.map +1 -0
- package/dist/esm/core.js +156 -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 +82 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { StacksNetwork } from "@stacks/network";
|
|
2
|
+
import { ChainsConfig } from "@wormhole-foundation/sdk-connect";
|
|
3
|
+
import { Contracts } from "@wormhole-foundation/sdk-connect";
|
|
4
|
+
import { AccountAddress, Network, TxHash, UnsignedTransaction, VAA, WormholeCore, WormholeMessageId } from "@wormhole-foundation/sdk-connect";
|
|
5
|
+
import { StacksChains, StacksPlatformType } from '@wormhole-foundation/sdk-stacks';
|
|
6
|
+
export type StacksWormholeMessageId = WormholeMessageId & {
|
|
7
|
+
emitterPrincipal: string;
|
|
8
|
+
payload: string;
|
|
9
|
+
};
|
|
10
|
+
export declare class StacksWormholeCore<N extends Network, C extends StacksChains> implements WormholeCore<N, C> {
|
|
11
|
+
readonly network: N;
|
|
12
|
+
readonly chain: C;
|
|
13
|
+
readonly provider: StacksNetwork;
|
|
14
|
+
readonly contracts: Contracts;
|
|
15
|
+
static readonly STATE_CONTRACT_NAME: string;
|
|
16
|
+
static readonly PROXY_CONTRACT_NAME: string;
|
|
17
|
+
readonly coreContractAddress: string;
|
|
18
|
+
constructor(network: N, chain: C, provider: StacksNetwork, contracts: Contracts);
|
|
19
|
+
getMessageFee(): Promise<bigint>;
|
|
20
|
+
getGuardianSetIndex(): Promise<number>;
|
|
21
|
+
getGuardianSet(index: number): Promise<WormholeCore.GuardianSet>;
|
|
22
|
+
publishMessage(sender: AccountAddress<C>, message: string | Uint8Array, nonce: number, consistencyLevel: number): AsyncGenerator<UnsignedTransaction<N, C>, any, any>;
|
|
23
|
+
verifyMessage(sender: AccountAddress<C>, vaa: VAA): AsyncGenerator<any, any, any>;
|
|
24
|
+
parseTransaction(txid: TxHash): Promise<StacksWormholeMessageId[]>;
|
|
25
|
+
parseMessages(txid: TxHash): Promise<VAA<"Uint8Array">[]>;
|
|
26
|
+
contractAddress(): string;
|
|
27
|
+
contractName(): Promise<string>;
|
|
28
|
+
isActiveDeployment(contractName: string): Promise<boolean>;
|
|
29
|
+
private readonly;
|
|
30
|
+
private getActiveCoreContract;
|
|
31
|
+
static fromRpc<N extends Network>(provider: StacksNetwork, config: ChainsConfig<N, StacksPlatformType>): Promise<StacksWormholeCore<N, StacksChains>>;
|
|
32
|
+
}
|
|
33
|
+
//# 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,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAEhE,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,EAAE,mBAAmB,EAAE,GAAG,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAC9I,OAAO,EAAE,YAAY,EAAkB,kBAAkB,EAAqB,MAAM,iCAAiC,CAAC;AAEtH,MAAM,MAAM,uBAAuB,GAAG,iBAAi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E,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC;IAIzD,eAAe,IAAI,MAAM;IAInB,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC;IAM/B,kBAAkB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;YAKlD,QAAQ;YAaR,qBAAqB;WAKtB,OAAO,CAAC,CAAC,SAAS,OAAO,EACpC,QAAQ,EAAE,aAAa,EACvB,MAAM,EAAE,YAAY,CAAC,CAAC,EAAE,kBAAkB,CAAC,GAC1C,OAAO,CAAC,kBAAkB,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC;CAWhD"}
|
package/dist/cjs/core.js
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StacksWormholeCore = void 0;
|
|
4
|
+
const transactions_1 = require("@stacks/transactions");
|
|
5
|
+
const sdk_connect_1 = require("@wormhole-foundation/sdk-connect");
|
|
6
|
+
const sdk_stacks_1 = require("@wormhole-foundation/sdk-stacks");
|
|
7
|
+
class StacksWormholeCore {
|
|
8
|
+
network;
|
|
9
|
+
chain;
|
|
10
|
+
provider;
|
|
11
|
+
contracts;
|
|
12
|
+
static STATE_CONTRACT_NAME = "wormhole-core-state";
|
|
13
|
+
static PROXY_CONTRACT_NAME = "wormhole-core-proxy-v2";
|
|
14
|
+
coreContractAddress;
|
|
15
|
+
constructor(network, chain, provider, contracts) {
|
|
16
|
+
this.network = network;
|
|
17
|
+
this.chain = chain;
|
|
18
|
+
this.provider = provider;
|
|
19
|
+
this.contracts = contracts;
|
|
20
|
+
const coreAddress = this.contracts.coreBridge;
|
|
21
|
+
if (!coreAddress)
|
|
22
|
+
throw new Error('Core bridge address not found');
|
|
23
|
+
this.coreContractAddress = coreAddress;
|
|
24
|
+
}
|
|
25
|
+
async getMessageFee() {
|
|
26
|
+
const activeCoreContract = await this.getActiveCoreContract();
|
|
27
|
+
const res = await this.readonly('get-message-fee', [
|
|
28
|
+
transactions_1.Cl.address(activeCoreContract)
|
|
29
|
+
], StacksWormholeCore.PROXY_CONTRACT_NAME);
|
|
30
|
+
return (0, transactions_1.cvToValue)(res.value);
|
|
31
|
+
}
|
|
32
|
+
async getGuardianSetIndex() {
|
|
33
|
+
const res = await this.readonly('get-active-guardian-set', []);
|
|
34
|
+
const value = (0, transactions_1.cvToValue)(res.value);
|
|
35
|
+
return Number(value['set-id'].value);
|
|
36
|
+
}
|
|
37
|
+
async getGuardianSet(index) {
|
|
38
|
+
const res = await this.readonly('get-active-guardian-set', []);
|
|
39
|
+
const value = (0, transactions_1.cvToValue)(res.value);
|
|
40
|
+
const activeGuardianSetIndex = Number(value['set-id'].value);
|
|
41
|
+
if (index !== activeGuardianSetIndex) {
|
|
42
|
+
throw new Error('Only latest guardian set is supported in Stacks');
|
|
43
|
+
}
|
|
44
|
+
const guardians = value['guardians'].value.map((v) => v.value['compressed-public-key'].value);
|
|
45
|
+
return {
|
|
46
|
+
expiry: 0n,
|
|
47
|
+
index: activeGuardianSetIndex,
|
|
48
|
+
keys: guardians
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
async *publishMessage(sender, message, nonce, consistencyLevel) {
|
|
52
|
+
const activeCoreContract = await this.getActiveCoreContract();
|
|
53
|
+
const tx = {
|
|
54
|
+
contractName: StacksWormholeCore.PROXY_CONTRACT_NAME,
|
|
55
|
+
contractAddress: this.coreContractAddress,
|
|
56
|
+
functionName: 'post-message',
|
|
57
|
+
functionArgs: [
|
|
58
|
+
transactions_1.Cl.address(activeCoreContract),
|
|
59
|
+
transactions_1.Cl.buffer(message instanceof Uint8Array ? message : new TextEncoder().encode(message)),
|
|
60
|
+
transactions_1.Cl.uint(nonce),
|
|
61
|
+
transactions_1.Cl.some(transactions_1.Cl.uint(consistencyLevel))
|
|
62
|
+
],
|
|
63
|
+
postConditionMode: transactions_1.PostConditionMode.Allow,
|
|
64
|
+
};
|
|
65
|
+
yield {
|
|
66
|
+
transaction: tx,
|
|
67
|
+
network: this.network,
|
|
68
|
+
chain: this.chain,
|
|
69
|
+
description: 'StacksWormholeCore.publishMessage',
|
|
70
|
+
parallelizable: false,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
// read-only in stacks, failing if we call this function signing a transaction instead of using a call
|
|
74
|
+
async *verifyMessage(sender, vaa) {
|
|
75
|
+
const res = await this.readonly('parse-and-verify-vaa', [transactions_1.Cl.buffer((0, sdk_connect_1.serialize)(vaa))]);
|
|
76
|
+
if (res.value.type !== 'ok') {
|
|
77
|
+
throw new Error(`Failed to verify VAA: ${res.value.data}`);
|
|
78
|
+
}
|
|
79
|
+
return res.value.data;
|
|
80
|
+
}
|
|
81
|
+
async parseTransaction(txid) {
|
|
82
|
+
const apiUrl = `${this.provider.client.baseUrl}/extended/v1/tx/${txid}`;
|
|
83
|
+
const res = await fetch(apiUrl);
|
|
84
|
+
let data = await res.json();
|
|
85
|
+
let retries = 0;
|
|
86
|
+
while ((!data || !data?.tx_status || data?.tx_status === 'pending') && retries < 10) {
|
|
87
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
88
|
+
data = await fetch(apiUrl).then(res => res.json());
|
|
89
|
+
retries++;
|
|
90
|
+
}
|
|
91
|
+
if (data.tx_status !== 'success') {
|
|
92
|
+
return [];
|
|
93
|
+
}
|
|
94
|
+
if (!data) {
|
|
95
|
+
return [];
|
|
96
|
+
}
|
|
97
|
+
const events = data.events;
|
|
98
|
+
const whEvent = events.filter((e) => {
|
|
99
|
+
return e.event_type === "smart_contract_log"
|
|
100
|
+
&& e.contract_log?.contract_id?.includes(StacksWormholeCore.STATE_CONTRACT_NAME)
|
|
101
|
+
&& e.contract_log?.topic === "print"
|
|
102
|
+
&& e.contract_log?.value?.repr?.includes("post-message");
|
|
103
|
+
});
|
|
104
|
+
const parsedEvents = whEvent.map((e) => (0, transactions_1.deserializeCV)(e.contract_log?.value?.hex));
|
|
105
|
+
if (!parsedEvents) {
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
const eventValues = parsedEvents.map((e) => e.value?.data?.value);
|
|
109
|
+
if (!eventValues) {
|
|
110
|
+
return [];
|
|
111
|
+
}
|
|
112
|
+
return Promise.resolve(eventValues.map((e) => {
|
|
113
|
+
return {
|
|
114
|
+
chain: this.chain,
|
|
115
|
+
emitter: new sdk_connect_1.UniversalAddress(e['emitter'].value),
|
|
116
|
+
sequence: e['sequence'].value,
|
|
117
|
+
emitterPrincipal: e['emitter-principal'].value,
|
|
118
|
+
payload: e['payload'].value,
|
|
119
|
+
};
|
|
120
|
+
}));
|
|
121
|
+
}
|
|
122
|
+
parseMessages(txid) {
|
|
123
|
+
throw new Error("Method not implemented.");
|
|
124
|
+
}
|
|
125
|
+
contractAddress() {
|
|
126
|
+
return this.coreContractAddress;
|
|
127
|
+
}
|
|
128
|
+
async contractName() {
|
|
129
|
+
const activeContract = await this.getActiveCoreContract();
|
|
130
|
+
const contractName = activeContract.split('.')[1];
|
|
131
|
+
return contractName;
|
|
132
|
+
}
|
|
133
|
+
async isActiveDeployment(contractName) {
|
|
134
|
+
const res = await this.readonly('is-active-deployment', [], contractName);
|
|
135
|
+
return (0, transactions_1.cvToValue)(res);
|
|
136
|
+
}
|
|
137
|
+
async readonly(functionName, functionArgs, contractName) {
|
|
138
|
+
return (0, transactions_1.fetchCallReadOnlyFunction)({
|
|
139
|
+
contractName: contractName ?? (await this.contractName()),
|
|
140
|
+
contractAddress: this.coreContractAddress,
|
|
141
|
+
functionName,
|
|
142
|
+
functionArgs,
|
|
143
|
+
client: {
|
|
144
|
+
baseUrl: this.provider.client.baseUrl
|
|
145
|
+
},
|
|
146
|
+
senderAddress: sdk_stacks_1.StacksZeroAddress
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
async getActiveCoreContract() {
|
|
150
|
+
const res = await this.readonly('get-active-wormhole-core-contract', [], StacksWormholeCore.STATE_CONTRACT_NAME);
|
|
151
|
+
return (0, transactions_1.cvToValue)(res).value;
|
|
152
|
+
}
|
|
153
|
+
static async fromRpc(provider, config) {
|
|
154
|
+
const [network, chain] = await sdk_stacks_1.StacksPlatform.chainFromRpc(provider);
|
|
155
|
+
const conf = config[chain];
|
|
156
|
+
return new StacksWormholeCore(network, chain, provider, conf.contracts);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
exports.StacksWormholeCore = StacksWormholeCore;
|
|
160
|
+
//# sourceMappingURL=core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../src/core.ts"],"names":[],"mappings":";;;AACA,uDAAkH;AAElH,kEAA+E;AAG/E,gEAAsH;AAOtH,MAAa,kBAAkB;IAQlB;IACA;IACA;IACA;IATX,MAAM,CAAU,mBAAmB,GAAW,qBAAqB,CAAC;IACpE,MAAM,CAAU,mBAAmB,GAAW,wBAAwB,CAAC;IAE9D,mBAAmB,CAAS;IAErC,YACW,OAAU,EACV,KAAQ,EACR,QAAuB,EACvB,SAAoB;QAHpB,YAAO,GAAP,OAAO,CAAG;QACV,UAAK,GAAL,KAAK,CAAG;QACR,aAAQ,GAAR,QAAQ,CAAe;QACvB,cAAS,GAAT,SAAS,CAAW;QAE7B,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC;QAC9C,IAAI,CAAC,WAAW;YAAE,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;QACnE,IAAI,CAAC,mBAAmB,GAAG,WAAW,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,aAAa;QACjB,MAAM,kBAAkB,GAAG,MAAM,IAAI,CAAC,qBAAqB,EAAE,CAAA;QAE7D,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,QAAQ,CAC7B,iBAAiB,EACjB;YACE,iBAAE,CAAC,OAAO,CAAC,kBAAkB,CAAC;SAC/B,EACD,kBAAkB,CAA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ding = (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_stacks_1 = require("@wormhole-foundation/sdk-stacks");
|
|
19
|
+
const core_js_1 = require("./core.js");
|
|
20
|
+
(0, sdk_connect_1.registerProtocol)(sdk_stacks_1._platform, 'WormholeCore', core_js_1.StacksWormholeCore);
|
|
21
|
+
__exportStar(require("./core.js"), 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,gEAA4D;AAC5D,uCAA+C;AAE/C,IAAA,8BAAgB,EAAC,sBAAS,EAAE,cAAc,EAAE,4BAAkB,CAAC,CAAC;AAEhE,4CAA0B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { StacksNetwork } from "@stacks/network";
|
|
2
|
+
import { ChainsConfig } from "@wormhole-foundation/sdk-connect";
|
|
3
|
+
import { Contracts } from "@wormhole-foundation/sdk-connect";
|
|
4
|
+
import { AccountAddress, Network, TxHash, UnsignedTransaction, VAA, WormholeCore, WormholeMessageId } from "@wormhole-foundation/sdk-connect";
|
|
5
|
+
import { StacksChains, StacksPlatformType } from '@wormhole-foundation/sdk-stacks';
|
|
6
|
+
export type StacksWormholeMessageId = WormholeMessageId & {
|
|
7
|
+
emitterPrincipal: string;
|
|
8
|
+
payload: string;
|
|
9
|
+
};
|
|
10
|
+
export declare class StacksWormholeCore<N extends Network, C extends StacksChains> implements WormholeCore<N, C> {
|
|
11
|
+
readonly network: N;
|
|
12
|
+
readonly chain: C;
|
|
13
|
+
readonly provider: StacksNetwork;
|
|
14
|
+
readonly contracts: Contracts;
|
|
15
|
+
static readonly STATE_CONTRACT_NAME: string;
|
|
16
|
+
static readonly PROXY_CONTRACT_NAME: string;
|
|
17
|
+
readonly coreContractAddress: string;
|
|
18
|
+
constructor(network: N, chain: C, provider: StacksNetwork, contracts: Contracts);
|
|
19
|
+
getMessageFee(): Promise<bigint>;
|
|
20
|
+
getGuardianSetIndex(): Promise<number>;
|
|
21
|
+
getGuardianSet(index: number): Promise<WormholeCore.GuardianSet>;
|
|
22
|
+
publishMessage(sender: AccountAddress<C>, message: string | Uint8Array, nonce: number, consistencyLevel: number): AsyncGenerator<UnsignedTransaction<N, C>, any, any>;
|
|
23
|
+
verifyMessage(sender: AccountAddress<C>, vaa: VAA): AsyncGenerator<any, any, any>;
|
|
24
|
+
parseTransaction(txid: TxHash): Promise<StacksWormholeMessageId[]>;
|
|
25
|
+
parseMessages(txid: TxHash): Promise<VAA<"Uint8Array">[]>;
|
|
26
|
+
contractAddress(): string;
|
|
27
|
+
contractName(): Promise<string>;
|
|
28
|
+
isActiveDeployment(contractName: string): Promise<boolean>;
|
|
29
|
+
private readonly;
|
|
30
|
+
private getActiveCoreContract;
|
|
31
|
+
static fromRpc<N extends Network>(provider: StacksNetwork, config: ChainsConfig<N, Stac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AAC;IAYhC,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC;IAMtC,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,WAAW,CAAC;IAiB/D,cAAc,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,GAAG,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,GAAG,cAAc,CAAC,mBAAmB,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC;IAwBrK,aAAa,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,GAAG,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;IAQlF,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,uBAAuB,EAAE,CAAC;IA+CxE,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC;IAIzD,eAAe,IAAI,MAAM;IAInB,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC;IAM/B,kBAAkB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;YAKlD,QAAQ;YAaR,qBAAqB;WAKtB,OAAO,CAAC,CAAC,SAAS,OAAO,EACpC,QAAQ,EAAE,aAAa,EACvB,MAAM,EAAE,YAAY,CAAC,CAAC,EAAE,kBAAkB,CAAC,GAC1C,OAAO,CAAC,kBAAkB,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC;CAWhD"}
|
package/dist/esm/core.js
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { Cl, cvToValue, deserializeCV, fetchCallReadOnlyFunction, PostConditionMode } from "@stacks/transactions";
|
|
2
|
+
import { serialize, UniversalAddress } from "@wormhole-foundation/sdk-connect";
|
|
3
|
+
import { StacksPlatform, StacksZeroAddress } from '@wormhole-foundation/sdk-stacks';
|
|
4
|
+
export class StacksWormholeCore {
|
|
5
|
+
network;
|
|
6
|
+
chain;
|
|
7
|
+
provider;
|
|
8
|
+
contracts;
|
|
9
|
+
static STATE_CONTRACT_NAME = "wormhole-core-state";
|
|
10
|
+
static PROXY_CONTRACT_NAME = "wormhole-core-proxy-v2";
|
|
11
|
+
coreContractAddress;
|
|
12
|
+
constructor(network, chain, provider, contracts) {
|
|
13
|
+
this.network = network;
|
|
14
|
+
this.chain = chain;
|
|
15
|
+
this.provider = provider;
|
|
16
|
+
this.contracts = contracts;
|
|
17
|
+
const coreAddress = this.contracts.coreBridge;
|
|
18
|
+
if (!coreAddress)
|
|
19
|
+
throw new Error('Core bridge address not found');
|
|
20
|
+
this.coreContractAddress = coreAddress;
|
|
21
|
+
}
|
|
22
|
+
async getMessageFee() {
|
|
23
|
+
const activeCoreContract = await this.getActiveCoreContract();
|
|
24
|
+
const res = await this.readonly('get-message-fee', [
|
|
25
|
+
Cl.address(activeCoreContract)
|
|
26
|
+
], StacksWormholeCore.PROXY_CONTRACT_NAME);
|
|
27
|
+
return cvToValue(res.value);
|
|
28
|
+
}
|
|
29
|
+
async getGuardianSetIndex() {
|
|
30
|
+
const res = await this.readonly('get-active-guardian-set', []);
|
|
31
|
+
const value = cvToValue(res.value);
|
|
32
|
+
return Number(value['set-id'].value);
|
|
33
|
+
}
|
|
34
|
+
async getGuardianSet(index) {
|
|
35
|
+
const res = await this.readonly('get-active-guardian-set', []);
|
|
36
|
+
const value = cvToValue(res.value);
|
|
37
|
+
const activeGuardianSetIndex = Number(value['set-id'].value);
|
|
38
|
+
if (index !== activeGuardianSetIndex) {
|
|
39
|
+
throw new Error('Only latest guardian set is supported in Stacks');
|
|
40
|
+
}
|
|
41
|
+
const guardians = value['guardians'].value.map((v) => v.value['compressed-public-key'].value);
|
|
42
|
+
return {
|
|
43
|
+
expiry: 0n,
|
|
44
|
+
index: activeGuardianSetIndex,
|
|
45
|
+
keys: guardians
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
async *publishMessage(sender, message, nonce, consistencyLevel) {
|
|
49
|
+
const activeCoreContract = await this.getActiveCoreContract();
|
|
50
|
+
const tx = {
|
|
51
|
+
contractName: StacksWormholeCore.PROXY_CONTRACT_NAME,
|
|
52
|
+
contractAddress: this.coreContractAddress,
|
|
53
|
+
functionName: 'post-message',
|
|
54
|
+
functionArgs: [
|
|
55
|
+
Cl.address(activeCoreContract),
|
|
56
|
+
Cl.buffer(message instanceof Uint8Array ? message : new TextEncoder().encode(message)),
|
|
57
|
+
Cl.uint(nonce),
|
|
58
|
+
Cl.some(Cl.uint(consistencyLevel))
|
|
59
|
+
],
|
|
60
|
+
postConditionMode: PostConditionMode.Allow,
|
|
61
|
+
};
|
|
62
|
+
yield {
|
|
63
|
+
transaction: tx,
|
|
64
|
+
network: this.network,
|
|
65
|
+
chain: this.chain,
|
|
66
|
+
description: 'StacksWormholeCore.publishMessage',
|
|
67
|
+
parallelizable: false,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
// read-only in stacks, failing if we call this function signing a transaction instead of using a call
|
|
71
|
+
async *verifyMessage(sender, vaa) {
|
|
72
|
+
const res = await this.readonly('parse-and-verify-vaa', [Cl.buffer(serialize(vaa))]);
|
|
73
|
+
if (res.value.type !== 'ok') {
|
|
74
|
+
throw new Error(`Failed to verify VAA: ${res.value.data}`);
|
|
75
|
+
}
|
|
76
|
+
return res.value.data;
|
|
77
|
+
}
|
|
78
|
+
async parseTransaction(txid) {
|
|
79
|
+
const apiUrl = `${this.provider.client.baseUrl}/extended/v1/tx/${txid}`;
|
|
80
|
+
const res = await fetch(apiUrl);
|
|
81
|
+
let data = await res.json();
|
|
82
|
+
let retries = 0;
|
|
83
|
+
while ((!data || !data?.tx_status || data?.tx_status === 'pending') && retries < 10) {
|
|
84
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
85
|
+
data = await fetch(apiUrl).then(res => res.json());
|
|
86
|
+
retries++;
|
|
87
|
+
}
|
|
88
|
+
if (data.tx_status !== 'success') {
|
|
89
|
+
return [];
|
|
90
|
+
}
|
|
91
|
+
if (!data) {
|
|
92
|
+
return [];
|
|
93
|
+
}
|
|
94
|
+
const events = data.events;
|
|
95
|
+
const whEvent = events.filter((e) => {
|
|
96
|
+
return e.event_type === "smart_contract_log"
|
|
97
|
+
&& e.contract_log?.contract_id?.includes(StacksWormholeCore.STATE_CONTRACT_NAME)
|
|
98
|
+
&& e.contract_log?.topic === "print"
|
|
99
|
+
&& e.contract_log?.value?.repr?.includes("post-message");
|
|
100
|
+
});
|
|
101
|
+
const parsedEvents = whEvent.map((e) => deserializeCV(e.contract_log?.value?.hex));
|
|
102
|
+
if (!parsedEvents) {
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
const eventValues = parsedEvents.map((e) => e.value?.data?.value);
|
|
106
|
+
if (!eventValues) {
|
|
107
|
+
return [];
|
|
108
|
+
}
|
|
109
|
+
return Promise.resolve(eventValues.map((e) => {
|
|
110
|
+
return {
|
|
111
|
+
chain: this.chain,
|
|
112
|
+
emitter: new UniversalAddress(e['emitter'].value),
|
|
113
|
+
sequence: e['sequence'].value,
|
|
114
|
+
emitterPrincipal: e['emitter-principal'].value,
|
|
115
|
+
payload: e['payload'].value,
|
|
116
|
+
};
|
|
117
|
+
}));
|
|
118
|
+
}
|
|
119
|
+
parseMessages(txid) {
|
|
120
|
+
throw new Error("Method not implemented.");
|
|
121
|
+
}
|
|
122
|
+
contractAddress() {
|
|
123
|
+
return this.coreContractAddress;
|
|
124
|
+
}
|
|
125
|
+
async contractName() {
|
|
126
|
+
const activeContract = await this.getActiveCoreContract();
|
|
127
|
+
const contractName = activeContract.split('.')[1];
|
|
128
|
+
return contractName;
|
|
129
|
+
}
|
|
130
|
+
async isActiveDeployment(contractName) {
|
|
131
|
+
const res = await this.readonly('is-active-deployment', [], contractName);
|
|
132
|
+
return cvToValue(res);
|
|
133
|
+
}
|
|
134
|
+
async readonly(functionName, functionArgs, contractName) {
|
|
135
|
+
return fetchCallReadOnlyFunction({
|
|
136
|
+
contractName: contractName ?? (await this.contractName()),
|
|
137
|
+
contractAddress: this.coreContractAddress,
|
|
138
|
+
functionName,
|
|
139
|
+
functionArgs,
|
|
140
|
+
client: {
|
|
141
|
+
baseUrl: this.provider.client.baseUrl
|
|
142
|
+
},
|
|
143
|
+
senderAddress: StacksZeroAddress
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
async getActiveCoreContract() {
|
|
147
|
+
const res = await this.readonly('get-active-wormhole-core-contract', [], StacksWormholeCore.STATE_CONTRACT_NAME);
|
|
148
|
+
return cvToValue(res).value;
|
|
149
|
+
}
|
|
150
|
+
static async fromRpc(provider, config) {
|
|
151
|
+
const [network, chain] = await StacksPlatform.chainFromRpc(provider);
|
|
152
|
+
const conf = config[chain];
|
|
153
|
+
return new StacksWormholeCore(network, chain, provider, conf.contracts);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../src/core.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,aAAa,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAElH,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAG/E,OAAO,EAAgB,cAAc,EAAsB,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAOtH,MAAM,OAAO,kBAAkB;IAQlB;IACA;IACA;IACA;IATX,MAAM,CAAU,mBAAmB,GAAW,qBAAqB,CAAC;IACpE,MAAM,CAAU,mBAAmB,GAAW,wBAAwB,CAAC;IAE9D,mBAAmB,CAAS;IAErC,YACW,OAAU,EACV,KAAQ,EACR,QAAuB,EACvB,SAAoB;QAHpB,YAAO,GAAP,OAAO,CAAG;QACV,UAAK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AK,CAAC,GAAG,MAAM,cAAc,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;QACrE,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAE,CAAC;QAE5B,OAAO,IAAI,kBAAkB,CAC3B,OAAY,EACZ,KAAK,EACL,QAAQ,EACR,IAAI,CAAC,SAAS,CACf,CAAC;IACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAMA,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { registerProtocol } from "@wormhole-foundation/sdk-connect";
|
|
2
|
+
import { _platform } from "@wormhole-foundation/sdk-stacks";
|
|
3
|
+
import { StacksWormholeCore } from "./core.js";
|
|
4
|
+
registerProtocol(_platform, 'WormholeCore', StacksWormholeCore);
|
|
5
|
+
export * from "./core.js";
|
|
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,iCAAiC,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAE/C,gBAAgB,CAAC,SAAS,EAAE,cAAc,EAAE,kBAAkB,CAAC,CAAC;AAEhE,cAAc,WAAW,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wormhole-foundation/sdk-stacks-core",
|
|
3
|
+
"version": "3.8.7",
|
|
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
|
+
"types": "./dist/cjs/index.d.ts",
|
|
18
|
+
"module": "./dist/esm/index.js",
|
|
19
|
+
"description": "SDK for Stacks chains, used in conjunction with @wormhole-foundation/sdk",
|
|
20
|
+
"files": [
|
|
21
|
+
"dist/esm",
|
|
22
|
+
"dist/cjs"
|
|
23
|
+
],
|
|
24
|
+
"keywords": [
|
|
25
|
+
"wormhole",
|
|
26
|
+
"sdk",
|
|
27
|
+
"typescript",
|
|
28
|
+
"connect",
|
|
29
|
+
"ethereum",
|
|
30
|
+
"moonbeam",
|
|
31
|
+
"celo",
|
|
32
|
+
"polygon",
|
|
33
|
+
"fantom",
|
|
34
|
+
"avalanche",
|
|
35
|
+
"bsc",
|
|
36
|
+
"evm",
|
|
37
|
+
"stacks"
|
|
38
|
+
],
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=16"
|
|
41
|
+
},
|
|
42
|
+
"sideEffects": [
|
|
43
|
+
"./dist/cjs/index.js",
|
|
44
|
+
"./dist/esm/index.js"
|
|
45
|
+
],
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build:cjs": "tsc -p ./tsconfig.cjs.json && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
|
|
48
|
+
"build:esm": "tsc -p ./tsconfig.esm.json",
|
|
49
|
+
"build": "npm run build:esm && npm run build:cjs",
|
|
50
|
+
"rebuild": "npm run clean && npm run build",
|
|
51
|
+
"clean": "rm -rf ./dist && rm -rf ./.turbo",
|
|
52
|
+
"lint": "npm run prettier && eslint --fix ./src --ext .ts",
|
|
53
|
+
"prettier": "prettier --write ./src"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@wormhole-foundation/sdk-connect": "3.8.7",
|
|
57
|
+
"@wormhole-foundation/sdk-stacks": "3.8.7"
|
|
58
|
+
},
|
|
59
|
+
"type": "module",
|
|
60
|
+
"exports": {
|
|
61
|
+
".": {
|
|
62
|
+
"react-native": {
|
|
63
|
+
"import": "./dist/esm/index.js",
|
|
64
|
+
"require": "./dist/cjs/index.js",
|
|
65
|
+
"types": "./dist/cjs/index.d.ts",
|
|
66
|
+
"default": "./dist/cjs/index.js"
|
|
67
|
+
},
|
|
68
|
+
"import": {
|
|
69
|
+
"types": "./dist/esm/index.d.ts",
|
|
70
|
+
"default": "./dist/esm/index.js"
|
|
71
|
+
},
|
|
72
|
+
"require": {
|
|
73
|
+
"types": "./dist/cjs/index.d.ts",
|
|
74
|
+
"default": "./dist/cjs/index.js"
|
|
75
|
+
},
|
|
76
|
+
"default": {
|
|
77
|
+
"types": "./dist/cjs/index.d.ts",
|
|
78
|
+
"default": "./dist/cjs/index.js"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|