Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

w3sper: Remove usage of deprecate Deno.serveHttp with Deno.serve #2892

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions w3sper.js/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
# w3sper.js SDK

The W3sper.js SDK is a robust toolkit designed to streamline the development of applications that seamlessly interact with the Dusk Blockchain. This repository hosts the Web SDK, built with JavaScript, while a Native SDK, implemented in Rust, is also available in a separate repository. Both versions of the SDK offer comprehensive tools for managing blockchain interactions, but this version focuses on web-based implementations.
The W3sper.js SDK is a robust toolkit designed to streamline the development of
applications that seamlessly interact with the Dusk Blockchain. This repository
hosts the Web SDK, built with JavaScript, while a Native SDK, implemented in
Rust, is also available in a separate repository. Both versions of the SDK offer
comprehensive tools for managing blockchain interactions, but this version
focuses on web-based implementations.

## Features

- **Address & Account Management**: Generate and manage profiles.
- **Balance & Transaction Handling**: Check balances, create signed transactions, and manage gas.
- **Balance & Transaction Handling**: Check balances, create signed
transactions, and manage gas.
- **Event Subscription**: Subscribe to network events and query blockchain data.
- **Proof Management**: Generate and delegate cryptographic proofs.

Expand All @@ -21,8 +27,11 @@ The W3sper.js SDK is a robust toolkit designed to streamline the development of

## Getting Started

To start using the W3sper SDK in your project, refer to the installation and usage guides for the [Native SDK](link-to-native-sdk-docs) and [Web SDK](link-to-web-sdk-docs).
To start using the W3sper SDK in your project, refer to the installation and
usage guides for the [Native SDK](link-to-native-sdk-docs) and
[Web SDK](link-to-web-sdk-docs).

## License

This project is licensed under the the [Mozilla Public License Version 2.0](./LICENSE).
This project is licensed under the the
[Mozilla Public License Version 2.0](./LICENSE).
6 changes: 3 additions & 3 deletions w3sper.js/deno.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"tasks": {
"test": "deno test --allow-read --allow-net --allow-write --allow-run --trace-leaks"
}
"tasks": {
"test": "deno test --allow-read --allow-net --allow-write --allow-run --trace-leaks"
}
}
19 changes: 11 additions & 8 deletions w3sper.js/src/b58.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const A = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";

// Uint8Array raw byte input
export function encode(buffer) {
var d = [], //the array for storing the stream of base58 digits
s = "", //the result string variable that will be returned
const d = []; //the array for storing the stream of base58 digits
let s = "", //the result string variable that will be returned
i, //the iterator variable for the byte input
j, //the iterator variable for the base58 digit array (d)
c, //the carry amount variable that is used to overflow from the current base58 digit to the next base58 digit
Expand All @@ -28,27 +28,29 @@ export function encode(buffer) {
j++; //iterate to the next base58 digit
}
}
while (j--)
while (j--) {
//since the base58 digits are backwards, loop through them in reverse order
s += A[d[j]]; //lookup the character associated with each base58 digit
}
return s; //return the final base58 string
}

