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

feat: support ton connect auth #50

Open
wants to merge 4 commits into
base: mainnet
Choose a base branch
from
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
11 changes: 9 additions & 2 deletions packages/ipfs-w3auth/auth-handler/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@crustio/ipfs-w3auth-handler",
"version": "0.0.18",
"version": "0.0.19",
"description": "IPFS W3Auth express middleware",
"main": "./src/index.js",
"license": "Apache-2.0",
Expand All @@ -11,21 +11,28 @@
"compile": "tsc",
"fix": "gts fix"
},
"resolutions": {
"usb": "1.8.x",
"utf-8-validate": "5.0.6",
"bufferutil": "4.0.4"
},
"dependencies": {
"@crustio/ipfs-w3auth-avalanche": "^0.0.1",
"@crustio/ipfs-w3auth-ethereum": "^0.0.2",
"@crustio/ipfs-w3auth-solana": "^0.0.1",
"@crustio/ipfs-w3auth-substrate": "^0.0.3",
"@crustio/ipfs-w3auth-substrate": "^0.0.4",
"@crustio/ipfs-w3auth-flow": "^0.0.1",
"@crustio/ipfs-w3auth-elrond": "^0.0.1",
"@crustio/ipfs-w3auth-xx": "^0.0.4",
"@crustio/ipfs-w3auth-aptos": "^0.0.3",
"@crustio/ipfs-w3auth-algorand": "^0.0.3",
"@crustio/ipfs-w3auth-ton": "^0.0.1",
"express": "^4.17.1",
"lodash": "^4.17.21",
"winston": "^3.3.3"
},
"devDependencies": {
"copyfiles": "latest",
"@types/express": "^4.17.13",
"@babel/runtime": "^7.13.2",
"@types/node": "^14.14.31",
Expand Down
2 changes: 2 additions & 0 deletions packages/ipfs-w3auth/auth-handler/src/authRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ElrondAuth from '@crustio/ipfs-w3auth-elrond';
import XXAuth from '@crustio/ipfs-w3auth-xx';
import AptosAuth from '@crustio/ipfs-w3auth-aptos';
import AlgorandAuth from '@crustio/ipfs-w3auth-algorand';
import TonAuth from '@crustio/ipfs-w3auth-ton';

const _ = require('lodash');

Expand All @@ -25,6 +26,7 @@ const authProviders = {
...mapBySigType(['xx'], XXAuth),
...mapBySigType(['aptos', 'apt'], AptosAuth),
...mapBySigType(['algorand', 'algo'], AlgorandAuth),
...mapBySigType(['ton'], TonAuth),
};

async function auth(signatureType: string, data: AuthData): Promise<boolean> {
Expand Down
5,342 changes: 2,352 additions & 2,990 deletions packages/ipfs-w3auth/auth-handler/yarn.lock

Large diffs are not rendered by default.

14 changes: 10 additions & 4 deletions packages/ipfs-w3auth/auth-substrate/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@crustio/ipfs-w3auth-substrate",
"version": "0.0.3",
"version": "0.0.4",
"description": "Substrate authentication of IPFS W3Auth",
"main": "./src/index.js",
"license": "Apache-2.0",
Expand All @@ -12,13 +12,19 @@
"fix": "gts fix",
"pub": "tsc && copyfiles ./pacakge.json ./build && cd build && npm publish --access public"
},
"resolutions": {
"usb": "1.8.x",
"utf-8-validate": "5.0.6",
"bufferutil": "4.0.4"
},
"dependencies": {
"@polkadot/api": "^5.6.1"
"@polkadot/api": "5.x"
},
"devDependencies": {
"copyfiles": "latest",
"@types/node": "^14.14.31",
"gts": "^3.1.0",
"typescript": "^4.1.3"
}
}
},
"author": ""
}
4 changes: 2 additions & 2 deletions packages/ipfs-w3auth/auth-substrate/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import {signatureVerify} from '@polkadot/util-crypto';
import {stringToU8a, u8aConcat, u8aToU8a, hexToU8a} from '@polkadot/util';

