Skip to content
Open
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 .eslintignore

This file was deleted.

11 changes: 0 additions & 11 deletions .eslintrc.json

This file was deleted.

5 changes: 1 addition & 4 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no -- commitlint --edit
npx --no -- commitlint --edit
3 changes: 0 additions & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run test
3 changes: 0 additions & 3 deletions .prettierrc.js

This file was deleted.

8 changes: 8 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://json.schemastore.org/prettierrc",
"semi": false,
"tabWidth": 2,
"singleQuote": true,
"printWidth": 100,
"trailingComma": "none"
}
123 changes: 72 additions & 51 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
# Changelog

## [2.5.0] - 2025-08-08

### Added

- **API Methods**

Added `address` option for the `api.getDelegate()` method
Added the `api.getPeer()` method

- **WebSocket**

Added:
- `onMessage(MessageType, handler)`
- `onChatMessage(handler)`
- `onRichMessage(handler)`
- `onSignalMessage(handler)`

### Fixed

- Fixed subscribing to multiple addresses

### Changed

- Updated dependencies
- Updated auto generated API types

## [2.4.0] - 2024-05-30

### Fixed
Expand Down Expand Up @@ -28,12 +54,12 @@
const transformed = transformTransactionQuery({
fromHeight: 7585271,
and: {
toHeight: 7586280,
toHeight: 7586280
},
or: {
senderId: 'U18132012621449491414',
},
});
senderId: 'U18132012621449491414'
}
})

/**
* {
Expand All @@ -42,7 +68,7 @@
* or:senderId: 'U18132012621449491414'
* }
*/
console.log(transformed);
console.log(transformed)
```

### Fixed
Expand All @@ -57,12 +83,12 @@
const blocks = await api.getTransactions({
fromHeight: 7585271,
and: {
toHeight: 7586280,
toHeight: 7586280
},
or: {
senderId: 'U18132012621449491414',
},
});
senderId: 'U18132012621449491414'
}
})
```

## [2.2.0] - 2023-12-01
Expand All @@ -72,20 +98,18 @@
- Export validator utils:

```ts
function isPassphrase(passphrase: unknown): passphrase is string;
function isAdmAddress(address: unknown): address is AdamantAddress;
function isAdmPublicKey(publicKey: unknown): publicKey is string;
function isAdmVoteForPublicKey(publicKey: unknown): publicKey is string;
function isAdmVoteForAddress(address: unknown): boolean;
function isAdmVoteForDelegateName(
delegateName: unknown
): delegateName is string;
function isPassphrase(passphrase: unknown): passphrase is string
function isAdmAddress(address: unknown): address is AdamantAddress
function isAdmPublicKey(publicKey: unknown): publicKey is string
function isAdmVoteForPublicKey(publicKey: unknown): publicKey is string
function isAdmVoteForAddress(address: unknown): boolean
function isAdmVoteForDelegateName(delegateName: unknown): delegateName is string
function validateMessage(
message: string,
messageType: MessageType = MessageType.Chat
): {success: false; error: string} | {success: true};
function isDelegateName(name: unknown): name is string;
function admToSats(amount: number): number;
): { success: false; error: string } | { success: true }
function isDelegateName(name: unknown): name is string
function admToSats(amount: number): number
```

## [2.1.0] - 2023-11-17
Expand All @@ -97,11 +121,11 @@
```js
const socket = new WebSocketClient({
/* ... */
});
})

api.initSocket(socket);
api.initSocket(socket)
// instead of
api.socket = socket;
api.socket = socket
```

- Improved the `encodeMessage()` and `decodeMessage()` functions to accept public keys as Uint8Array or Buffer
Expand Down Expand Up @@ -131,7 +155,7 @@
For example, you can now use `'log'` instead of `LogLevel.Log` in TypeScript:

```ts
const api = new AdamantApi({/* ... */ logLevel: 'log'});
const api = new AdamantApi({ /* ... */ logLevel: 'log' })
```

- TypeScript: Added missing declaration modules to npm that led to the error:
Expand Down Expand Up @@ -164,25 +188,25 @@

```js
// before
const block = await api.get('blocks/get', {id});
const block = await api.get('blocks/get', { id })

// after
const block = await api.getBlock(id);
const block = await api.getBlock(id)
```

and `post()` method:

```js
await api.post('transactions/process', {transaction});
await api.post('transactions/process', { transaction })
```

