spydk: initial release
Change-Id: I002d99bee0fffa4e9f489746824f8fd123d52476
This commit is contained in:
parent
05425a96df
commit
3a71550dea
|
@ -44,4 +44,5 @@ COPY --from=go-build /app/node/pkg/proto pkg/proto
|
|||
|
||||
FROM scratch AS node-export
|
||||
COPY --from=node-build /app/sdk/js/src/proto sdk/js/src/proto
|
||||
COPY --from=node-build /app/spydk/js/src/proto spydk/js/src/proto
|
||||
COPY --from=node-build /app/explorer/src/proto explorer/src/proto
|
||||
|
|
|
@ -9,7 +9,6 @@ plugins:
|
|||
- env=browser
|
||||
- forceLong=string
|
||||
- outputClientImpl=grpc-web
|
||||
- explorer/src/proto
|
||||
- name: tsproto
|
||||
out: sdk/js/src/proto
|
||||
path: tools/node_modules/.bin/protoc-gen-ts_proto
|
||||
|
@ -19,4 +18,12 @@ plugins:
|
|||
- env=browser
|
||||
- forceLong=string
|
||||
- outputClientImpl=grpc-web
|
||||
- bridge_ui/src/proto
|
||||
- name: tsproto
|
||||
out: spydk/js/src/proto
|
||||
path: tools/node_modules/.bin/protoc-gen-ts_proto
|
||||
opt:
|
||||
- paths=source_relative
|
||||
- esModuleInterop=true
|
||||
- env=node
|
||||
- forceLong=string
|
||||
- outputServices=grpc-js
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.js
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# ethereum contracts
|
||||
/contracts
|
||||
/src/ethers-contracts
|
||||
|
||||
# tsproto output
|
||||
/src/proto
|
||||
|
||||
# build
|
||||
/lib
|
|
@ -0,0 +1,5 @@
|
|||
# Changelog
|
||||
|
||||
## 0.0.1
|
||||
|
||||
Initial release
|
|
@ -0,0 +1,13 @@
|
|||
Copyright 2020 Wormhole Project Contributors
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
|
@ -0,0 +1,21 @@
|
|||
# Wormhole Spy SDK
|
||||
|
||||
> Note: This is a pre-alpha release and in active development. Function names and signatures are subject to change.
|
||||
|
||||
Wormhole Spy service SDK for use with [@certusone/wormhole-sdk](https://www.npmjs.com/package/@certusone/wormhole-sdk)
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
import {
|
||||
createSpyRPCServiceClient,
|
||||
subscribeSignedVAA,
|
||||
} from "@certusone/wormhole-spydk";
|
||||
const client = createSpyRPCServiceClient(SPY_SERVICE_HOST);
|
||||
const stream = await subscribeSignedVAA(client, {});
|
||||
stream.on("data", ({ vaaBytes }) => {
|
||||
console.log(vaaBytes);
|
||||
});
|
||||
```
|
||||
|
||||
Also see [integration tests](https://github.com/certusone/wormhole/blob/dev.v2/spydk/js/src/__tests__/integration.ts)
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"transform": {
|
||||
"^.+\\.(t|j)sx?$": "ts-jest"
|
||||
},
|
||||
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
|
||||
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"]
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,51 @@
|
|||
{
|
||||
"name": "@certusone/wormhole-spydk",
|
||||
"version": "0.0.1",
|
||||
"description": "Wormhole Spy service SDK for use with @certusone/wormhole-sdk",
|
||||
"homepage": "https://wormholenetwork.com",
|
||||
"main": "./lib/cjs/index.js",
|
||||
"module": "./lib/esm/index.js",
|
||||
"files": [
|
||||
"lib/"
|
||||
],
|
||||
"repository": "https://github.com/certusone/wormhole/tree/dev.v2/spydk/js",
|
||||
"scripts": {
|
||||
"build-lib": "tsc -p tsconfig.json && tsc -p tsconfig-cjs.json",
|
||||
"build-all": "npm run build-lib",
|
||||
"test": "jest --config jestconfig.json --verbose",
|
||||
"build": "npm run build-all",
|
||||
"format": "echo \"disabled: prettier --write \"src/**/*.ts\"\"",
|
||||
"lint": "tslint -p tsconfig.json",
|
||||
"prepare": "npm run build",
|
||||
"prepublishOnly": "echo \"disabled: npm test && npm run lint\"",
|
||||
"preversion": "npm run lint",
|
||||
"version": "npm run format && git add -A src",
|
||||
"postversion": "git push && git push --tags"
|
||||
},
|
||||
"keywords": [
|
||||
"wormhole",
|
||||
"bridge",
|
||||
"token",
|
||||
"sdk",
|
||||
"spy"
|
||||
],
|
||||
"author": "certusone",
|
||||
"license": "Apache-2.0",
|
||||
"devDependencies": {
|
||||
"@certusone/wormhole-sdk": "^0.1.1",
|
||||
"@solana/web3.js": "^1.31.0",
|
||||
"@types/jest": "^27.0.2",
|
||||
"@types/node": "^16.6.1",
|
||||
"ethers": "^5.4.4",
|
||||
"jest": "^27.3.1",
|
||||
"prettier": "^2.3.2",
|
||||
"ts-jest": "^27.0.7",
|
||||
"tslint": "^6.1.3",
|
||||
"tslint-config-prettier": "^1.18.0",
|
||||
"typescript": "^4.3.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@grpc/grpc-js": "^1.4.4",
|
||||
"protobufjs": "^6.11.2"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
import { attestFromSolana } from "@certusone/wormhole-sdk";
|
||||
import { setDefaultWasm } from "@certusone/wormhole-sdk/lib/cjs/solana/wasm";
|
||||
import { jest, test } from "@jest/globals";
|
||||
import { Connection, Keypair } from "@solana/web3.js";
|
||||
import { createSpyRPCServiceClient, subscribeSignedVAA } from "..";
|
||||
|
||||
setDefaultWasm("node");
|
||||
|
||||
jest.setTimeout(60000);
|
||||
|
||||
const SOLANA_HOST = "http://localhost:8899";
|
||||
const SOLANA_PRIVATE_KEY = new Uint8Array([
|
||||
14, 173, 153, 4, 176, 224, 201, 111, 32, 237, 183, 185, 159, 247, 22, 161, 89,
|
||||
84, 215, 209, 212, 137, 10, 92, 157, 49, 29, 192, 101, 164, 152, 70, 87, 65,
|
||||
8, 174, 214, 157, 175, 126, 98, 90, 54, 24, 100, 177, 247, 77, 19, 112, 47,
|
||||
44, 165, 109, 233, 102, 14, 86, 109, 29, 134, 145, 132, 141,
|
||||
]);
|
||||
const SOLANA_CORE_BRIDGE_ADDRESS =
|
||||
"Bridge1p5gheXUvJ6jGWGeCsgPKgnE3YgdGKRVCMY9o";
|
||||
const SOLANA_TOKEN_BRIDGE_ADDRESS =
|
||||
"B6RHG3mfcckmrYN1UhmJzyS1XX3fZKbkeUcpJe9Sy3FE";
|
||||
const SPYMASTER = "localhost:7072";
|
||||
const TEST_SOLANA_TOKEN = "2WDq7wSs9zYrpx2kbHDA4RUTRch2CCTP6ZWaH4GNfnQQ";
|
||||
|
||||
test("Can spy on messages", (done) => {
|
||||
(async () => {
|
||||
// set up the spy client
|
||||
const client = createSpyRPCServiceClient(SPYMASTER);
|
||||
// subscribe to the stream of signedVAAs
|
||||
const stream = await subscribeSignedVAA(client, {});
|
||||
// register error callback to avoid crashing on .cancel()
|
||||
stream.addListener("error", (error: any) => {
|
||||
if (error.code === 1) {
|
||||
// Cancelled on client
|
||||
done();
|
||||
} else {
|
||||
done(error);
|
||||
}
|
||||
});
|
||||
// register data callback
|
||||
stream.addListener("data", ({ vaaBytes }: { vaaBytes: any }) => {
|
||||
console.log(vaaBytes);
|
||||
// cancel the stream to end the test
|
||||
stream.cancel();
|
||||
});
|
||||
// make a transaction which posts a message
|
||||
// create a keypair for Solana
|
||||
const keypair = Keypair.fromSecretKey(SOLANA_PRIVATE_KEY);
|
||||
const payerAddress = keypair.publicKey.toString();
|
||||
// attest the test token
|
||||
const connection = new Connection(SOLANA_HOST, "confirmed");
|
||||
const transaction = await attestFromSolana(
|
||||
connection,
|
||||
SOLANA_CORE_BRIDGE_ADDRESS,
|
||||
SOLANA_TOKEN_BRIDGE_ADDRESS,
|
||||
payerAddress,
|
||||
TEST_SOLANA_TOKEN
|
||||
);
|
||||
// sign, send, and confirm transaction
|
||||
transaction.partialSign(keypair);
|
||||
const txid = await connection.sendRawTransaction(transaction.serialize());
|
||||
await connection.confirmTransaction(txid);
|
||||
})();
|
||||
});
|
|
@ -0,0 +1,24 @@
|
|||
import {
|
||||
DeepPartial,
|
||||
SpyRPCServiceClient,
|
||||
SubscribeSignedVAARequest,
|
||||
} from "./proto/spy/v1/spy";
|
||||
import grpc, { ChannelCredentials } from "@grpc/grpc-js";
|
||||
|
||||
export function createSpyRPCServiceClient(
|
||||
host: string,
|
||||
credentials: grpc.ChannelCredentials = ChannelCredentials.createInsecure(),
|
||||
options?: Partial<grpc.ChannelOptions>
|
||||
) {
|
||||
return new SpyRPCServiceClient(host, credentials, options);
|
||||
}
|
||||
|
||||
export async function subscribeSignedVAA(
|
||||
client: SpyRPCServiceClient,
|
||||
request: DeepPartial<SubscribeSignedVAARequest>
|
||||
) {
|
||||
return client.subscribeSignedVAA(
|
||||
SubscribeSignedVAARequest.fromPartial(request)
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"module": "CommonJS",
|
||||
"outDir": "./lib/cjs"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"declaration": true,
|
||||
"outDir": "./lib/esm",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"downlevelIteration": true,
|
||||
"allowJs": true,
|
||||
"lib": ["dom", "es5", "scripthost", "es2020.bigint"]
|
||||
},
|
||||
"include": ["src", "types"],
|
||||
"exclude": ["node_modules", "**/__tests__/*"]
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"extends": ["tslint:recommended", "tslint-config-prettier"],
|
||||
"linterOptions": {
|
||||
"exclude": ["src/proto/**"]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue