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

Miscellaneous Fixes #30

Draft
wants to merge 28 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3c9636a
remove mathjs
micahkendall Dec 29, 2023
f8cf501
removed ogmios
micahkendall Dec 29, 2023
47f304f
merge main
micahkendall Dec 30, 2023
b601f47
overestimates, script data hash
micahkendall Dec 30, 2023
7ab9ee6
only calculate scripthash when there's redeemers
micahkendall Jan 2, 2024
43a7591
Cache protocol params
micahkendall Jan 5, 2024
943041d
Overestimate failure fix
micahkendall Jan 5, 2024
47422a9
round
micahkendall Jan 5, 2024
96cad95
seperate out estimates
micahkendall Jan 5, 2024
d5fb58c
bump uplc
micahkendall Jan 6, 2024
c45e750
fix npm compat
micahkendall Jan 7, 2024
5117483
browser fix
micahkendall Jan 7, 2024
da5467e
uplc fix
micahkendall Jan 7, 2024
fca2c7a
no more crypto
micahkendall Jan 7, 2024
6a5e4eb
get rid of tiny-sha
micahkendall Jan 8, 2024
ca898be
remove old scripts
micahkendall Jan 8, 2024
523b206
better collateral utxo finding
micahkendall Jan 11, 2024
fbefd9b
fetch best ada amount to solve not enough ada for change
micahkendall Jan 12, 2024
73b8d97
fix ada amount search
micahkendall Jan 12, 2024
5276015
fix
micahkendall Jan 12, 2024
89c6304
ada input should not be used in utxo balancing
micahkendall Jan 16, 2024
3a1e5c8
select utxos last
micahkendall Jan 16, 2024
3071a79
do not double add collateral
micahkendall Jan 16, 2024
7f5c22a
custom balancing
micahkendall Jan 17, 2024
59f8e10
input balancer fix
micahkendall Jan 17, 2024
e215518
patch collateral not found
micahkendall Jan 24, 2024
0f3c71c
remove comment
micahkendall Jan 24, 2024
05847b9
fix collateral input edge case
micahkendall Feb 7, 2024
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
Binary file modified bun.lockb
Binary file not shown.
18 changes: 8 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
{
"name": "translucent-cardano",
"module": "index.ts",
"main": "index.ts",
"type": "module",
"version": "0.0.2",
"scripts": {
"build:wasm": "cd ./uplc && ./build.sh && rm pkg-node/.gitignore && rm pkg-web/.gitignore && cd .. && npm i"
},
"devDependencies": {
"@types/jest": "^29.5.5",
"@types/sha256": "^0.2.2",
"bun-types": "latest",
"eslint": "^8.50.0",
"jest": "^29.7.0",
"ts-jest": "^29.1.1",
"typescript": "^5.3.3",
"@cardano-ogmios/schema": "^6.0.0-rc6"
"typescript": "^5.3.3"
},
"dependencies": {
"@aws-crypto/sha256-browser": "^5.2.0",
"@dcspark/cardano-multiplatform-lib-browser": "^3.1.2",
"@dcspark/cardano-multiplatform-lib-nodejs": "^3.1.2",
"@emurgo/cardano-message-signing-browser": "^1.0.1",
"@emurgo/cardano-message-signing-nodejs": "^1.0.1",
"@sinclair/typebox": "^0.31.28",
"fast-check": "^3.14.0",
"mathjs": "^12.2.1",
"prettier": "^3.1.1",
"sha256": "^0.2.0",
"uplc-node": "^0.0.2",
"uplc-web": "^0.0.2"
"uplc-node": "^0.0.3",
"uplc-web": "^0.0.3"
},
"browser": {
"./core/core.ts": "./core/core-browser.ts"
"@dcspark/cardano-multiplatform-lib-nodejs": "@dcspark/cardano-multiplatform-lib-browser",
"@emurgo/cardano-message-signing-nodejs": "@emurgo/cardano-message-signing-browser",
"uplc-node": "uplc-web"
},
"peerDependencies": {
"typescript": "^5.0.0"
Expand Down
5 changes: 0 additions & 5 deletions src/core/core-browser.ts

This file was deleted.

28 changes: 16 additions & 12 deletions src/misc/bip39.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This is a partial reimplementation of BIP39 in Deno: https://github.com/bitcoinjs/bip39
// We only use the default Wordlist (english)
import { toHex } from "../utils/mod.ts";
import sha256 from "sha256";
import {Sha256} from '@aws-crypto/sha256-browser'

const INVALID_MNEMONIC = "Invalid mnemonic";
const INVALID_ENTROPY = "Invalid entropy";
Expand All @@ -10,10 +10,10 @@ const WORDLIST_REQUIRED =
"A wordlist is required but a default could not be found.\n" +
"Please pass a 2048 word array explicitly.";

export function mnemonicToEntropy(
export async function mnemonicToEntropy(
mnemonic: string,
wordlist?: Array<string>,
): string {
): Promise<string> {
wordlist = wordlist || DEFAULT_WORDLIST;
if (!wordlist) {
throw new Error(WORDLIST_REQUIRED);
Expand Down Expand Up @@ -48,7 +48,7 @@ export function mnemonicToEntropy(
throw new Error(INVALID_ENTROPY);
}
const entropy = new Uint8Array(entropyBytes);
const newChecksum = deriveChecksumBits(entropy);
const newChecksum = await deriveChecksumBits(entropy);
if (newChecksum !== checksumBits) {
throw new Error(INVALID_CHECKSUM);
}
Expand Down Expand Up @@ -83,24 +83,24 @@ function randomBytes(size: number): Uint8Array {
return bytes;
}

export function generateMnemonic(
export async function generateMnemonic(
strength: number,
rng?: (size: number) => Uint8Array,
wordlist?: Array<string>,
): string {
): Promise<string> {
strength = strength || 128;
if (strength % 32 !== 0) {
throw new TypeError(INVALID_ENTROPY);
}

rng = rng || randomBytes;
return entropyToMnemonic(rng(strength / 8), wordlist);
return await entropyToMnemonic(rng(strength / 8), wordlist);
}

function entropyToMnemonic(
async function entropyToMnemonic(
entropy: Uint8Array,
wordlist?: Array<string>,
): string {
): Promise<string> {
wordlist = wordlist || DEFAULT_WORDLIST;
if (!wordlist) {
throw new Error(WORDLIST_REQUIRED);
Expand All @@ -116,7 +116,7 @@ function entropyToMnemonic(
throw new TypeError(INVALID_ENTROPY);
}
const entropyBits = bytesToBinary(Array.from(entropy));
const checksumBits = deriveChecksumBits(entropy);
const checksumBits = await deriveChecksumBits(entropy);
const bits = entropyBits + checksumBits;
const chunks = bits.match(/(.{1,11})/g);
const words = chunks!.map((binary) => {
Expand All @@ -128,10 +128,14 @@ function entropyToMnemonic(
: words.join(" ");
}

function deriveChecksumBits(entropyBuffer: Uint8Array): string {
async function deriveChecksumBits(entropyBuffer: Uint8Array): Promise<string> {
const ENT = entropyBuffer.length * 8;
const CS = ENT / 32;
const hash = sha256(Array.from(entropyBuffer), { asBytes: true });
const hasher = new Sha256();
hasher.update(entropyBuffer);
const hash = await hasher.digest();

//const hash = sha256(Array.from(entropyBuffer), { asBytes: true });
return bytesToBinary(Array.from(hash)).slice(0, CS);
}

Expand Down
Loading