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

SERVICES-1131 rebranding #5

Merged
merged 1 commit into from
Jan 10, 2023
Merged
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
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ Native Authenticator for JavaScript and TypeScript (written in TypeScript).

## Distribution

[npm](https://www.npmjs.com/package/@elrondnetwork/native-auth)
[npm](https://www.npmjs.com/package/@multiversx/mx-sdk-erdjs-native-auth-client)

## Example

### Client-side

```js
Expand All @@ -15,7 +16,7 @@ const init = await client.initialize();

// obtain signature by signing the following message: `${address}${init}`
// Example:
// - if the address is `erd1qnk2vmuqywfqtdnkmauvpm8ls0xh00k8xeupuaf6cm6cd4rx89qqz0ppgl`
// - if the address is `erd1qnk2vmuqywfqtdnkmauvpm8ls0xh00k8xeupuaf6cm6cd4rx89qqz0ppgl`
// - and the init string is `YXBpLmVscm9uZC5jb20.066de4ba7df143f2383c3e0cd7ef8eeaf13375d1123ec8bafcef9f7908344b0f.86400.e30`
// - then the signable message should be `erd1qnk2vmuqywfqtdnkmauvpm8ls0xh00k8xeupuaf6cm6cd4rx89qqz0ppgl066de4ba7df143f2383c3e0cd7ef8eeaf13375d1123ec8bafcef9f7908344b0f.86400.e30`

Expand All @@ -37,15 +38,15 @@ When initializing the client object, an optional config can also be specified wi
// The endpoint from where the current block information will be fetched upon initialization.
// The default value points to the mainnet API, but can be overridden to be network-specific
// or to point to a self-hosted location
apiUrl: string = 'https://api.elrond.com';
apiUrl: string = 'https://api.multiversx.com';

// TTL that will be encoded in the access token.
// This value will also be validated by the server and must not be greater than the maximum ttl allowed.
// Default: one day (86400 seconds)
expirySeconds: number = 60 * 60 * 24;

// Optional, to fetch the block hash from a single shard.
// Useful in the situations where the server connects directly to a node to fetch block info
// Useful in the situations where the server connects directly to a node to fetch block info
// and would like a predictable shard for the validation of tokens
blockHashShard: 0;
}
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@elrondnetwork/native-auth-client",
"version": "0.1.5",
"name": "@multiversx/mx-sdk-erdjs-native-auth-client",
"version": "0.1.6",
"description": "Native authentication client-side",
"main": "lib/src/index.js",
"types": "lib/src/index.d.ts",
Expand All @@ -15,15 +15,15 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/ElrondNetwork/native-auth-client.git"
"url": "git+https://github.com/MultiversX/mx-sdk-erdjs-native-auth-client.git"
},
"keywords": [
"elrond",
"multiversx",
"native",
"auth",
"client"
],
"author": "ElrondNetwork",
"author": "MultiversX",
"license": "GPL-3.0-or-later",
"devDependencies": {
"@babel/core": "^7.17.8",
Expand All @@ -43,4 +43,4 @@
"dependencies": {
"axios": "^0.27.2"
}
}
}
2 changes: 1 addition & 1 deletion src/entities/native.auth.client.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export class NativeAuthClientConfig {
host: string = typeof window !== "undefined" ? window.location.hostname : '';
apiUrl: string = 'https://api.elrond.com';
apiUrl: string = 'https://api.multiversx.com';
expirySeconds: number = 60 * 60 * 24;
blockHashShard?: number;
gatewayUrl?: string;
Expand Down
30 changes: 15 additions & 15 deletions test/native.auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import { NativeAuthClient } from '../src';

describe("Native Auth", () => {
let mock: MockAdapter;
const ADDRESS = 'erd13rrn3fwjds8r5260n6q3pd2qa6wqkudrhczh26d957c0edyzermshds0k8';
const SIGNATURE = '4b445f287663b868e269aa0532c9fd73acb37cfd45f46e33995777e68e5ecc15d97318d9af09c4102f9b40ecf347a75e2d2e81acbcc3c72ae32fcf659c2acd0e';
const BLOCK_HASH = 'b3d07565293fd5684c97d2b96eb862d124fd698678f3f95b2515ed07178a27b4';
const ADDRESS = 'erd1qnk2vmuqywfqtdnkmauvpm8ls0xh00k8xeupuaf6cm6cd4rx89qqz0ppgl';
const SIGNATURE = '563cb2dfdf96ab335423a05287fa3cd00154034423d0062421ee6ce03230d941da6df9ce79689fcd173c0ba5d4331b3ccd82c8ec2e6ab4d875db1587c2ab720c';
const BLOCK_HASH = '82ec8044966efb2d00e8a6367ea23ddbc7bea6504ed98f4a1a536d7c21bb2682';
const TTL = 86400;
const HOST = 'elrond.com';
const TOKEN = `ZWxyb25kLmNvbQ.${BLOCK_HASH}.${TTL}.e30`;
const ACCESS_TOKEN = 'ZXJkMTNycm4zZndqZHM4cjUyNjBuNnEzcGQycWE2d3FrdWRyaGN6aDI2ZDk1N2MwZWR5emVybXNoZHMwazg.Wld4eWIyNWtMbU52YlEuYjNkMDc1NjUyOTNmZDU2ODRjOTdkMmI5NmViODYyZDEyNGZkNjk4Njc4ZjNmOTViMjUxNWVkMDcxNzhhMjdiNC44NjQwMC5lMzA.4b445f287663b868e269aa0532c9fd73acb37cfd45f46e33995777e68e5ecc15d97318d9af09c4102f9b40ecf347a75e2d2e81acbcc3c72ae32fcf659c2acd0e';
const HOST = 'api.multiversx.com';
const TOKEN = `YXBpLm11bHRpdmVyc3guY29t.${BLOCK_HASH}.${TTL}.e30`;
const ACCESS_TOKEN = 'ZXJkMXFuazJ2bXVxeXdmcXRkbmttYXV2cG04bHMweGgwMGs4eGV1cHVhZjZjbTZjZDRyeDg5cXF6MHBwZ2w.WVhCcExtMTFiSFJwZG1WeWMzZ3VZMjl0LjgyZWM4MDQ0OTY2ZWZiMmQwMGU4YTYzNjdlYTIzZGRiYzdiZWE2NTA0ZWQ5OGY0YTFhNTM2ZDdjMjFiYjI2ODIuODY0MDAuZTMw.563cb2dfdf96ab335423a05287fa3cd00154034423d0062421ee6ce03230d941da6df9ce79689fcd173c0ba5d4331b3ccd82c8ec2e6ab4d875db1587c2ab720c';

const onLatestBlockHashGet = function (mock: MockAdapter): RequestHandler {
return mock.onGet('https://api.elrond.com/blocks?size=1&fields=hash');
return mock.onGet('https://api.multiversx.com/blocks?size=1&fields=hash');
};

beforeAll(() => {
Expand Down Expand Up @@ -61,22 +61,22 @@ describe("Native Auth", () => {

describe("Native Auth with gateway", () => {
let mock: MockAdapter;
const ADDRESS = 'erd13rrn3fwjds8r5260n6q3pd2qa6wqkudrhczh26d957c0edyzermshds0k8';
const SIGNATURE = '4b445f287663b868e269aa0532c9fd73acb37cfd45f46e33995777e68e5ecc15d97318d9af09c4102f9b40ecf347a75e2d2e81acbcc3c72ae32fcf659c2acd0e';
const BLOCK_HASH = 'b3d07565293fd5684c97d2b96eb862d124fd698678f3f95b2515ed07178a27b4';
const ADDRESS = 'erd1qnk2vmuqywfqtdnkmauvpm8ls0xh00k8xeupuaf6cm6cd4rx89qqz0ppgl';
const SIGNATURE = '563cb2dfdf96ab335423a05287fa3cd00154034423d0062421ee6ce03230d941da6df9ce79689fcd173c0ba5d4331b3ccd82c8ec2e6ab4d875db1587c2ab720c';
const BLOCK_HASH = '82ec8044966efb2d00e8a6367ea23ddbc7bea6504ed98f4a1a536d7c21bb2682';
const TTL = 86400;
const HOST = 'elrond.com';
const TOKEN = `ZWxyb25kLmNvbQ.${BLOCK_HASH}.${TTL}.e30`;
const ACCESS_TOKEN = 'ZXJkMTNycm4zZndqZHM4cjUyNjBuNnEzcGQycWE2d3FrdWRyaGN6aDI2ZDk1N2MwZWR5emVybXNoZHMwazg.Wld4eWIyNWtMbU52YlEuYjNkMDc1NjUyOTNmZDU2ODRjOTdkMmI5NmViODYyZDEyNGZkNjk4Njc4ZjNmOTViMjUxNWVkMDcxNzhhMjdiNC44NjQwMC5lMzA.4b445f287663b868e269aa0532c9fd73acb37cfd45f46e33995777e68e5ecc15d97318d9af09c4102f9b40ecf347a75e2d2e81acbcc3c72ae32fcf659c2acd0e';
const HOST = 'api.multiversx.com';
const TOKEN = `YXBpLm11bHRpdmVyc3guY29t.${BLOCK_HASH}.${TTL}.e30`;
const ACCESS_TOKEN = 'ZXJkMXFuazJ2bXVxeXdmcXRkbmttYXV2cG04bHMweGgwMGs4eGV1cHVhZjZjbTZjZDRyeDg5cXF6MHBwZ2w.WVhCcExtMTFiSFJwZG1WeWMzZ3VZMjl0LjgyZWM4MDQ0OTY2ZWZiMmQwMGU4YTYzNjdlYTIzZGRiYzdiZWE2NTA0ZWQ5OGY0YTFhNTM2ZDdjMjFiYjI2ODIuODY0MDAuZTMw.563cb2dfdf96ab335423a05287fa3cd00154034423d0062421ee6ce03230d941da6df9ce79689fcd173c0ba5d4331b3ccd82c8ec2e6ab4d875db1587c2ab720c';
const latestRound = 115656;
const METASHARD = 4294967295;
const GATEWAY = 'https://gateway.elrond.com';
const GATEWAY = 'https://gateway.multiversx.com';

const onBlocksByRound = function (mock: MockAdapter): RequestHandler {
return mock.onGet(`${GATEWAY}/blocks/by-round/${latestRound}`);
};

//https://testnet-gateway.elrond.com/network/status/4294967295
//https://testnet-gateway.multiversx.com/network/status/4294967295
const onNetworkStatus = function (mock: MockAdapter): RequestHandler {
return mock.onGet(`${GATEWAY}/network/status/${METASHARD}`);
};
Expand Down