Skip to content

Commit 3a31cec

Browse files
authored
Merge pull request #3 from standardconnect/0.0.4-beta
0.0.4 beta
2 parents c01f681 + 62528a6 commit 3a31cec

20 files changed

+445
-99
lines changed

examples/index.ts

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import xls32d from '../dist/src';
2+
import { IAccountEncodeOpts, ICtiEncodeOpts } from '../dist/types';
3+
4+
const mod = {
5+
networkId: 1,
6+
ledger_hash: 'F8A87917637D476E871D22A1376D7C129DAC9E25D45AD4B67D1E75EA4418654C',
7+
ledger_index: '62084722',
8+
txn_hash: '1C0FA22BBF5D0A8A7A105EB7D0AD7A2532863AA48584493D4BC45741AEDC4826',
9+
txn_index: '25',
10+
};
11+
12+
const { uri, cti, bigInt, hex, bin, bytes } = new xls32d.utils.cti.Encode(mod);
13+
console.log(uri, cti, bigInt, hex, bin, bytes);
14+
15+
const input: ICtiEncodeOpts = {
16+
type: 'cti',
17+
params: {
18+
networkId: 1,
19+
ledger_hash: 'F8A87917637D476E871D22A1376D7C129DAC9E25D45AD4B67D1E75EA4418654C',
20+
ledger_index: '62084722',
21+
txn_hash: '1C0FA22BBF5D0A8A7A105EB7D0AD7A2532863AA48584493D4BC45741AEDC4826',
22+
txn_index: '25',
23+
},
24+
};
25+
26+
const inputa: IAccountEncodeOpts = {
27+
type: 'account',
28+
params: {
29+
xaddress: 'rpfBYsmNBB7Y6z7qHS8g26KE3y3hHaTxkq',
30+
},
31+
};
32+
33+
const main = async () => {
34+
const uri32 = xls32d.encode(input);
35+
console.log(uri32);
36+
37+
const duri32 = await xls32d.decode('xrpl:cti?id=17475295679037553836033');
38+
console.log(duri32);
39+
40+
const durai32 = await xls32d.decode(
41+
'xrpl:account?address=rpfBYsmNBB7Y6z7qHS8g26KE3y3hHaTxkq&tag=000001'
42+
);
43+
44+
console.log(durai32);
45+
46+
const uria32 = xls32d.encode(inputa);
47+
48+
console.log(uria32);
49+
};
50+
51+
main();

examples/package.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "examples",
3+
"version": "0.0.1",
4+
"main": "index.js",
5+
"license": "MIT",
6+
"dependencies": {
7+
"xls-32d": "^0.0.3-beta"
8+
},
9+
"devDependencies": {
10+
"ts-node": "^10.9.1"
11+
}
12+
}