function auth(data: AuthData): boolean {
const {address, signature} = data;
const {address, txMsg, signature} = data;

try {
const message = stringToU8a(address);
const message = txMsg ? txMsg : stringToU8a(address);

if (signatureVerify(message, hexToU8a(signature), address).isValid) {
return true;
Expand Down
1 change: 1 addition & 0 deletions packages/ipfs-w3auth/auth-substrate/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
interface AuthData {
address: string;
signature: string;
txMsg?: string;
}

class AuthError extends Error {
Expand Down
18 changes: 9 additions & 9 deletions packages/ipfs-w3auth/auth-substrate/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
"@polkadot/util-crypto" "^7.3.1"
rxjs "^7.3.0"

"@polkadot/[email protected]", "@polkadot/api@^5.6.1":
"@polkadot/[email protected]", "@polkadot/api@5.x":
version "5.9.1"
resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-5.9.1.tgz#ce314cc34f0a47098d039db7b9036bb491c2898c"
integrity sha512-POpIXn/Ao+NLB0uMldXdXU44dVbRr6+6Ax77Z0R285M8Z2EiF5jl2K3SPvlowLo4SntxiCSaHQxCekYhUcJKlw==
Expand Down Expand Up @@ -577,10 +577,10 @@ brorand@^1.1.0:
resolved "https://registry.yarnpkg.com/brorand/-/brorand-1.1.0.tgz#12c25efe40a45e3c323eb8675a0a0ce57b22371f"
integrity sha1-EsJe/kCkXjwyPrhnWgoM5XsiNx8=

bufferutil@^4.0.1:
version "4.0.3"
resolved "https://registry.yarnpkg.com/bufferutil/-/bufferutil-4.0.3.tgz#66724b756bed23cd7c28c4d306d7994f9943cc6b"
integrity sha512-yEYTwGndELGvfXsImMBLop58eaGW+YdONi1fNjTINSY98tmMmFijBG6WXgdkfuLNt4imzQNtIE+eBp1PVpMCSw==
bufferutil@4.0.4, bufferutil@^4.0.1:
version "4.0.4"
resolved "https://registry.yarnpkg.com/bufferutil/-/bufferutil-4.0.4.tgz#ab81373d313a6ead0d734e98c448c722734ae7bb"
integrity sha512-VNxjXUCrF3LvbLgwfkTb5LsFvk6pGIn7OBb9x+3o+iJ6mKw0JTUp4chBFc88hi1aspeZGeZG9jAIbpFYPQSLZw==
dependencies:
node-gyp-build "^4.2.0"

Expand Down Expand Up @@ -2708,10 +2708,10 @@ url-parse-lax@^3.0.0:
dependencies:
prepend-http "^2.0.0"

utf-8-validate@^5.0.2:
version "5.0.5"
resolved "https://registry.yarnpkg.com/utf-8-validate/-/utf-8-validate-5.0.5.tgz#dd32c2e82c72002dc9f02eb67ba6761f43456ca1"
integrity sha512-+pnxRYsS/axEpkrrEpzYfNZGXp0IjC/9RIxwM5gntY4Koi8SHmUGSfxfWqxZdRxrtaoVstuOzUp/rbs3JSPELQ==
utf-8-validate@5.0.6, utf-8-validate@^5.0.2:
version "5.0.6"
resolved "https://registry.yarnpkg.com/utf-8-validate/-/utf-8-validate-5.0.6.tgz#e1b3e0a5cc8648a3b44c1799fbb170d1aaaffe80"
integrity sha512-hoY0gOf9EkCw+nimK21FVKHUIG1BMqSiRwxB/q3A9yKZOrOI99PP77BxmarDqWz6rG3vVYiBWfhG8z2Tl+7fZA==
dependencies:
node-gyp-build "^4.2.0"

Expand Down
1 change: 1 addition & 0 deletions packages/ipfs-w3auth/auth-ton/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
3 changes: 3 additions & 0 deletions packages/ipfs-w3auth/auth-ton/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "./node_modules/gts/"
}
3 changes: 3 additions & 0 deletions packages/ipfs-w3auth/auth-ton/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require('gts/.prettierrc.json')
}
26 changes: 26 additions & 0 deletions packages/ipfs-w3auth/auth-ton/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@crustio/ipfs-w3auth-ton",
"version": "0.0.1",
"description": "Ton connnect authentication of IPFS W3Auth",
"main": "./src/index.js",
"license": "Apache-2.0",
"scripts": {
"build:types": "npx ts-node src/scripts/generate.ts",
"lint": "gts lint",
"clean": "gts clean",
"compile": "tsc",
"fix": "gts fix",
"pub": "tsc && copyfiles ./pacakge.json ./build && cd build && npm publish --access public"
},

"dependencies": {
"tweetnacl": "1.x"
},
"devDependencies": {
"copyfiles": "latest",
"@types/node": "^14.14.31",
"gts": "^3.1.0",
"typescript": "^4.1.3"
},
"author": ""
}
24 changes: 24 additions & 0 deletions packages/ipfs-w3auth/auth-ton/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* eslint-disable node/no-extraneous-import */
import {AuthData} from './types';
import nacl from 'tweetnacl';

function auth(data: AuthData): boolean {
const {address, txMsg, signature} = data;

try {
if (!txMsg) return false;
return nacl.sign.detached.verify(
// message
Buffer.from(txMsg, 'hex'),
// signature
Buffer.from(signature, 'base64'),
// pubkey
Buffer.from(address, 'hex')
);
} catch (error) {}
return false;
}

export default {
auth,
};
14 changes: 14 additions & 0 deletions packages/ipfs-w3auth/auth-ton/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
interface AuthData {
address: string;
signature: string;
txMsg?: string;
}

class AuthError extends Error {
constructor(msg: string) {
super(msg);
Object.setPrototypeOf(this, AuthError.prototype);
}
}

export {AuthData, AuthError};
12 changes: 12 additions & 0 deletions packages/ipfs-w3auth/auth-ton/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"rootDir": "./",
"outDir": "build",
"esModuleInterop": true,
"skipLibCheck": true,
"strict": true,
"declaration": true,
}
}
Loading
Loading