-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
363 additions
and
282 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"printWidth": 120, | ||
"trailingComma": "all", | ||
"singleQuote": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,48 @@ | ||
{ | ||
"name": "lcs", | ||
"version": "0.0.1", | ||
"main": "build/lib/index.js", | ||
"description": "Implementation of the LCS (Libra Canonical Serialization) protocol", | ||
"types": "build/lib/index.d.ts", | ||
"author": "Igor Demko <[email protected]>", | ||
"license": "MIT", | ||
"keywords": [ | ||
"dfinance", | ||
"dfi", | ||
"move", | ||
"libra", | ||
"smartcontract", | ||
"xfi", | ||
"lcs", | ||
"lcs-serialization", | ||
"lcs-deserialization" | ||
], | ||
"scripts": { | ||
"serve": "nodemon src/index.ts" | ||
"serve": "nodemon src/example.ts", | ||
"build": "tsc", | ||
"format": "prettier --write \"src/**/*.ts\"", | ||
"lint": "tslint -p tsconfig.json", | ||
"prepare": "yarn run build", | ||
"prepublishOnly": "yarn run lint", | ||
"preversion": "yarn run lint", | ||
"version": "yarn run format && git add -A src", | ||
"postversion": "git push && git push --tags" | ||
}, | ||
"files": ["build/**/*"], | ||
"dependencies": { | ||
"bignumber.js": "^9.0.0", | ||
"int64-buffer": "^0.99.1007", | ||
"leb": "^0.3.0", | ||
"uleb128": "^1.0.1", | ||
"xregexp": "^4.3.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/types": "^7.11.5", | ||
"@types/node": "^14.10.1", | ||
"@types/xregexp": "^4.3.0", | ||
"nodemon": "^2.0.4", | ||
"prettier": "^2.1.2", | ||
"ts-node": "^9.0.0", | ||
"tslint": "^6.1.3", | ||
"tslint-config-prettier": "^1.18.0", | ||
"typescript": "^4.0.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,6 @@ | ||
import { stringLiteral } from "@babel/types" | ||
import { Buffer } from "buffer" | ||
|
||
export class BufferUtil { | ||
public static fromHex(source: string): Uint8Array { | ||
const data = source.match(/.{1,2}/g)!.map(x => parseInt(x, 16)) | ||
return new Uint8Array(data) | ||
} | ||
|
||
public static fromBase64(source: string): Uint8Array { | ||
return Uint8Array.from(Buffer.from(source, 'base64')) | ||
} | ||
|
||
public static fromString(source: string): Uint8Array { | ||
const buffer = new ArrayBuffer(source.length) | ||
const view = new DataView(buffer) | ||
for(let i=0; i< source.length; i++) { | ||
view.setUint8(i,source.charCodeAt(i)) | ||
} | ||
return new Uint8Array(buffer) | ||
} | ||
|
||
public static toString(source: Uint8Array): string { | ||
const data: string[] = [] | ||
source.forEach( x => { | ||
data.push(String.fromCharCode(x)) | ||
}) | ||
return data.join('') | ||
} | ||
|
||
public static toHex(sources:Uint8Array): string { | ||
const data:string[] = [] | ||
sources.forEach(x => { | ||
data.push(x.toString(16).padStart(2, '0')) | ||
}) | ||
return data.join('') | ||
} | ||
|
||
public static toBase64(sources:Uint8Array): string { | ||
return Buffer.from(sources).toString('base64') | ||
} | ||
|
||
public static concat(a:Uint8Array, b:Uint8Array): Uint8Array { | ||
const c = new Uint8Array(a.length + b.length) | ||
c.set(a) | ||
c.set(b, a.length) | ||
return c | ||
} | ||
} | ||
export class BufferUtil { | ||
public static fromHex(source: string): Uint8Array { | ||
const data = source.match(/.{1,2}/g)!.map((x) => parseInt(x, 16)); | ||
return new Uint8Array(data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import LCS from './lcs' | ||
import types from './types' | ||
import LCS from './lcs'; | ||
import types from './types'; | ||
|
||
Object.keys(types).forEach((typeName: string) => { | ||
// @ts-ignore | ||
LCS.registerType(typeName, types[typeName]) | ||
}) | ||
LCS.registerType(typeName, types[typeName]); | ||
}); | ||
|
||
export default LCS | ||
export default LCS; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import CursorBuffer from "../common/CursorBuffer"; | ||
import CursorBuffer from '../common/CursorBuffer'; | ||
|
||
export interface TypeInterface { | ||
decode: (cursor: CursorBuffer, options?: any) => any, | ||
code: (cursor: CursorBuffer, value: any, options?: any) => any | ||
decode: (cursor: CursorBuffer, options?: any) => any; | ||
code: (cursor: CursorBuffer, value: any, options?: any) => any; | ||
} | ||
|
||
export interface RegisterTypeInterface { | ||
[key: string]: TypeInterface | string | ||
[key: string]: TypeInterface | string; | ||
} |
Oops, something went wrong.