feat: initial version

This commit is contained in:
Derrick Hammer 2023-09-01 09:40:08 -04:00
parent 100b4e19c6
commit b907b6f276
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
5 changed files with 18430 additions and 1 deletions

5
.presetterrc.json Normal file
View File

@ -0,0 +1,5 @@
{
"preset": [
"@lumeweb/node-library-preset"
]
}

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:

18344
npm-shrinkwrap.json generated Normal file

File diff suppressed because it is too large Load Diff

28
package.json Normal file
View File

@ -0,0 +1,28 @@
{
"name": "@lumeweb/kernel-s5-client",
"version": "0.1.0",
"type": "module",
"repository": {
"type": "git",
"url": "gitea@git.lumeweb.com:LumeWeb/kernel-s5-client.git"
},
"devDependencies": {
"@lumeweb/node-library-preset": "^0.2.7",
"presetter": "*"
},
"readme": "ERROR: No README data found!",
"_id": "@lumeweb/kernel-s5-client@0.1.0",
"scripts": {
"prepare": "presetter bootstrap"
},
"dependencies": {
"@lumeweb/libkernel": "0.1.0-develop.36",
"@lumeweb/libs5": "^0.1.0-develop.25"
},
"publishConfig": {
"access": "public"
},
"files": [
"lib"
]
}

52
src/index.ts Normal file
View File

@ -0,0 +1,52 @@
import { factory, NetworkClient } from "@lumeweb/libkernel/module";
import type { SignedRegistryEntry } from "@lumeweb/libs5";
export const MODULE =
"zduPehBQc2edPXDBsxo9CM6pTnS6bpDx1MBS92GH5wLAqMnErsVKhnobD1";
export interface RegistryEntry {
key: Uint8Array;
data: Uint8Array;
revision: number;
}
export class S5Client extends NetworkClient {
public async getRegistryEntry(pubkey: Uint8Array | Buffer | string) {
return this.callModuleReturn("getRegistryEntry", { pubkey });
}
public async setRegistryEntry({
key,
data,
revision,
}: RegistryEntry): Promise<SignedRegistryEntry> {
return this.callModuleReturn("setRegistryEntry", { key, data, revision });
}
public registrySubscription(
pubkey: Uint8Array,
cb: (sre: SignedRegistryEntry) => void,
): () => void {
let done = false;
const [end, ret] = this.connectModule(
"registrySubscription",
{ pubkey },
cb,
);
ret.then((ret) => {
this.handleError(ret);
});
return () => {
if (done) {
return;
}
done = true;
end();
};
}
}
export const createClient = factory<S5Client>(S5Client, MODULE);