Compare commits

...

4 Commits

Author SHA1 Message Date
semantic-release-bot 819c7395b7 chore(release): 0.1.0-develop.1 [skip ci]
# [0.1.0-develop.1](https://git.lumeweb.com/LumeWeb/kernel-lavanet/compare/v0.0.1...v0.1.0-develop.1) (2023-08-20)

### Features

* initial version ([59ece67](59ece6720e))
2023-08-20 09:40:47 +00:00
Derrick Hammer f77db1cf7d
chore: update LICENSE 2023-08-20 05:31:46 -04:00
Derrick Hammer 72c6072c41
ci: setup 2023-08-20 05:31:09 -04:00
Derrick Hammer 59ece6720e
feat: initial version 2023-08-20 05:29:40 -04:00
9 changed files with 20693 additions and 1 deletions

13
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,13 @@
name: Build/Publish
on:
push:
branches:
- master
- develop
- develop-*
jobs:
main:
uses: lumeweb/github-node-deploy-workflow/.github/workflows/main.yml@master
secrets: inherit

8
.presetterrc.json Normal file
View File

@ -0,0 +1,8 @@
{
"preset": [
"@lumeweb/presetter-kernel-module-preset"
],
"config": {
"official": true
}
}

6
CHANGELOG.md Normal file
View File

