-
Notifications
You must be signed in to change notification settings - Fork 7
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
15 changed files
with
172 additions
and
4 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 @@ | ||
--- | ||
"@fleet-sdk/crypto": minor | ||
--- | ||
|
||
Introduce `crypto` package with Ergo crypto primitives. |
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,3 +1,3 @@ | ||
# @fleet-sdk/core [![License](https://badgen.net/github/license/fleet-sdk/fleet/)](https://github.com/fleet-sdk/fleet/blob/master/LICENSE) [![npm](https://badgen.net/npm/v/@fleet-sdk/common)](https://www.npmjs.com/package/@fleet-sdk/common) | ||
# @fleet-sdk/common [![License](https://badgen.net/github/license/fleet-sdk/fleet/)](https://github.com/fleet-sdk/fleet/blob/master/LICENSE) [![npm](https://badgen.net/npm/v/@fleet-sdk/common)](https://www.npmjs.com/package/@fleet-sdk/common) | ||
|
||
Internal utility functions, constants and types shared across @fleet-sdk packages. |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Nautilus Team | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,3 @@ | ||
# @fleet-sdk/crypto [![License](https://badgen.net/github/license/fleet-sdk/fleet/)](https://github.com/fleet-sdk/fleet/blob/master/LICENSE) [![npm](https://badgen.net/npm/v/@fleet-sdk/crypto)](https://www.npmjs.com/package/@fleet-sdk/crypto) | ||
|
||
Ergo blockchain crypto primitives. |
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,47 @@ | ||
{ | ||
"name": "@fleet-sdk/crypto", | ||
"version": "0.0.0", | ||
"description": "Ergo blockchain crypto primitives.", | ||
"main": "dist/cjs/index.js", | ||
"module": "dist/esm/index.js", | ||
"typings": "dist/esm/index.d.ts", | ||
"sideEffects": true, | ||
"repository": "fleet-sdk/fleet", | ||
"license": "MIT", | ||
"publishConfig": { | ||
"access": "public", | ||
"provenance": true | ||
}, | ||
"keywords": [ | ||
"ergo", | ||
"blockchain", | ||
"crypto" | ||
], | ||
"scripts": { | ||
"build": "run-p build:*", | ||
"build:cjs": "tsc -p tsconfig.json", | ||
"build:esm": "tsc -p tsconfig.esm.json", | ||
"watch:build": "tsc -p tsconfig.json -w", | ||
"watch:unit": "vitest" | ||
}, | ||
"engines": { | ||
"node": ">=14" | ||
}, | ||
"dependencies": { | ||
"@noble/hashes": "^1.3.0", | ||
"@scure/base": "^1.1.1" | ||
}, | ||
"devDependencies": { | ||
"@fleet-sdk/common": "workspace:^" | ||
}, | ||
"files": [ | ||
"src", | ||
"dist", | ||
"!**/*.spec.*", | ||
"!**/*.json", | ||
"!tests", | ||
"CHANGELOG.md", | ||
"LICENSE", | ||
"README.md" | ||
] | ||
} |
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,16 @@ | ||
import { hexToBytes } from "@fleet-sdk/common"; | ||
import { hex } from "@scure/base"; | ||
import { bench, describe } from "vitest"; | ||
|
||
describe("HEX <> Bytes decoding", () => { | ||
const validHex = "0008cd026dc059d64a50d0dbf07755c2c4a4e557e3df8afa7141868b3ab200643d437ee7"; | ||
// const invalidHex = "0008cd026dc059d64a50d0dbf07755c2c4a4e557e3df8afa7141868b3ab200643d437ee7tt"; | ||
|
||
bench("Using scure", () => { | ||
hex.decode(validHex); | ||
}); | ||
|
||
bench("Using own impl", () => { | ||
hexToBytes(validHex); | ||
}); | ||
}); |
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,21 @@ | ||
import { | ||
base58 as base58Coder, | ||
base64 as base64Coder, | ||
hex as hexCoder, | ||
utf8 as utf8Coder | ||
} from "@scure/base"; | ||
|
||
export interface Coder<F, T> { | ||
encode(from: F): T; | ||
decode(to: T): F; | ||
} | ||
|
||
export interface BytesCoder extends Coder<Uint8Array, string> { | ||
encode: (data: Uint8Array) => string; | ||
decode: (str: string) => Uint8Array; | ||
} | ||
|
||
export const base58 = base58Coder as BytesCoder; | ||
export const hex = hexCoder as BytesCoder; | ||
export const utf8 = utf8Coder as BytesCoder; | ||
export const base64 = base64Coder as BytesCoder; |
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,17 @@ | ||
import { hexToBytes, utf8ToBytes } from "@fleet-sdk/common"; | ||
import { describe, expect, it } from "vitest"; | ||
import { blake2b256, sha256, tests } from "./hashes"; | ||
|
||
describe("Hashes", () => { | ||
it("Should hash message using BLAKE2b256", () => { | ||
expect(blake2b256(utf8ToBytes("blake2b256"))).to.be.deep.equal( | ||
hexToBytes("eb95e6932cedac15db722fcdb0cfd21437f94690339a716251fad2f89842ea8b") | ||
); | ||
}); | ||
|
||
it("Should hash message using sha256", () => { | ||
expect(sha256(utf8ToBytes("sha256"))).to.be.deep.equal( | ||
hexToBytes("5d5b09f6dcb2d53a5fffc60c4ac0d55fabdf556069d6631545f42aa6e3500f2e") | ||
); | ||
}); | ||
}); |
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,7 @@ | ||
import { blake2b } from "@noble/hashes/blake2b"; | ||
import { sha256 as nobleSha256 } from "@noble/hashes/sha256"; | ||
import { BytesInput } from "./types"; | ||
|
||
export const blake2b256 = (message: BytesInput) => blake2b(message, { dkLen: 32 }); | ||
|
||
export const sha256 = nobleSha256 as (message: BytesInput) => Uint8Array; |
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 @@ | ||
export * from "./hashes"; |
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 @@ | ||
export type BytesInput = Uint8Array | string; |
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,8 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"module": "ESNext", | ||
"outDir": "dist/esm" | ||
} | ||
} |
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,8 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"rootDir": "./src", | ||
"outDir": "dist/cjs" | ||
}, | ||
"include": ["src/**/*.ts"] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.