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

Frankie/i#376 tsc #400

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion index.cjs

This file was deleted.

File renamed without changes.
1 change: 0 additions & 1 deletion keys.cjs

This file was deleted.

File renamed without changes.
42 changes: 17 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,51 @@
"description": "JS SDK for entropy blockchain ",
"type": "module",
"files": [
"index.cjs",
"index.mjs",
"keys.cjs",
"keys.mjs",
"index.js",
"keys.js",
"utils.js",
"dist/**/*",
"dev/**/*",
"README.md"
],
"exports": {
".": {
"import": "./index.mjs",
"require": "./index.cjs",
"default": "./dist/index.js",
"import": "./index.js",
"default": "./index.js",
"types": "./dist/index.d.ts"
},
"./keys": {
"import": "./keys.mjs",
"require": "./keys.cjs",
"default": "./dist/keys/index.js",
"import": "./keys.js",
"default": "./keys.js",
"types": "./dist/keys/index.d.ts"
},
"./utils": {
"import": "./dist/utils/index.js",
"require": "./dist/utils/index.cjs",
"default": "./dist/utils/index.js",
"import": "./utils.js",
"default": "./utils.js",
"types": "./dist/utils/index.d.ts"
},
"./testing": {
"import": "./dev/testing-utils.mjs"
}
},
"module": "./index.mjs",
"main": "./index.cjs",
"main": "./index.js",
"module": "./index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "yarn test:setup && yarn test:types && yarn test:ts && yarn test:only && yarn test:require && yarn test:import",
"test": "yarn test:setup && yarn test:types && yarn test:cjs && yarn test:mjs && yarn test:ts && yarn test:only",
"test:setup": "./dev/bin/check-tools.sh && yarn build",
"test:types": "tsc",
"test:types": "tsc --noEmit",
"test:ts": "yarn removedb && ./dev/bin/test-ts.sh",
"test:require": "node tests/require.test.cjs | tap-spec",
"test:import": "node tests/import.test.mjs | tap-spec",
"test:cjs": "node tests/import.test.cjs | tap-spec",
"test:mjs": "node tests/import.test.mjs | tap-spec",
"test:only": "./dev/bin/test-only.sh",
"test:coverage": "nyc yarn test",
"lint": "yarn lint:ts && yarn lint:eslint",
"lint:ts": "tsc",
"lint:eslint": "eslint . --ext .ts --fix",
"peek": "tsc --build --clean",
"burn": "rm -Rf node_modules && yarn cache clean --all && yarn install",
"build": "tsup",
"build:watch": "tsup --watch",
"build:node": "tsup --platform node ",
"build:browser": "tsup --platform browser",
"build": "rm -rf dist && tsc",
"build:link": "yarn build && yarn unlink && yarn link",
"find-deadcode": "ts-prune",
"generate:types": "dev/bin/generate-types.sh",
Expand Down Expand Up @@ -96,7 +89,6 @@
"tape": "^5.7.5",
"ts-node": "^10.9.1",
"ts-prune": "^0.10.3",
"tsup": "^6.5.0",
"tsx": "^4.9.3",
"typedoc": "^0.25.3",
"typedoc-plugin-merge-modules": "^5.1.0",
Expand All @@ -108,7 +100,7 @@
"dependencies": {
"@entropyxyz/entropy-protocol-nodejs": "^0.2.0",
"@entropyxyz/entropy-protocol-web": "^0.2.0",
"@polkadot/api": "^10.13.1",
"@polkadot/api": "10.13.1",
"@types/node": "^20.12.12",
"debug": "^4.3.4",
"hpke-js": "^1.2.7",
Expand Down
4 changes: 2 additions & 2 deletions src/extrinsic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { EventRecord } from '@polkadot/types/interfaces/types'
import { SubmittableExtrinsic } from '@polkadot/api/types'
import { RegistryError } from '@polkadot/types-codec/types'

import { Signer } from '../keys/types/internal'
import { EventFilter } from '../types/internal'
import { Signer } from '../keys/types/internal.js'
import { EventFilter } from '../types/internal.js'

interface Decoded extends RegistryError {
name: string
Expand Down
23 changes: 12 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { ApiPromise, WsProvider } from '@polkadot/api'
import xtend from 'xtend'
import { isValidSubstrateAddress as isDeployer } from './utils'
import RegistrationManager, { RegistrationParams } from './registration'
import SignatureRequestManager, { SigOps, SigWithAdaptersOps } from './signing'
import { crypto, loadCryptoLib } from './utils/crypto'
import { Adapter } from './signing/adapters/types'
import ProgramManager from './programs'
import Keyring from './keys'
import { keysCryptoWaitReady } from './keys/utils'
import { ChildKey } from './keys/types/constants'
import { DEVICE_KEY_PROXY_PROGRAM_INTERFACE } from './signing/adapters/device-key-proxy'
import { HexString } from './keys/types/json'

import { isValidSubstrateAddress as isDeployer } from './utils/index.js'
import RegistrationManager, { RegistrationParams } from './registration/index.js'
import SignatureRequestManager, { SigOps, SigWithAdaptersOps } from './signing/index.js'
import { crypto, loadCryptoLib } from './utils/crypto/index.js'
import ProgramManager from './programs/index.js'
import Keyring from './keys/index.js'
import { keysCryptoWaitReady } from './keys/utils.js'
import { DEVICE_KEY_PROXY_PROGRAM_INTERFACE } from './signing/adapters/device-key-proxy.js'
import { Adapter } from './signing/adapters/types.js'
import { ChildKey } from './keys/types/constants.js'
import { HexString } from './keys/types/json.js'

export async function wasmGlobalsReady () {
await loadCryptoLib()
Expand Down
14 changes: 7 additions & 7 deletions src/keys/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import EventEmitter from 'node:events'
import { deepCopy } from '../utils/housekeeping'
import * as utils from './utils'
import { EntropyAccount, KeyMaterial, PairMaterial } from './types/json'
import { EventEmitter } from 'node:events'
import { deepCopy } from '../utils/housekeeping/index.js'
import * as utils from './utils.js'
import { EntropyAccount, KeyMaterial, PairMaterial } from './types/json.js'
import {
ChildKey,
EntropyAccountType,
EntropyAccountContextType,
} from './types/constants'
import { Signer } from './types/internal'
import { AccountsEmitter } from './types'
} from './types/constants.js'
import { Signer } from './types/internal.js'
import { AccountsEmitter } from './types/index.js'

// Whats the point of remapping here?
// .map of object.keys is same as object.values, and either way the
Expand Down
6 changes: 3 additions & 3 deletions src/keys/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* */

import { EventEmitter } from 'node:events'
import { EntropyAccountType, ChildKey } from './constants'
import { EntropyAccount, PairMaterial } from './json'
import { Signer } from './internal'
import { EntropyAccountType, ChildKey } from './constants.js'
import { EntropyAccount, PairMaterial } from './json.js'
import { Signer } from './internal.js'
export type RegisteredAccountType = 'Private' | 'Public'

export interface AccountsEmitter extends EventEmitter {
Expand Down
4 changes: 2 additions & 2 deletions src/keys/types/internal.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import EventEmitter from 'node:events'
import * as EventEmitter from 'node:events'
import { Keys } from '@polkadot/types/interfaces/types'
import { KeyringPair } from '@polkadot/keyring/types'
import { ChildKey } from './constants'
import { ChildKey } from './constants.js'

/**
* Keep this in mind when dealing with Polkadot:
Expand Down
2 changes: 1 addition & 1 deletion src/keys/types/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
ChildKey,
EntropyAccountType,
EntropyAccountContextType,
} from './constants'
} from './constants.js'

export type UIDv4 = string

Expand Down
6 changes: 3 additions & 3 deletions src/keys/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import {
sr25519PairFromSeed,
cryptoWaitReady,
} from '@polkadot/util-crypto'
import { debug } from '../utils'
import { Pair } from './types/internal'
import { ChildKeyBasePaths } from './types/constants'
import { debug } from '../utils/index.js'
import { Pair } from './types/internal.js'
import { ChildKeyBasePaths } from './types/constants.js'

export const keysCryptoWaitReady = cryptoWaitReady()

Expand Down
9 changes: 5 additions & 4 deletions src/programs/dev.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import ExtrinsicBaseClass from '../extrinsic'
import { ApiPromise } from '@polkadot/api'
import { Signer } from '../keys/types/internal'
import { SubmittableExtrinsic } from '@polkadot/api/types'
import { hex2buf, stripHexPrefix } from '../utils'
import * as util from '@polkadot/util'
import { HexString } from '../keys/types/json'

import ExtrinsicBaseClass from '../extrinsic/index.js'
import { Signer } from '../keys/types/internal.js'
import { HexString } from '../keys/types/json.js'
import { hex2buf, stripHexPrefix } from '../utils/index.js'

/**
* Represents program information.
Expand Down
7 changes: 4 additions & 3 deletions src/programs/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { ApiPromise } from '@polkadot/api'
import { SubmittableExtrinsic } from '@polkadot/api/types'
import ExtrinsicBaseClass from '../extrinsic'
import ProgramDev from './dev'
import { Signer } from '../keys/types/internal'

import ProgramDev from './dev.js'
import ExtrinsicBaseClass from '../extrinsic/index.js'
import { Signer } from '../keys/types/internal.js'

export interface ProgramInstance {
program_pointer: string
Expand Down
11 changes: 6 additions & 5 deletions src/registration/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { ApiPromise } from '@polkadot/api'
import ExtrinsicBaseClass from '../extrinsic'
import { HexString, SS58Address } from '../keys/types/json'
import { ProgramInstance } from '../programs'
import { Signer } from '../keys/types/internal'
import { Address } from '../types/internal'

import ExtrinsicBaseClass from '../extrinsic/index.js'
import { ProgramInstance } from '../programs/index.js'
import { Signer } from '../keys/types/internal.js'
import { HexString, SS58Address } from '../keys/types/json.js'
import { Address } from '../types/internal.js'

export interface RegistrationParams {
/** initial programs associated with the user */
Expand Down
8 changes: 4 additions & 4 deletions src/signing/adapters/base.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*eslint-disable*/
// @ts-nocheck
import { HexString } from '../../keys/types/json'
import { Signer } from '../../keys/types/internal'
import { AUX_DATA, PRESIGN_RESULT } from './types'
import { toHex } from '../../utils'
import { AUX_DATA, PRESIGN_RESULT } from './types.js'
import { HexString } from '../../keys/types/json.js'
import { Signer } from '../../keys/types/internal.js'
import { toHex } from '../../utils/index.js'

/**
* The configuration for the specific program
Expand Down
4 changes: 2 additions & 2 deletions src/signing/adapters/default.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as deviceKeyProxy from './device-key-proxy'
import * as noop from './noop'
import * as deviceKeyProxy from './device-key-proxy.js'
import * as noop from './noop.js'

export const defaultAdapters = {
deviceKeyProxy,
Expand Down
9 changes: 5 additions & 4 deletions src/signing/adapters/device-key-proxy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { HexString } from '../../keys/types/json'
import { Signer } from '../../keys/types/internal'
import { AUX_DATA, PRESIGN_RESULT } from './types'
import { toHex } from '../../utils'
import { toHex } from '../../utils/index.js'
import { AUX_DATA, PRESIGN_RESULT } from './types.js'
import { HexString } from '../../keys/types/json.js'
import { Signer } from '../../keys/types/internal.js'

export interface UserConfig {
ecdsaPublicKeys?: HexString[]
sr25519PublicKeys?: HexString[]
Expand Down
8 changes: 4 additions & 4 deletions src/signing/adapters/noop.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HexString } from '../../keys/types/json'
import { Signer } from '../../keys/types/internal'
import { PRESIGN_RESULT } from './types'
import { toHex } from '../../utils'
import { toHex } from '../../utils/index.js'
import { HexString } from '../../keys/types/json.js'
import { Signer } from '../../keys/types/internal.js'
import { PRESIGN_RESULT } from './types.js'

/**
*
Expand Down
6 changes: 3 additions & 3 deletions src/signing/adapters/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MsgParams } from '..'
import { Signer } from '../../keys/types/internal'
import { HexString } from '../../keys/types/json'
import { MsgParams } from '../index.js'
import { Signer } from '../../keys/types/internal.js'
import { HexString } from '../../keys/types/json.js'

/**
* THIS TYPE DENOTES AUXILIARY DATA MUST BE ABLE TO PASS JSON.stringify()
Expand Down
16 changes: 8 additions & 8 deletions src/signing/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ApiPromise } from '@polkadot/api'
import { Signer } from '../keys/types/internal'
import { defaultAdapters } from './adapters/default'
import { Adapter } from './adapters/types'
import { EncMsg, ValidatorInfo } from '../types/internal'
import { stripHexPrefix, sendHttpPost, toHex } from '../utils'
import { crypto } from '../utils/crypto'
import { CryptoLib } from '../utils/crypto/types'
import Keyring from '../keys'
import { defaultAdapters } from './adapters/default.js'
import { stripHexPrefix, sendHttpPost, toHex } from '../utils/index.js'
import { crypto } from '../utils/crypto/index.js'
import Keyring from '../keys/index.js'
import { EncMsg, ValidatorInfo } from '../types/internal.js'
import { Signer } from '../keys/types/internal.js'
import { Adapter } from './adapters/types.js'
import { CryptoLib } from '../utils/crypto/types/index.js'

export interface Config {
keyring: Keyring
Expand Down
2 changes: 1 addition & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* */

// are we sure this is right?
import Entropy from './../index'
import Entropy from './../index.js'

export type EntropyInstance = InstanceType<typeof Entropy>

Expand Down
2 changes: 1 addition & 1 deletion src/types/internal.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* These are internal facing types
* */
import Entropy from './../index'
import type { AccountId32 } from '@polkadot/types/interfaces/runtime'
import Entropy from './../index.js'

/**
* Represents an instance of the Entropy class.
Expand Down
4 changes: 2 additions & 2 deletions src/utils/crypto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import {
decodeAddress,
signatureVerify,
} from '@polkadot/util-crypto'

import * as polkadotCryptoUtil from '@polkadot/util-crypto'
import { CryptoLib, ResObjectType } from './types'
import { u8aToHex } from '@polkadot/util'

import { CryptoLib, ResObjectType } from './types/index.js'

let cryptoLib
const res: ResObjectType = {
resolve: () => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { decodeAddress, encodeAddress } from '@polkadot/keyring'
import { hexToU8a, isHex } from '@polkadot/util'
import Debug from 'debug'
import { Address } from '../types/internal'
import { Address } from '../types/internal.js'

export const debug = Debug('@entropyxyz/sdk')

Expand Down
8 changes: 5 additions & 3 deletions tests/require.test.cjs → tests/import.test.cjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
const test = require('tape')
const { default: DefaultEntropy, Entropy, wasmGlobalsReady } = require('@entropyxyz/sdk')
const { default: DefaultKeyring, Keyring } = require('@entropyxyz/sdk/keys')

const charlieSeed = '0xbc1ede780f784bb6991a585e4f6e61522c14e1cae6ad0895fb57b9a205a8f938'

test('CJS require', async t => {
test('CJS import()', async t => {
try {
const { default: DefaultEntropy, Entropy, wasmGlobalsReady } = await import('@entropyxyz/sdk')
const { default: DefaultKeyring, Keyring } = await import('@entropyxyz/sdk/keys')

t.deepEqual(DefaultEntropy, Entropy, 'Entropy exported as default + named')
await wasmGlobalsReady()

t.true(
typeof Entropy === 'function'
&& Entropy.name === 'Entropy',
Expand Down
Loading