@ -0,0 +1,6 @@
# [0.1.0-develop.1](https://git.lumeweb.com/LumeWeb/kernel-lavanet/compare/v0.0.1...v0.1.0-develop.1) (2023-08-20)
### Features
* initial version ([59ece67](https://git.lumeweb.com/LumeWeb/kernel-lavanet/commit/59ece6720e23869063da00b2a460265a615c2e10))

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2023 LumeWeb
Copyright (c) 2023 Hammer Technologies LLC
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

20469
npm-shrinkwrap.json generated Normal file

File diff suppressed because it is too large Load Diff

24
package.json Normal file
View File

@ -0,0 +1,24 @@
{
"name": "@lumeweb/kernel-lavanet",
"type": "module",
"version": "0.1.0-develop.1",
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "gitea@git.lumeweb.com:LumeWeb/kernel-lavanet.git"
},
"scripts": {
"prepare": "presetter bootstrap",
"build": "run build",
"semantic-release": "semantic-release"
},
"dependencies": {
"@lavanet/lava-sdk": "^0.21.1",
"@lumeweb/kernel-rpc-client": "^0.0.2-develop.13",
"@lumeweb/libkernel": "^0.1.0-develop.36"
},
"devDependencies": {
"@lumeweb/presetter-kernel-module-preset": "^0.1.0-develop.44",
"patch-package": "^8.0.0"
}
}

View File

@ -0,0 +1,46 @@
diff --git a/node_modules/@lavanet/lava-sdk/bin/src/badge/fetchBadge.js b/node_modules/@lavanet/lava-sdk/bin/src/badge/fetchBadge.js
index 0c3063a..5e9cd0c 100644
--- a/node_modules/@lavanet/lava-sdk/bin/src/badge/fetchBadge.js
+++ b/node_modules/@lavanet/lava-sdk/bin/src/badge/fetchBadge.js
@@ -24,6 +24,7 @@ class BadgeManager {
this.badgeServerAddress = "";
this.projectId = "";
this.active = true;
+ this.transport = transport;
if (!options) {
this.active = false;
return;
@@ -52,7 +53,7 @@ class BadgeManager {
request: request,
host: this.badgeServerAddress,
metadata: this.authentication ? this.authentication : {},
- transport: browser_1.default,
+ transport: this.transport ?? browser_1.default,
onMessage: (message) => {
resolve(message);
},
diff --git a/node_modules/@lavanet/lava-sdk/bin/src/sdk/sdk.js b/node_modules/@lavanet/lava-sdk/bin/src/sdk/sdk.js
index 53bfa7d..4ef0fd7 100644
--- a/node_modules/@lavanet/lava-sdk/bin/src/sdk/sdk.js
+++ b/node_modules/@lavanet/lava-sdk/bin/src/sdk/sdk.js
@@ -47,9 +47,6 @@ class LavaSDK {
if (!badge && !privateKey) {
throw errors_1.default.errPrivKeyAndBadgeNotInitialized;
}
- else if (badge && privateKey) {
- throw errors_1.default.errPrivKeyAndBadgeBothInitialized;
- }
// Initialize local attributes
this.debugMode = options.debug ? options.debug : false; // enabling debug prints mainly used for development / debugging
this.secure = options.secure !== undefined ? options.secure : true;
@@ -148,8 +145,8 @@ class LavaSDK {
return __awaiter(this, void 0, void 0, function* () {
const start = performance.now();
if (this.badgeManager.isActive()) {
- const { wallet, privKey } = yield (0, wallet_1.createDynamicWallet)();
- this.privKey = privKey;
+ const wallet = yield (0, wallet_1.createWallet)(this.privKey);
+ const account = yield wallet.getConsumerAccount();
this.walletAddress = (yield wallet.getConsumerAccount()).address;
const badgeResponse = yield this.fetchNewBadge();
this.currentEpochBadge = badgeResponse.getBadge();

76
src/index.ts Normal file
View File

@ -0,0 +1,76 @@
import { LavaSDK } from "@lavanet/lava-sdk";
import type { ActiveQuery } from "@lumeweb/libkernel/module";
import {
addHandler,
defer,
getKey,
handlePresentKey as handlePresentKeyModule,
} from "@lumeweb/libkernel/module";
import {
createClient as createRpcClient,
RpcNetwork,
} from "@lumeweb/kernel-rpc-client";
import { bytesToHex, deriveChildKey } from "@lumeweb/libweb";
import { hyperTransport } from "./transport.js";
addHandler("presentKey", handlePresentKey);
addHandler("query", handleQuery);
const chainInstances = new Map<string, LavaSDK>();
const moduleReadyDefer = defer();
let rpc: RpcNetwork;
async function handlePresentKey(aq: ActiveQuery) {
handlePresentKeyModule({
callerInput: {
key: aq.callerInput.rootKey,
},
} as ActiveQuery);
rpc = createRpcClient();
moduleReadyDefer.resolve();
}
async function handleQuery(aq: ActiveQuery) {
if (!("chain" in aq.callerInput)) {
aq.reject("chain missing");
return;
}
if (!("query" in aq.callerInput)) {
aq.reject("query missing");
return;
}
const { chain, query, rpcInterface = undefined } = aq.callerInput;
let lava: LavaSDK;
if (!chainInstances.has(chain)) {
lava = await setupRelayChain(chain, rpcInterface);
} else {
lava = chainInstances.get(chain) as LavaSDK;
}
await rpc.ready;
try {
aq.respond(lava.sendRelay(query));
} catch (e) {
aq.reject(e);
}
}
async function setupRelayChain(chain: string, rpcInterface?: string) {
const instance = await LavaSDK.create({
chainID: chain,
privateKey: bytesToHex(deriveChildKey(await getKey(), "lavanet")),
badge: {
// @ts-ignore
transport: hyperTransport(rpc),
},
rpcInterface,
});
chainInstances.set(chain, instance);
return instance;
}

50
src/transport.ts Normal file
View File

@ -0,0 +1,50 @@
import { grpc } from "@improbable-eng/grpc-web";
import { RpcNetwork } from "@lumeweb/kernel-rpc-client";
import Metadata = grpc.Metadata;
class HyperTransport implements grpc.Transport {
private options: grpc.TransportOptions;
private rpc: RpcNetwork;
private metadata?: Metadata;
constructor(transportOptions: grpc.TransportOptions, rpc: RpcNetwork) {
this.options = transportOptions;
this.rpc = rpc;
}
cancel(): void {}
finishSend(): void {}
async sendMessage(msgBytes: Uint8Array): Promise<void> {
const req = this.rpc.simpleQuery({
query: {
module: "lavanet",
method: "badge_request",
data: {
metadata: this.metadata,
data: msgBytes,
},
},
});
const ret = await req.result;
if (ret.error) {
this.options.onEnd({ message: ret.error, name: "", stack: "" });
return;
}
this.options.onChunk(ret.data);
this.options.onEnd();
}
start(metadata: Metadata): void {
this.metadata = metadata;
}
}
export function hyperTransport(rpc: RpcNetwork): grpc.TransportFactory {
return (opts: grpc.TransportOptions) => {
return new HyperTransport(opts, rpc);
};
}