Compare commits
No commits in common. "v0.2.0-develop.1" and "v0.1.3" have entirely different histories.
v0.2.0-dev
...
v0.1.3
|
@ -4,8 +4,7 @@
|
|||
"tsconfig": {
|
||||
"compilerOptions": {
|
||||
"lib": [
|
||||
"ES2021",
|
||||
"dom"
|
||||
"ES2021"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
|
14
CHANGELOG.md
14
CHANGELOG.md
|
@ -1,17 +1,3 @@
|
|||
# [0.2.0-develop.1](https://git.lumeweb.com/LumeWeb/libweb/compare/v0.1.3...v0.2.0-develop.1) (2023-06-23)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* need to add dom support to TS ([738c3f1](https://git.lumeweb.com/LumeWeb/libweb/commit/738c3f12cfb49456fbcdd433b3f4bd30daa031b7))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add deriveChildKey function ([d7cdaaf](https://git.lumeweb.com/LumeWeb/libweb/commit/d7cdaaf316d4d26ed44860701376d18030030708))
|
||||
* add portal management apis ([d340447](https://git.lumeweb.com/LumeWeb/libweb/commit/d340447aba098dbac6163bfbacca0429323e6e45))
|
||||
* implement initial download method ([7c07211](https://git.lumeweb.com/LumeWeb/libweb/commit/7c07211356497ed36119d32943c46cb2e268b30f))
|
||||
|
||||
## [0.1.3](https://git.lumeweb.com/LumeWeb/libweb/compare/v0.1.2...v0.1.3) (2023-06-21)
|
||||
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@lumeweb/libweb",
|
||||
"version": "0.2.0-develop.1",
|
||||
"version": "0.1.3",
|
||||
"main": "lib/index.js",
|
||||
"type": "module",
|
||||
"repository": {
|
||||
|
@ -21,7 +21,7 @@
|
|||
"semantic-release": "semantic-release"
|
||||
},
|
||||
"dependencies": {
|
||||
"@lumeweb/libportal": "^0.2.0-develop.2",
|
||||
"@lumeweb/libportal": "^0.1.0",
|
||||
"@noble/curves": "^1.1.0",
|
||||
"@noble/hashes": "^1.3.1"
|
||||
},
|
||||
|
|
|
@ -1,41 +1 @@
|
|||
import { getActivePortals } from "#portal.js";
|
||||
import { ErrTuple } from "#types.js";
|
||||
import { decodeCid, getVerifiableStream } from "@lumeweb/libportal";
|
||||
|
||||
const NO_PORTALS_ERROR = [null, "no active portals"] as ErrTuple;
|
||||
|
||||
export async function downloadObject(cid: string): Promise<ErrTuple> {
|
||||
const activePortals = getActivePortals();
|
||||
|
||||
if (!activePortals.size) {
|
||||
return NO_PORTALS_ERROR;
|
||||
}
|
||||
|
||||
for (const portal of activePortals) {
|
||||
if (!(await portal.isLoggedIn())) {
|
||||
try {
|
||||
await portal.register();
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
|
||||
await portal.login();
|
||||
}
|
||||
|
||||
let stream, proof;
|
||||
|
||||
try {
|
||||
stream = await portal.downloadFile(cid);
|
||||
proof = await portal.downloadProof(cid);
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
|
||||
return [
|
||||
await getVerifiableStream(decodeCid(cid).hash, proof, stream),
|
||||
null,
|
||||
];
|
||||
}
|
||||
|
||||
return NO_PORTALS_ERROR;
|
||||
}
|
||||
export function downloadObject(cid: string) {}
|
||||
|
|
|
@ -9,5 +9,4 @@ export * from "./stringifyJSON.js";
|
|||
export * from "./types.js";
|
||||
export * from "./cid.js";
|
||||
export * from "./encoding.js";
|
||||
export * from "./keys.js";
|
||||
export { ed25519, sha512 };
|
||||
|
|
11
src/keys.ts
11
src/keys.ts
|
@ -1,11 +0,0 @@
|
|||
import { blake3 } from "@noble/hashes/blake3";
|
||||
import { concatBytes } from "@noble/hashes/utils";
|
||||
|
||||
export function deriveChildKey(
|
||||
parentKey: Uint8Array,
|
||||
tweak: string,
|
||||
): Uint8Array {
|
||||
const tweakHash = blake3(tweak);
|
||||
|
||||
return blake3(concatBytes(parentKey, tweakHash));
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
import { ErrTuple, KeyPair, Portal } from "#types.js";
|
||||
import { Client } from "@lumeweb/libportal";
|
||||
import { deriveChildKey } from "#keys.js";
|
||||
import { ed25519 } from "@noble/curves/ed25519";
|
||||
import { bytesToHex } from "@noble/hashes/utils.js";
|
||||
|
||||
let activePortalMasterKey;
|
||||
|
||||
export const DEFAULT_PORTAL_LIST: Portal[] = [
|
||||
{ id: "lumeweb", url: "https://web3portal.com", name: "web3portal.com" },
|
||||
];
|
||||
|
||||
const ACTIVE_PORTALS = new Set<Client>();
|
||||
|
||||
type PortalSessionsStore = { [id: string]: string };
|
||||
|
||||
export function maybeInitDefaultPortals(): ErrTuple {
|
||||
if (!activePortalMasterKey) {
|
||||
return [null, "activePortalMasterKey not set"];
|
||||
}
|
||||
|
||||
let portalSessionsData = window.localStorage.getItem("portals");
|
||||
let portalSessions: PortalSessionsStore = {};
|
||||
if (portalSessions) {
|
||||
portalSessions = JSON.parse(
|
||||
portalSessionsData as string,
|
||||
) as PortalSessionsStore;
|
||||
}
|
||||
|
||||
for (const portal of DEFAULT_PORTAL_LIST) {
|
||||
let jwt: string | null = null;
|
||||
|
||||
if (portalSessions) {
|
||||
if (portal.id in portalSessions) {
|
||||
jwt = portalSessions[portal.id];
|
||||
}
|
||||
}
|
||||
|
||||
const client = new Client({
|
||||
email: generatePortalEmail(portal),
|
||||
portalUrl: portal.url,
|
||||
privateKey: generatePortalKeyPair(portal).privateKey,
|
||||
jwt: jwt as string,
|
||||
});
|
||||
|
||||
ACTIVE_PORTALS.add(client);
|
||||
}
|
||||
|
||||
return [null, null];
|
||||
}
|
||||
|
||||
export function setActivePortalMasterKey(key: Uint8Array) {
|
||||
activePortalMasterKey = key;
|
||||
}
|
||||
|
||||
export function generatePortalEmail(portal: Portal) {
|
||||
const keyPair = generatePortalKeyPair(portal);
|
||||
|
||||
const userId = bytesToHex(keyPair.publicKey.slice(0, 12));
|
||||
|
||||
return `${userId}@example.com`;
|
||||
}
|
||||
|
||||
export function generatePortalKeyPair(portal: Portal): KeyPair {
|
||||
const privateKey = deriveChildKey(
|
||||
activePortalMasterKey,
|
||||
`portal-account:${portal.id}`,
|
||||
);
|
||||
|
||||
return {
|
||||
privateKey,
|
||||
publicKey: ed25519.getPublicKey(privateKey),
|
||||
};
|
||||
}
|
||||
|
||||
export function getActivePortals(): Set<Client> {
|
||||
return ACTIVE_PORTALS;
|
||||
}
|
|
@ -71,11 +71,6 @@ interface RequestOverrideResponse {
|
|||
body?: Uint8Array;
|
||||
}
|
||||
|
||||
export interface KeyPair {
|
||||
publicKey: Uint8Array;
|
||||
privateKey: Uint8Array;
|
||||
}
|
||||
|
||||
export {
|
||||
DataFn,
|
||||
ErrFn,
|
||||
|
|
Loading…
Reference in New Issue