mirror of
https://github.com/fluencelabs/signature-connector
synced 2025-04-24 13:42:14 +00:00
init
This commit is contained in:
commit
f9a4308070
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
.idea
|
||||
build
|
||||
node_modules
|
26
assembly/index.ts
Normal file
26
assembly/index.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import {getStringInvoker} from "./signature";
|
||||
|
||||
|
||||
let stringInvoker = getStringInvoker();
|
||||
|
||||
export class Result {
|
||||
checkPassed: bool;
|
||||
payload: string | null;
|
||||
errorMessage: string | null;
|
||||
|
||||
constructor(result: string) {
|
||||
|
||||
if (result.includes("[Error]")) {
|
||||
this.checkPassed = false;
|
||||
this.errorMessage = result;
|
||||
} else {
|
||||
this.checkPassed = true;
|
||||
this.payload = result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function checkSignature(request: string): Result {
|
||||
let result = stringInvoker.invoke(request);
|
||||
return new Result(result);
|
||||
}
|
13
assembly/signature.ts
Normal file
13
assembly/signature.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import {StringInvoke, API} from "../node_modules/crossmodule/assembly/index"
|
||||
|
||||
export declare function allocate(size: i32): i32;
|
||||
export declare function deallocate(ptr: i32, size: i32): void;
|
||||
export declare function invoke(ptr: i32, size: i32): i32;
|
||||
export declare function store(ptr: i32, byte: u8): void;
|
||||
export declare function load(ptr: i32): u8;
|
||||
|
||||
export function getStringInvoker(): StringInvoke {
|
||||
let api = new API(invoke, allocate, deallocate, store, load);
|
||||
|
||||
return new StringInvoke(api);
|
||||
}
|
6
assembly/tsconfig.json
Normal file
6
assembly/tsconfig.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": "../node_modules/assemblyscript/std/assembly.json",
|
||||
"include": [
|
||||
"./**/*.ts"
|
||||
]
|
||||
}
|
4691
package-lock.json
generated
Normal file
4691
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
39
package.json
Normal file
39
package.json
Normal file
@ -0,0 +1,39 @@
|
||||
{
|
||||
"name": "crossmodule",
|
||||
"version": "0.0.1",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"asbuild:untouched": "asc assembly/index.ts -b build/untouched.wasm -t build/untouched.wat --sourceMap --validate --debug",
|
||||
"asbuild:optimized": "asc assembly/index.ts -b build/optimized.wasm -t build/optimized.wat --sourceMap --validate --optimize",
|
||||
"asbuild": "npm run asbuild:untouched && npm run asbuild:optimized",
|
||||
"asbuild:test": "npm run asbuild:test:signature",
|
||||
"asbuild:test:signature": "npx asc tests/assembly/signature-test.spec.as.ts -b tests/build/signature-test.wasm -t tests/build/signature-test.wat --validate --sourceMap --importMemory --debug",
|
||||
"test": "npm run asbuild:test && ava -v --serial",
|
||||
"test:ci": "npm run asbuild:test && ava --fail-fast --serial"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"@types/node": "^10.12.3",
|
||||
"assemblyscript": "AssemblyScript/assemblyscript",
|
||||
"ts-node": "^7.0.1",
|
||||
"ava": "^1.4.0",
|
||||
"typescript": "^3.1.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"crossmodule": "github:fluencelabs/crossmodule"
|
||||
},
|
||||
"ava": {
|
||||
"compileEnhancements": true,
|
||||
"extensions": [
|
||||
"ts"
|
||||
],
|
||||
"require": [
|
||||
"ts-node/register/transpile-only"
|
||||
],
|
||||
"files": [
|
||||
"tests/**/*.spec.ts"
|
||||
]
|
||||
}
|
||||
}
|
18
tests/assembly/signature-test.spec.as.ts
Normal file
18
tests/assembly/signature-test.spec.as.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import {Result} from "../../assembly/index";
|
||||
import "allocator/arena";
|
||||
|
||||
declare function logStr(str: string): void;
|
||||
|
||||
export class CrossModuleTest {
|
||||
//TODO fix error: TypeError: WebAssembly Instantiation: Import #0 module="signature" error: module is not an object or function
|
||||
//TODO that caused by importing methods from nonexisted module `signature` in test
|
||||
/*static shouldReturnResultWithError(): bool {
|
||||
let message = "[Error] Some error.";
|
||||
let result = new Result(message);
|
||||
|
||||
assert(!result.checkPassed, "The message should be qualified as error.");
|
||||
assert(result.payload == null, "Payload should be null on error.");
|
||||
assert(result.errorMessage == message, "An error message should exist.");
|
||||
return true;
|
||||
}*/
|
||||
}
|
6
tests/assembly/tsconfig.json
Normal file
6
tests/assembly/tsconfig.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": "../../node_modules/assemblyscript/std/assembly.json",
|
||||
"include": [
|
||||
"./**/*.ts","*.ts"
|
||||
]
|
||||
}
|
3
tests/signature.spec.ts
Normal file
3
tests/signature.spec.ts
Normal file
@ -0,0 +1,3 @@
|
||||
import { defineTestsFromModule } from './utils/spec';
|
||||
|
||||
defineTestsFromModule('signature-test');
|
Loading…
x
Reference in New Issue
Block a user