Skip to content

Commit

Permalink
feat: add starknet blob decoder wasm package
Browse files Browse the repository at this point in the history
  • Loading branch information
PJColombo committed May 12, 2024
1 parent 1abc00a commit 2943d90
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ packages:
- "clis/*"
- "packages/*"
- "tooling/*"
- "wasms/*"
7 changes: 7 additions & 0 deletions wasms/majin-blob-wasm/majin_blob_wasm.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* tslint:disable */
/* eslint-disable */
/**
* @param {string} data
* @returns {string}
*/
export function blob_recover(data: string): string;
4 changes: 4 additions & 0 deletions wasms/majin-blob-wasm/majin_blob_wasm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import * as wasm from "./majin_blob_wasm_bg.wasm";
import { __wbg_set_wasm } from "./majin_blob_wasm_bg.js";
__wbg_set_wasm(wasm);
export * from "./majin_blob_wasm_bg.js";
115 changes: 115 additions & 0 deletions wasms/majin-blob-wasm/majin_blob_wasm_bg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
let wasm;
export function __wbg_set_wasm(val) {
wasm = val;
}


let WASM_VECTOR_LEN = 0;

let cachedUint8Memory0 = null;

function getUint8Memory0() {
if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
}
return cachedUint8Memory0;
}

const lTextEncoder = typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder;

let cachedTextEncoder = new lTextEncoder('utf-8');

const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
? function (arg, view) {
return cachedTextEncoder.encodeInto(arg, view);
}
: function (arg, view) {
const buf = cachedTextEncoder.encode(arg);
view.set(buf);
return {
read: arg.length,
written: buf.length
};
});

function passStringToWasm0(arg, malloc, realloc) {

if (realloc === undefined) {
const buf = cachedTextEncoder.encode(arg);
const ptr = malloc(buf.length, 1) >>> 0;
getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
WASM_VECTOR_LEN = buf.length;
return ptr;
}

let len = arg.length;
let ptr = malloc(len, 1) >>> 0;

const mem = getUint8Memory0();

let offset = 0;

for (; offset < len; offset++) {
const code = arg.charCodeAt(offset);
if (code > 0x7F) break;
mem[ptr + offset] = code;
}

if (offset !== len) {
if (offset !== 0) {
arg = arg.slice(offset);
}
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
const ret = encodeString(arg, view);

offset += ret.written;
ptr = realloc(ptr, len, offset, 1) >>> 0;
}

WASM_VECTOR_LEN = offset;
return ptr;
}

let cachedInt32Memory0 = null;

function getInt32Memory0() {
if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) {
cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
}
return cachedInt32Memory0;
}

const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;

let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });

cachedTextDecoder.decode();

function getStringFromWasm0(ptr, len) {
ptr = ptr >>> 0;
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
}
/**
* @param {string} data
* @returns {string}
*/
export function blob_recover(data) {
let deferred2_0;
let deferred2_1;
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
const ptr0 = passStringToWasm0(data, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN;
wasm.blob_recover(retptr, ptr0, len0);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
deferred2_0 = r0;
deferred2_1 = r1;
return getStringFromWasm0(r0, r1);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
}
}

Binary file added wasms/majin-blob-wasm/majin_blob_wasm_bg.wasm
Binary file not shown.
8 changes: 8 additions & 0 deletions wasms/majin-blob-wasm/majin_blob_wasm_bg.wasm.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* tslint:disable */
/* eslint-disable */
export const memory: WebAssembly.Memory;
export function blob_recover(a: number, b: number, c: number): void;
export function __wbindgen_add_to_stack_pointer(a: number): number;
export function __wbindgen_malloc(a: number, b: number): number;
export function __wbindgen_realloc(a: number, b: number, c: number, d: number): number;
export function __wbindgen_free(a: number, b: number, c: number): void;
18 changes: 18 additions & 0 deletions wasms/majin-blob-wasm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "@blobscan/majin-blob-wasm",
"private": true,
"collaborators": [
"Abdelhamid Bakhta <@AbdelStark>"
],
"version": "0.0.1",
"files": [
"browser/*",
"node/*"
],
"types": "majin_blob_wasm.d.ts",
"main": "./majin_blob_wasm.js",
"sideEffects": [
"./majin_blob_wasm.js",
"./snippets/*"
]
}

0 comments on commit 2943d90

Please sign in to comment.