- **getTransactionId()** method

Pass signed transaction with signature to get a transaction id as a string:

```js
import {getTransactionId} from 'adamant-api';
const id = getTransactionId(signedTransaction);
import { getTransactionId } from 'adamant-api'
const id = getTransactionId(signedTransaction)
```

_See [documentation](https://github.com/Adamant-im/adamant-api-jsclient/wiki/Calculating-transaction-id) for more information._
Expand All @@ -204,13 +228,13 @@
Now you will create new instances of `adamant-api` using keyword `new`:

```js
import {AdamantApi} from 'adamant-api';
import { AdamantApi } from 'adamant-api'

const api = new AdamantApi({
nodes: [
/* ... */
],
});
]
})
```

- **Socket Initialization**
Expand All @@ -225,50 +249,47 @@
admAddress: 'U1234..',
onNewMessage(transaction) {
// ...
},
});
}
})

// after
api.initSocket({admAddress: 'U1234..'});
api.initSocket({ admAddress: 'U1234..' })

api.socket.on((transaction: AnyTransaction) => {
// ...
});
})
```

Or specify `socket` option when initializing API:

```ts
// socket.ts
import {WebSocketClient, TransactionType} from 'adamant-api';
import { WebSocketClient, TransactionType } from 'adamant-api'

const socket = new WebSocketClient({admAddress: 'U1234..'});
const socket = new WebSocketClient({ admAddress: 'U1234..' })

socket.on(
[TransactionType.CHAT_MESSAGE, TransactionType.SEND],
transaction => {
// handle chat messages and transfer tokens transactions
}
);
socket.on([TransactionType.CHAT_MESSAGE, TransactionType.SEND], (transaction) => {
// handle chat messages and transfer tokens transactions
})

socket.on(TransactionType.VOTE, transaction => {
socket.on(TransactionType.VOTE, (transaction) => {
// handle vote for delegate transaction
});
})

export {socket};
export { socket }
```

```ts
// api.ts
import {AdamantApi} from 'adamant-api';
import {socket} from './socket';
import { AdamantApi } from 'adamant-api'
import { socket } from './socket'

export const api = new AdamantApi({
socket,
nodes: [
/* ... */
],
});
]
})
```

### Removed
Expand Down
3 changes: 0 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,12 @@ Then, copy `dist/generated.ts` to `adamant-api-jsclient` at `src/api/generated.t
## Project Structure

- **`src`**: contains the source code

- **`api`**: contains group of methods and methods for the API.

- **`genearated.ts`**: contains auto-generated types for API.

- **`coins`**: contains group of utils for coins.

- **`helpers`**: contains utilities shared across the entire codebase.

- **`tests`**: contains tests for the helpers directory.

## Contributing Tests
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ Initialize the library:
const { AdamantApi } = require('adamant-api')

const nodes = [
"http://localhost:36666",
"https://endless.adamant.im",
"https://clown.adamant.im",
"http://23.226.231.225:36666",
"http://88.198.156.44:36666",
"https://lake.adamant.im"
];
'http://localhost:36666',
'https://endless.adamant.im',
'https://clown.adamant.im',
'http://23.226.231.225:36666',
'http://88.198.156.44:36666',
'https://lake.adamant.im'
]

const api = new AdamantApi({
nodes,
});
nodes
})
```

Request example:
Expand Down
4 changes: 2 additions & 2 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
extends: ['@commitlint/config-conventional'],
};
extends: ['@commitlint/config-conventional']
}
31 changes: 31 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import js from '@eslint/js'
import globals from 'globals'
import tseslint from 'typescript-eslint'
import json from '@eslint/json'
import { defineConfig, globalIgnores } from 'eslint/config'

export default defineConfig([
globalIgnores(['dist/', 'package-lock.json']),
{
files: ['**/*.{js,mjs,cjs,ts,mts,cts}'],
plugins: { js },
extends: ['js/recommended']
},
{
files: ['**/*.{js,mjs,cjs,ts,mts,cts}'],
languageOptions: { globals: globals.node }
},
tseslint.configs.recommended,
{
files: ['**/*.json'],
plugins: { json },
language: 'json/json',
extends: ['json/recommended']
},
{
files: ['**/*.json5'],
plugins: { json },
language: 'json/json5',
extends: ['json/recommended']
}
])
Loading