Skip to content

Commit

Permalink
build(wip): transactions started, many errors
Browse files Browse the repository at this point in the history
  • Loading branch information
aulneau committed Oct 6, 2020
1 parent 5848fb4 commit 16ea055
Show file tree
Hide file tree
Showing 18 changed files with 90 additions and 65 deletions.
24 changes: 10 additions & 14 deletions packages/transactions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
"description": "Javascript library for constructing transactions on the Stacks blockchain.",
"homepage": "https://blockstack.org",
"license": "GPL-3.0-or-later",
"main": "./dist/index.js",
"umd:main": "./dist/auth.umd.production.js",
"module": "./dist/auth.esm.js",
"directories": {
"lib": "lib",
"dist": "dist",
Expand Down Expand Up @@ -75,7 +72,7 @@
"ripemd160-min": "^0.0.6",
"sha.js": "^2.4.11",
"smart-buffer": "^4.1.0",
"tsdx": "^0.13.3"
"tsdx": "^0.14.0"
},
"publishConfig": {
"access": "public"
Expand All @@ -85,18 +82,17 @@
"url": "git+https://github.com/blockstack/blockstack.js.gi.git"
},
"scripts": {
"build": "cross-env NODE_ENV=production tsdx build --format=cjs,esm,umd",
"build-all": "run-p build:*",
"build:cjs": "tsc --outDir ./lib -m commonjs -t es2017",
"build:esm": "tsc --outDir ./lib-esm -m es6 -t es2017",
"build:cjs:watch": "tsc --outDir ./lib -m commonjs -t es2017 --watch",
"build:esm:watch": "tsc --outDir ./lib-esm -m es6 -t es2017 --watch",
"build:docs": "rimraf docs && cross-env typedoc --name \"stacks-transactions-js $npm_package_version Library Reference\" --tsconfig tsconfig.typedoc.json --out docs --json docs/docs.json src",
"lint": "eslint ./src --ext .ts -f codeframe",
"lint:fix": "eslint ./src --ext .ts --fix",
"lint": "yarn lint:eslint && yarn lint:prettier",
"lint:eslint": "eslint \"src/**/*.{ts,tsx}\" -f unix",
"lint:fix": "eslint \"src/**/*.{ts,tsx}\" -f unix --fix",
"lint:prettier": "prettier --check \"src/**/*.{ts,tsx}\" *.js",
"lint:prettier:fix": "prettier --write \"src/**/*.{ts,tsx}\" *.js",
"start": "tsdx watch --verbose --noClean --onSuccess yalc publish --push",
"build": "tsdx build --format cjs,esm,umd",
"typecheck": "tsc --noEmit",
"typecheck:watch": "npm run typecheck -- --watch",
"test": "jest --coverage",
"prepublishOnly": "npm run test && npm run build",
"typecheck": "tsc -p tsconfig.build.json --noEmit",
"codecovUpload": "codecov"
},
"bugs": {
Expand Down
7 changes: 3 additions & 4 deletions packages/transactions/src/authorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import {
RECOVERABLE_ECDSA_SIG_LENGTH_BYTES,
SingleSigHashMode,
MultiSigHashMode,
AddressVersion,
StacksMessageType,
} from './constants';

import { BufferArray, txidFromData, sha512_256, leftPadHex, cloneDeep } from './utils';
import { BufferArray, txidFromData, leftPadHex, cloneDeep } from './utils';

import {
addressFromPublicKeys,
Expand All @@ -31,7 +30,7 @@ import {
publicKeyFromSignature,
} from './keys';

import * as BigNum from 'bn.js';
import BigNum from 'bn.js';
import { BufferReader } from './bufferReader';
import { SerializationError, DeserializationError, SigningError } from './errors';

Expand Down Expand Up @@ -428,7 +427,7 @@ function verifySingleSig(
initialSigHash: string,
authType: AuthType
): string {
const { pubKey, nextSigHash } = nextVerification(
const { nextSigHash } = nextVerification(
initialSigHash,
authType,
condition.fee,
Expand Down
2 changes: 1 addition & 1 deletion packages/transactions/src/builders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import { cvToHex, parseReadOnlyResponse, cloneDeep, omit } from './utils';

import { fetchPrivate } from '@stacks/common';

import * as BigNum from 'bn.js';
import BigNum from 'bn.js';
import { ClarityValue, PrincipalCV } from './clarity';
import { validateContractCall, ClarityAbi } from './contract-abi';
import { c32address } from 'c32check';
Expand Down
1 change: 0 additions & 1 deletion packages/transactions/src/clarity/clarityValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {

import { principalToString } from './types/principalCV';
import { CLARITY_INT_SIZE } from '../constants';
import { isClarityName } from '../utils';

/**
* Type IDs corresponding to each of the Clarity value types as described here:
Expand Down
2 changes: 1 addition & 1 deletion packages/transactions/src/clarity/types/intCV.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as BigNum from 'bn.js';
import BigNum from 'bn.js';
import { CLARITY_INT_SIZE } from '../../constants';
import { ClarityType } from '../clarityValue';

Expand Down
5 changes: 1 addition & 4 deletions packages/transactions/src/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ export function createStacksPublicKey(key: string): StacksPublicKey {

export function publicKeyFromSignature(message: string, messageSignature: MessageSignature) {
const ec = new EC('secp256k1');
const messageBN = ec
.keyFromPrivate(message, 'hex')
.getPrivate()
.toString(10);
const messageBN = ec.keyFromPrivate(message, 'hex').getPrivate().toString(10);

const parsedSignature = parseRecoverableSignature(messageSignature.data);

Expand Down
4 changes: 2 additions & 2 deletions packages/transactions/src/payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import {

import { ClarityValue, serializeCV, deserializeCV } from './clarity/';

import * as BigNum from 'bn.js';
import BigNum from 'bn.js';
import { BufferReader } from './bufferReader';
import { PrincipalCV, standardPrincipalCV, principalCV } from './clarity/types/principalCV';
import { PrincipalCV, principalCV } from './clarity/types/principalCV';

export type Payload =
| TokenTransferPayload
Expand Down
2 changes: 1 addition & 1 deletion packages/transactions/src/postcondition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
parsePrincipalString,
} from './types';

import * as BigNum from 'bn.js';
import BigNum from 'bn.js';
import { BufferReader } from './bufferReader';
import { ClarityValue, serializeCV, deserializeCV } from './clarity';
import { DeserializationError } from './errors';
Expand Down
4 changes: 1 addition & 3 deletions packages/transactions/src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
AuthType,
StacksMessageType,
ChainID,
AddressHashMode,
} from './constants';

import {
Expand All @@ -16,7 +15,6 @@ import {
nextSignature,
isSingleSig,
SingleSigSpendingCondition,
MultiSigSpendingCondition,
createTransactionAuthField,
createMessageSignature,
} from './authorization';
Expand All @@ -31,7 +29,7 @@ import { StacksPrivateKey, StacksPublicKey } from './keys';

import { BufferReader } from './bufferReader';

import * as BigNum from 'bn.js';
import BigNum from 'bn.js';
import { SerializationError, SigningError } from './errors';

export class StacksTransaction {
Expand Down
10 changes: 1 addition & 9 deletions packages/transactions/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ import {
PostConditionPrincipalID,
} from './constants';

import {
StacksPublicKey,
serializePublicKey,
deserializePublicKey,
isCompressed,
publicKeyToString,
} from './keys';
import { StacksPublicKey, serializePublicKey, deserializePublicKey, isCompressed } from './keys';

import {
BufferArray,
Expand All @@ -24,7 +18,6 @@ import {
hashP2PKH,
rightPadHexToLength,
hashP2SH,
hash160,
} from './utils';

import { c32addressDecode, c32address } from 'c32check';
Expand All @@ -40,7 +33,6 @@ import {
serializeTransactionAuthField,
TransactionAuthField,
} from './authorization';
import { deserialize } from 'v8';

export type StacksMessage =
| Address
Expand Down
16 changes: 2 additions & 14 deletions packages/transactions/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
import { sha256, sha512 } from 'sha.js';

import { ClarityValue, serializeCV } from './clarity';

import RIPEMD160 from 'ripemd160-min';

import * as randombytes_ from 'randombytes';

import randombytes from 'randombytes';
import { deserializeCV } from './clarity';

import fetch from 'cross-fetch';
import { c32addressDecode } from 'c32check';

// Note: lodash is using old-style ts exports and requires this
// @ts-expect-error
import * as lodashCloneDeep_ from 'lodash/cloneDeep';

let lodashCloneDeep = lodashCloneDeep_;

let randombytes = randombytes_;
import lodashCloneDeep from 'lodash/cloneDeep';

export { randombytes as randomBytes };

Expand Down
2 changes: 1 addition & 1 deletion packages/transactions/tests/authorization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { addressFromVersionHash } from '../src/types';

import { AddressHashMode, AddressVersion, PubKeyEncoding } from '../src/constants';

import * as BigNum from 'bn.js';
import BigNum from 'bn.js';
import { BufferReader } from '../src/bufferReader';
import {
createStacksPrivateKey,
Expand Down
2 changes: 1 addition & 1 deletion packages/transactions/tests/builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import { StacksTestnet, StacksMainnet } from '@stacks/network';

import { bufferCV, standardPrincipalCV, bufferCVFromString, serializeCV } from '../src/clarity';

import * as BigNum from 'bn.js';
import BigNum from 'bn.js';

import { ClarityAbi } from '../src/contract-abi';
import { createStacksPrivateKey, pubKeyfromPrivKey, publicKeyToString } from '../src/keys';
Expand Down
2 changes: 1 addition & 1 deletion packages/transactions/tests/payload.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { serializeDeserialize } from './macros';

import { trueCV, falseCV, standardPrincipalCV, contractPrincipalCV } from '../src/clarity';

import * as BigNum from 'bn.js';
import BigNum from 'bn.js';

import { COINBASE_BUFFER_LENGTH_BYTES, StacksMessageType } from '../src/constants';
import { principalToString } from '../src/clarity/types/principalCV';
Expand Down
2 changes: 1 addition & 1 deletion packages/transactions/tests/postcondition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {

import { serializeDeserialize } from './macros';

import * as BigNum from 'bn.js';
import BigNum from 'bn.js';
import { bufferCVFromString, BufferCV } from '../src/clarity';

test('STX post condition serialization and deserialization', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/transactions/tests/transaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import {

import { TransactionSigner } from '../src/signer';

import * as BigNum from 'bn.js';
import BigNum from 'bn.js';
import fetchMock from 'jest-fetch-mock';
import { BufferReader } from '../src/bufferReader';
import { standardPrincipalCV } from '../src/clarity';
Expand Down
53 changes: 47 additions & 6 deletions packages/transactions/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,48 @@
{
"extends": "../../tsconfig.json",
"include": [
"./src/**/*",
"./tests/**/*"
]
}
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"lib": ["dom", "esnext"],
"jsx": "react",
"importHelpers": true,
"declaration": true,
"sourceMap": true,
"moduleResolution": "node",
"forceConsistentCasingInFileNames": true,
"strict": true,
"pretty": true,
"removeComments": true,
"noImplicitAny": true,
"strictFunctionTypes": true,
"noImplicitThis": true,
"alwaysStrict": true,
"stripInternal": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"emitDecoratorMetadata": false,
"noEmit": false,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"suppressImplicitAnyIndexErrors": false,
"outDir": "./dist",
"baseUrl": "./src",
"rootDirs": ["./src"],
"skipLibCheck": true,
"esModuleInterop": true,
"strictNullChecks": true,
"paths": {
"@stacks/auth": ["../../auth/src"],
"@stacks/cli": ["../../cli/src"],
"@stacks/common": ["../../common/src"],
"@stacks/encryption": ["../../encryption/src"],
"@stacks/keychain": ["../../keychain/src"],
"@stacks/network": ["../../network/src"],
"@stacks/profile": ["../../profile/src"],
"@stacks/storage": ["../../storage/src"],
"@stacks/transactions": ["../../transactions/src"]
}
},
"include": ["src/**/*"]
}
15 changes: 15 additions & 0 deletions packages/transactions/tsdx.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
rollup(config, options) {
if (options.format === 'esm') {
config.output = {
...config.output,
dir: 'dist/',
entryFileNames: '[name].esm.js',
preserveModules: true,
preserveModulesRoot: 'src',
};
delete config.output.file;
}
return config;
},
};

0 comments on commit 16ea055

Please sign in to comment.