examples/yarn-error.log

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
Arguments:
2+
/usr/local/bin/node /usr/local/bin/yarn add xls32d
3+
4+
PATH:
5+
/Users/intercoder/.gem/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/intercoder/.gem/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Applications/Visual Studio Code.app/Contents/Resources/app/bin:/Applications/Visual Studio Code.app/Contents/Resources/app/bin
6+
7+
Yarn version:
8+
1.22.10
9+
10+
Node version:
11+
18.12.0
12+
13+
Platform:
14+
darwin arm64
15+
16+
Trace:
17+
Error: https://registry.yarnpkg.com/xls32d: Not found
18+
at params.callback [as _callback] (/usr/local/lib/node_modules/yarn/lib/cli.js:66988:18)
19+
at self.callback (/usr/local/lib/node_modules/yarn/lib/cli.js:140662:22)
20+
at Request.emit (node:events:513:28)
21+
at Request.<anonymous> (/usr/local/lib/node_modules/yarn/lib/cli.js:141634:10)
22+
at Request.emit (node:events:513:28)
23+
at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/yarn/lib/cli.js:141556:12)
24+
at Object.onceWrapper (node:events:627:28)
25+
at IncomingMessage.emit (node:events:525:35)
26+
at endReadableNT (node:internal/streams/readable:1359:12)
27+
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
28+
29+
npm manifest:
30+
{
31+
"name": "examples",
32+
"version": "0.0.1",
33+
"main": "index.js",
34+
"license": "MIT"
35+
}
36+
37+
yarn manifest:
38+
No manifest
39+
40+
Lockfile:
41+
No lockfile

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "xls-32d",
3-
"version": "0.0.3-beta",
3+
"version": "0.0.4-beta",
44
"description": "XRPLF Standards Proposal - Request URI Structure",
55
"main": "./dist/src/index.js",
66
"repository": "https://github.com/standardconnect/xls-32d.git",
@@ -39,8 +39,10 @@
3939
"devDependencies": {
4040
"@types/fs-extra": "^11.0.1",
4141
"@types/jest": "^29.2.6",
42+
"@types/jsonwebtoken": "^9.0.1",
4243
"@types/node": "^18.8.0",
4344
"@types/qrcode": "^1.5.0",
45+
"@types/uuid": "^9.0.0",
4446
"jest": "^29.3.1",
4547
"prettier": "^2.8.0",
4648
"ts-jest": "^29.0.5",
@@ -49,8 +51,10 @@
4951
},
5052
"dependencies": {
5153
"fs-extra": "^10.1.0",
54+
"jsonwebtoken": "^9.0.0",
5255
"qrcode": "^1.5.1",
5356
"tsc-alias": "^1.8.2",
57+
"uuid": "^9.0.0",
5458
"zod": "^3.20.2"
5559
}
5660
}

src/helpers/client.ts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { URL } from './procedure';
2+
3+
// This is a helper client which will be used to manufacture the correct URL/URI
4+
// The clients main prupose is to make sure that the provided domain supports xls32-d
5+
// and is so, retrieves a jwt and endpoint
6+
// With the jwt and endpoint, the request manufacturer can product the correct URL/URI
7+
8+
// The client will also be used to receive incoming URI/URLs, check their validity and parse information for custom client-side handling
9+
10+
export class Client {
11+
constructor() {}
12+
13+
// check to see if domain has a provider and determine the appropiate endpoint for the manufacturing of the url
14+
15+
// required this this feature
16+
// this.endpoint and this.jwt
17+
//encode = (url:string) => new URL().encode(url)
18+
19+
decode = (url: string) => new URL().decode(url);
20+
}

src/helpers/decode.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import { DecodeObj } from 'types/index';
22
import utils from 'utils/index';
33