// Base58 encoded string input
export function decode(string) {
var d = [], //the array for storing the stream of decoded bytes
b = [], //the result byte array that will be returned
i, //the iterator variable for the base58 string
const d = [], //the array for storing the stream of decoded bytes
b = []; //the result byte array that will be returned
let i, //the iterator variable for the base58 string
j, //the iterator variable for the byte array (d)
c, //the carry amount variable that is used to overflow from the current byte to the next byte
n; //a temporary placeholder variable for the current byte
for (i in string) {
//loop through each base58 character in the input string
(j = 0), //reset the byte iterator
(c = A.indexOf(string[i])); //set the initial carry amount equal to the current base58 digit
if (c < 0)
if (c < 0) {
//see if the base58 digit lookup is invalid (-1)
return undefined; //if invalid base58 digit, bail out and return undefined
}
c || b.length ^ i ? i : b.push(0); //prepend the result array with a zero if the base58 digit is zero and non-zero characters haven't been seen yet (to ensure correct decode length)
while (j in d || c) {
//start looping through the bytes until there are no more bytes and no carry amount
Expand All @@ -59,8 +61,9 @@ export function decode(string) {
j++; //iterate to the next byte
}
}
while (j--)
while (j--) {
//since the byte array is backwards, loop through it in reverse order
b.push(d[j]); //append each byte to the result
}
return new Uint8Array(b); //return the final byte array in Uint8Array format
}
3 changes: 2 additions & 1 deletion w3sper.js/src/bookkeeper.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ export class Bookkeeper {
switch (type) {
case "account":
return await this.#treasury.account(identifier);
case "address":
case "address": {
const notes = await this.#treasury.address(identifier);
const seed = await ProfileGenerator.seedFrom(identifier);
const index = +identifier;

return ProtocolDriver.balance(seed, index, notes);
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions w3sper.js/src/network/bookmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ export class Bookmark {
if (typeof source?.[intoBookmark] === "function") {
return source[intoBookmark]();
} else if (typeof source === "bigint" || typeof source === "number") {
let buffer = new ArrayBuffer(8);
const buffer = new ArrayBuffer(8);
new DataView(buffer).setBigUint64(0, BigInt(source), true);
return new Bookmark(new Uint8Array(buffer));
} else if (source instanceof Bookmark) {
return new Bookmark(source.data);
}

let buffer = Uint8Array.from(data);
const buffer = Uint8Array.from(data);
return new Bookmark(buffer);
}

Expand Down
2 changes: 1 addition & 1 deletion w3sper.js/src/network/components/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class Blocks {
.then((data) =>
Object.fromEntries(
Object.entries(data).map(([key, value]) => [key, BigInt(value)]),
),
)
);
}

Expand Down
2 changes: 1 addition & 1 deletion w3sper.js/src/network/components/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class Node {
snakeToCamel(key),
value,
]),
),
)
)
.then((info) => {
info.chainId = info.chainId ?? 0;
Expand Down
8 changes: 5 additions & 3 deletions w3sper.js/src/network/mod.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ export { AddressSyncer } from "./syncer/address.js";
export { AccountSyncer } from "./syncer/account.js";
export { Bookmark } from "./bookmark.js";

// deno-lint-ignore no-unused-vars
const abortable = (signal) =>
new Promise((resolve, reject) =>
signal?.aborted ? reject(signal.reason) : resolve(signal),
signal?.aborted ? reject(signal.reason) : resolve(signal)
);

// deno-lint-ignore no-unused-vars
const once = (target, topic) =>
new Promise((resolve) =>
target.addEventListener(topic, resolve, { once: true }),
target.addEventListener(topic, resolve, { once: true })
);

export class Network {
Expand Down Expand Up @@ -95,7 +97,7 @@ export class Network {
return tx;
}

async prove(circuits) {
prove(circuits) {
return this.#rues
.scope("prover")
.call.prove(circuits, {
Expand Down
6 changes: 3 additions & 3 deletions w3sper.js/src/network/syncer/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export class AccountSyncer extends EventTarget {
profiles.map(intoAccount),
);

let balances = rawUsers.map((user) =>
this.#network.contracts.transferContract.call.account(user),
const balances = rawUsers.map((user) =>
this.#network.contracts.transferContract.call.account(user)
);

return await Promise.all(balances)
Expand All @@ -44,7 +44,7 @@ export class AccountSyncer extends EventTarget {
buffers.map((buffer) => ({
nonce: new DataView(buffer).getBigUint64(0, true),
value: new DataView(buffer).getBigUint64(8, true),
})),
}))
);
}
}
23 changes: 11 additions & 12 deletions w3sper.js/src/network/syncer/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const size = (array) => array.reduce((sum, { size }) => sum + size, 0);
export class AddressSyncer extends EventTarget {
#network;

constructor(network, options = {}) {
constructor(network, _options = {}) {
super();
this.#network = network;
}
Expand All @@ -34,13 +34,13 @@ export class AddressSyncer extends EventTarget {
.then((response) => response.arrayBuffer());
}

async openings(notes, options = {}) {
async openings(notes, _soptions = {}) {
const network = this.#network;
// Get the bookmarks for each notes
const bookmarks = await ProtocolDriver.bookmarks(notes);

// Fetch the openings for each picked notes
let requests = [];
const requests = [];

for (let i = 0; i < bookmarks.length; i += 8) {
const body = bookmarks.slice(i, i + 8);
Expand Down Expand Up @@ -82,24 +82,24 @@ export class AddressSyncer extends EventTarget {
const lastBookmark = await this.#bookmark;
const lastBlock = await this.#network.blockHeight;

let body, topic, to;
let body, topic, _to;

if (from instanceof Bookmark) {
topic = "leaves_from_pos";
body = from.data;
to = lastBookmark;
_to = lastBookmark;
} else {
topic = "leaves_from_height";
body = new Uint8Array(8);
to = lastBlock;
_to = lastBlock;
new DataView(body.buffer).setBigUint64(0, from, true);
}

let response = await this.#network.contracts.transferContract.call[topic](
const response = await this.#network.contracts.transferContract.call[topic](
body,
{ headers: { "Rusk-Feeder": "true" } },
);
let reader = getBYOBReader(response.body);
const reader = getBYOBReader(response.body);

const entrySize = await ProtocolDriver.getEntrySize();

Expand All @@ -120,10 +120,9 @@ export class AddressSyncer extends EventTarget {
value,
).catch(console.error);

let progress =
Number(
((syncInfo.bookmark * 100n) / lastBookmark.asUint()) * 100n,
) / 10000;
const progress = Number(
((syncInfo.bookmark * 100n) / lastBookmark.asUint()) * 100n,
) / 10000;

this.dispatchEvent(
new SyncEvent("synciteration", {
Expand Down
16 changes: 9 additions & 7 deletions w3sper.js/src/protocol-driver/alloc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//
// Copyright (c) DUSK NETWORK. All rights reserved.

import * as DataBuffer from "./buffer.js";
import { none } from "./none.js";

const _mem = Symbol("allocator::mem");
Expand Down Expand Up @@ -76,22 +75,22 @@ class Allocator {
function u32x(source) {
source ??= this;
return memcpy(null, +source, 4).then((data) =>
new DataView(data.buffer).getUint32(0, true),
new DataView(data.buffer).getUint32(0, true)
);
}
u32x.byteLength = 4;

function u64(source) {
source ??= this;
return memcpy(null, +source, 8).then((data) =>
new DataView(data.buffer).getBigUint64(0, true),
new DataView(data.buffer).getBigUint64(0, true)
);
}
u32x.byteLength = 8;

function ptrx(type) {
return async function () {
let address = await u32x.call(this);
const address = await u32x.call(this);
return await type.call(address);
};
}
Expand All @@ -102,12 +101,15 @@ class Allocator {
const len = await u32x(source);
const data = await memcpy(null, source + 4, len);

let align = new DataView(data.buffer).getUint32(
const align = new DataView(data.buffer).getUint32(
data.byteLength - 8,
true,
);

let size = new DataView(data.buffer).getUint32(data.byteLength - 4, true);
const size = new DataView(data.buffer).getUint32(
data.byteLength - 4,
true,
);

return [data, { align, size }];
}
Expand All @@ -129,7 +131,7 @@ class Allocator {

u32(source) {
return memcpy(null, +source, 4).then((data) =>
new DataView(data.buffer).getUint32(0, true),
new DataView(data.buffer).getUint32(0, true)
);
},
};
Expand Down
2 changes: 0 additions & 2 deletions w3sper.js/src/protocol-driver/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
//
// Copyright (c) DUSK NETWORK. All rights reserved.

const unbind = Function.call.bind(Function.bind, Function.call);

function setLayout(dest, size) {
// Subtract 8 bytes to exclude the space reserved for alignment and size
const totalLength = dest.byteLength - 8;
Expand Down
Loading
Loading