4-
export const decode = async (uri: string): Promise<DecodeObj> => {
4+
export const uri_decode = async (uri: string): Promise<DecodeObj> => {
55
return {
66
protocol: utils.parse.getProtocol(uri),
77
version: await utils.parse.getVersion(uri),
88
type: utils.parse.getType(uri),
99
params: utils.parse.getParams(uri),
1010
};
1111
};
12+
13+
export const url_decode = async (url: string): Promise<any> =>
14+
Object.fromEntries(new URL(url).searchParams);

src/helpers/encode.ts

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
1-
import { EncodeOpts, ExtendedEcodingOpts } from 'types/index';
1+
import {
2+
URIEncodeOpts,
3+
ExtendedURIEncodingOpts,
4+
URLEncodeOpts,
5+
ExtendedURLEncodingOpts,
6+
} from 'types/index';
27
import utils from 'utils/index';
38
import { getVersion } from 'utils/index';
49

5-
export const encode = (opts: EncodeOpts): string => {
6-
let object: ExtendedEcodingOpts = {
10+
export const uri_encode = (opts: URIEncodeOpts): string => {
11+
let object: ExtendedURIEncodingOpts = {
712
protocol: 'xrpl',
813
version: getVersion(),
914
...opts,
1015
};
1116

1217
return utils.parse.convertToUri(object);
1318
};
19+
20+
export const url_encode = (opts: URLEncodeOpts): string => {
21+
let object: ExtendedURLEncodingOpts = {
22+
protocol: 'xrpl',
23+
version: getVersion(),
24+
...opts,
25+
};
26+
27+
return utils.parse.convertToUrl(object);
28+
};

src/helpers/index.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
import { EncodeOpts } from 'types/index';
2-
import x from './procedure';
1+
import { URIEncodeOpts, URLEncodeOpts } from 'types/index';
2+
import { URI, URL } from './procedure';
33

4-
export const encode = (opts: EncodeOpts) => new x().encode(opts);
5-
export const decode = (uri: string) => new x().input(uri).decode(uri);
4+
export const uri = {
5+
encode: (opts: URIEncodeOpts) => new URI().encode(opts),
6+
decode: (uri: string) => new URI().input(uri).decode(uri),
7+
};
8+
9+
export const url = {
10+
encode: (opts: URLEncodeOpts) => new URL().encode(opts),
11+
decode: (url: string) => new URL().decode(url),
12+
};

src/helpers/procedure.ts

+19-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
1-
import { encode as _encode } from './encode';
2-
import { decode as _decode } from './decode';
3-
import { EncodeOpts } from 'types/index';
1+
import { uri_encode, url_encode } from './encode';
2+
import { uri_decode, url_decode } from './decode';
3+
import { URIEncodeOpts, URLEncodeOpts } from 'types/index';
44

55
import utils from 'utils/index';
66

7-
export default class x {
7+
export class URI {
88
input = (uri: string) => {
99
utils.checks.isValidSchema(uri);
1010
return this;
1111
};
12-
encode = (opts: EncodeOpts) => _encode(opts);
13-
decode = (uri: string) => _decode(uri);
12+
encode = (opts: URIEncodeOpts) => uri_encode(opts);
13+
decode = (uri: string) => uri_decode(uri);
14+
}
15+
16+
export class URL {
17+
input = (uri: string) => {
18+
utils.checks.isValidSchema(uri);
19+
return this;
20+
};
21+
22+
fetchProvider = () => {};
23+
24+
encode = (opts: URLEncodeOpts) => url_encode(opts);
25+
26+
decode = (uri: string) => url_decode(uri);
1427
}

src/helpers/provider.ts

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { getVersion } from 'utils/getVersion';
2+
import { v4 as uuid } from 'uuid';
3+
import jwt from 'jsonwebtoken';
4+
5+
const jwt_key = 'my secret';
6+
const providerEndpoint = '/this/is/the/recieving/point';
7+
8+
const defaultResponse = {
9+
version: getVersion(),
10+
supported: true,
11+
};
12+
13+
export interface Request {
14+
host?: string;
15+
domain?: string;
16+
origin?: string;
17+
ip?: string;
18+
uuid?: string;
19+
}
20+
export interface Response {
21+
version: string;
22+
supported: boolean;
23+
endpoint?: string;
24+
jwt?: string;
25+
}
26+
27+
// This is a provider to be installed on the receiver of the URL
28+
// Provider shall be hosted at a default standardized endpoint
29+
// For the purposes of this example, this provider will be hosted at
30+
// https://localhost:3000/sc
31+
32+
export class Provider {
33+
req: Request;
34+
res: Response = defaultResponse;
35+
uuid: string = uuid();
36+
key: string;
37+
secret: string;
38+
credentials: { key: string; secret: string };
39+
endpoint: string;
40+
41+
constructor({ key, secret }: { key: string; secret: string }, request: Request = {}) {
42+
this.key = key;
43+
this.secret = secret;
44+
this.req = request;
45+
this.credentials = { key: this.key, secret: this.secret };
46+
this.endpoint = providerEndpoint;
47+
if (this.endpoint) this.res.endpoint = this.endpoint;
48+
this.res.jwt = this.write();
49+
}
50+
51+
private write = () =>
52+
jwt.sign(Object.assign(this.credentials, { uuid: this.uuid }), jwt_key, {
53+
expiresIn: '7d',
54+
});
55+
56+
public response = () => this.res;
57+
}

src/index.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import utils from 'utils/index';
2-
import { decode, encode } from 'helpers/index';
2+
import { uri, url } from 'helpers/index';
33
import { generateQRCodeToBase64 as qr } from 'utils/qr';
4+
import * as types from 'types';
45

5-
export { decode, encode, utils, qr };
6+
export { uri, url, utils, qr, types };
67

7-
export default { decode, encode, qr, utils };
8+
export default { uri, url, qr, utils, types };

0 commit comments

Comments
 (0)