@splashprotocol/remote-builder 2.0.0-beta.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,62 @@
1
+
2
+ yarn run v1.22.22
3
+ warning package.json: No license field
4
+ $ tsup src/index.ts --format esm,cjs --dts --clean
5
+ CLI Building entry: src/index.ts
6
+ CLI Using tsconfig: tsconfig.json
7
+ CLI tsup v8.3.0
8
+ CLI Target: esnext
9
+ CLI Cleaning output folder
10
+ ESM Build start
11
+ CJS Build start
12
+
13
+ [10:24:09 AM]  WARN  ▲ [WARNING] The condition "types" here will never be used as it comes after both "import" and "require" [package.json]
14
+
15
+ package.json:16:6:
16
+  16 │ "types": "./dist/index.d.ts"
17
+ ╵ ~~~~~~~
18
+
19
+ The "import" condition comes earlier and will be used for all "import" statements:
20
+
21
+ package.json:15:6:
22
+  15 │ "import": "./dist/index.js",
23
+ ╵ ~~~~~~~~
24
+
25
+ The "require" condition comes earlier and will be used for all "require" calls:
26
+
27
+ package.json:14:6:
28
+  14 │ "require": "./dist/index.cjs",
29
+ ╵ ~~~~~~~~~
30
+
31
+
32
+
33
+
34
+ [10:24:09 AM]  WARN  ▲ [WARNING] The condition "types" here will never be used as it comes after both "import" and "require" [package.json]
35
+
36
+ package.json:16:6:
37
+  16 │ "types": "./dist/index.d.ts"
38
+ ╵ ~~~~~~~
39
+
40
+ The "import" condition comes earlier and will be used for all "import" statements:
41
+
42
+ package.json:15:6:
43
+  15 │ "import": "./dist/index.js",
44
+ ╵ ~~~~~~~~
45
+
46
+ The "require" condition comes earlier and will be used for all "require" calls:
47
+
48
+ package.json:14:6:
49
+  14 │ "require": "./dist/index.cjs",
50
+ ╵ ~~~~~~~~~
51
+
52
+
53
+
54
+ ESM dist/index.js 1.47 KB
55
+ ESM ⚡️ Build success in 25ms
56
+ CJS dist/index.cjs 2.58 KB
57
+ CJS ⚡️ Build success in 25ms
58
+ DTS Build start
59
+ DTS ⚡️ Build success in 683ms
60
+ DTS dist/index.d.ts 1.87 KB
61
+ DTS dist/index.d.cts 1.87 KB
62
+ ✨ Done in 1.97s.
package/dist/index.cjs ADDED
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ RemoteTransaction: () => RemoteTransaction,
24
+ SignedRemoteTransaction: () => SignedRemoteTransaction,
25
+ SplashRemoteBuilder: () => SplashRemoteBuilder
26
+ });
27
+ module.exports = __toCommonJS(src_exports);
28
+
29
+ // src/core/models/RemoteTransaction/RemoteTransaction.ts
30
+ var RemoteTransaction = class _RemoteTransaction {
31
+ constructor(serialization, builder) {
32
+ this.builder = builder;
33
+ this.serialization = serialization;
34
+ }
35
+ static new(serialization, builder) {
36
+ return new _RemoteTransaction(serialization, builder);
37
+ }
38
+ /**
39
+ * Transaction serialization
40
+ * @type {S}
41
+ */
42
+ serialization;
43
+ sign() {
44
+ return this.builder.sign(this);
45
+ }
46
+ signAndSubmit() {
47
+ return this.sign().then((srt) => srt.submit());
48
+ }
49
+ };
50
+
51
+ // src/builders/SplashRemoteBuilder.ts
52
+ var SplashRemoteBuilder = class _SplashRemoteBuilder {
53
+ static new(api) {
54
+ return new _SplashRemoteBuilder(api);
55
+ }
56
+ api;
57
+ constructor(api) {
58
+ this.api = api;
59
+ }
60
+ sign() {
61
+ throw new Error("not implemented.");
62
+ }
63
+ submit() {
64
+ throw new Error("not implemented.");
65
+ }
66
+ trade() {
67
+ return Promise.resolve(RemoteTransaction.new("", this));
68
+ }
69
+ };
70
+
71
+ // src/core/models/SignedRemoteTransaction/SignedRemoteTransaction.ts
72
+ var SignedRemoteTransaction = class _SignedRemoteTransaction {
73
+ constructor(serialization, builder) {
74
+ this.builder = builder;
75
+ this.serialization = serialization;
76
+ }
77
+ static new(serialization, builder) {
78
+ return new _SignedRemoteTransaction(serialization, builder);
79
+ }
80
+ /**
81
+ * Transaction serialization
82
+ * @type {S}
83
+ */
84
+ serialization;
85
+ submit() {
86
+ return this.builder.submit(this);
87
+ }
88
+ };
89
+ // Annotate the CommonJS export names for ESM import in node:
90
+ 0 && (module.exports = {
91
+ RemoteTransaction,
92
+ SignedRemoteTransaction,
93
+ SplashRemoteBuilder
94
+ });
@@ -0,0 +1,47 @@
1
+ import { Api, Backend, SplashBackend } from '@splashprotocol/api';
2
+ import { TransactionHash, CborHexString } from '@splashprotocol/core';
3
+
4
+ declare class SignedRemoteTransaction<S, RB extends RemoteBuilder<Api<Backend<{}>>, S>> {
5
+ private builder;
6
+ static new<S, RB extends RemoteBuilder<Api<Backend<{}>>, S>>(serialization: S, builder: RB): SignedRemoteTransaction<S, RB>;
7
+ /**
8
+ * Transaction serialization
9
+ * @type {S}
10
+ */
11
+ readonly serialization: S;
12
+ private constructor();
13
+ submit(): Promise<TransactionHash>;
14
+ }
15
+
16
+ /**
17
+ * Remote transaction representation
18
+ */
19
+ declare class RemoteTransaction<S, RB extends RemoteBuilder<Api<Backend<{}>>, S>> {
20
+ private builder;
21
+ static new<S, RB extends RemoteBuilder<Api<Backend<{}>>, S>>(serialization: S, builder: RB): RemoteTransaction<S, RB>;
22
+ /**
23
+ * Transaction serialization
24
+ * @type {S}
25
+ */
26
+ readonly serialization: S;
27
+ private constructor();
28
+ sign(): Promise<SignedRemoteTransaction<S, RB>>;
29
+ signAndSubmit(): Promise<TransactionHash>;
30
+ }
31
+
32
+ interface RemoteBuilder<A extends Api<Backend<{}>>, S> {
33
+ readonly api: A;
34
+ sign(tx: RemoteTransaction<S, RemoteBuilder<A, S>>): Promise<SignedRemoteTransaction<S, RemoteBuilder<A, S>>>;
35
+ submit(signedTx: SignedRemoteTransaction<S, RemoteBuilder<A, S>>): Promise<TransactionHash>;
36
+ }
37
+
38
+ declare class SplashRemoteBuilder implements RemoteBuilder<Api<SplashBackend>, CborHexString> {
39
+ static new(api: Api<SplashBackend>): SplashRemoteBuilder;
40
+ readonly api: Api<SplashBackend>;
41
+ private constructor();
42
+ sign(): Promise<SignedRemoteTransaction<CborHexString, RemoteBuilder<Api<SplashBackend>, CborHexString>>>;
43
+ submit(): Promise<TransactionHash>;
44
+ trade(): Promise<RemoteTransaction<CborHexString, RemoteBuilder<Api<SplashBackend>, CborHexString>>>;
45
+ }
46
+
47
+ export { type RemoteBuilder, RemoteTransaction, SignedRemoteTransaction, SplashRemoteBuilder };
@@ -0,0 +1,47 @@
1
+ import { Api, Backend, SplashBackend } from '@splashprotocol/api';
2
+ import { TransactionHash, CborHexString } from '@splashprotocol/core';
3
+
4
+ declare class SignedRemoteTransaction<S, RB extends RemoteBuilder<Api<Backend<{}>>, S>> {
5
+ private builder;
6
+ static new<S, RB extends RemoteBuilder<Api<Backend<{}>>, S>>(serialization: S, builder: RB): SignedRemoteTransaction<S, RB>;
7
+ /**
8
+ * Transaction serialization
9
+ * @type {S}
10
+ */
11
+ readonly serialization: S;
12
+ private constructor();
13
+ submit(): Promise<TransactionHash>;
14
+ }
15
+
16
+ /**
17
+ * Remote transaction representation
18
+ */
19
+ declare class RemoteTransaction<S, RB extends RemoteBuilder<Api<Backend<{}>>, S>> {
20
+ private builder;
21
+ static new<S, RB extends RemoteBuilder<Api<Backend<{}>>, S>>(serialization: S, builder: RB): RemoteTransaction<S, RB>;
22
+ /**
23
+ * Transaction serialization
24
+ * @type {S}
25
+ */
26
+ readonly serialization: S;
27
+ private constructor();
28
+ sign(): Promise<SignedRemoteTransaction<S, RB>>;
29
+ signAndSubmit(): Promise<TransactionHash>;
30
+ }
31
+
32
+ interface RemoteBuilder<A extends Api<Backend<{}>>, S> {
33
+ readonly api: A;
34
+ sign(tx: RemoteTransaction<S, RemoteBuilder<A, S>>): Promise<SignedRemoteTransaction<S, RemoteBuilder<A, S>>>;
35
+ submit(signedTx: SignedRemoteTransaction<S, RemoteBuilder<A, S>>): Promise<TransactionHash>;
36
+ }
37
+
38
+ declare class SplashRemoteBuilder implements RemoteBuilder<Api<SplashBackend>, CborHexString> {
39
+ static new(api: Api<SplashBackend>): SplashRemoteBuilder;
40
+ readonly api: Api<SplashBackend>;
41
+ private constructor();
42
+ sign(): Promise<SignedRemoteTransaction<CborHexString, RemoteBuilder<Api<SplashBackend>, CborHexString>>>;
43
+ submit(): Promise<TransactionHash>;
44
+ trade(): Promise<RemoteTransaction<CborHexString, RemoteBuilder<Api<SplashBackend>, CborHexString>>>;
45
+ }
46
+
47
+ export { type RemoteBuilder, RemoteTransaction, SignedRemoteTransaction, SplashRemoteBuilder };
package/dist/index.js ADDED
@@ -0,0 +1,65 @@
1
+ // src/core/models/RemoteTransaction/RemoteTransaction.ts
2
+ var RemoteTransaction = class _RemoteTransaction {
3
+ constructor(serialization, builder) {
4
+ this.builder = builder;
5
+ this.serialization = serialization;
6
+ }
7
+ static new(serialization, builder) {
8
+ return new _RemoteTransaction(serialization, builder);
9
+ }
10
+ /**
11
+ * Transaction serialization
12
+ * @type {S}
13
+ */
14
+ serialization;
15
+ sign() {
16
+ return this.builder.sign(this);
17
+ }
18
+ signAndSubmit() {
19
+ return this.sign().then((srt) => srt.submit());
20
+ }
21
+ };
22
+
23
+ // src/builders/SplashRemoteBuilder.ts
24
+ var SplashRemoteBuilder = class _SplashRemoteBuilder {
25
+ static new(api) {
26
+ return new _SplashRemoteBuilder(api);
27
+ }
28
+ api;
29
+ constructor(api) {
30
+ this.api = api;
31
+ }
32
+ sign() {
33
+ throw new Error("not implemented.");
34
+ }
35
+ submit() {
36
+ throw new Error("not implemented.");
37
+ }
38
+ trade() {
39
+ return Promise.resolve(RemoteTransaction.new("", this));
40
+ }
41
+ };
42
+
43
+ // src/core/models/SignedRemoteTransaction/SignedRemoteTransaction.ts
44
+ var SignedRemoteTransaction = class _SignedRemoteTransaction {
45
+ constructor(serialization, builder) {
46
+ this.builder = builder;
47
+ this.serialization = serialization;
48
+ }
49
+ static new(serialization, builder) {
50
+ return new _SignedRemoteTransaction(serialization, builder);
51
+ }
52
+ /**
53
+ * Transaction serialization
54
+ * @type {S}
55
+ */
56
+ serialization;
57
+ submit() {
58
+ return this.builder.submit(this);
59
+ }
60
+ };
61
+ export {
62
+ RemoteTransaction,
63
+ SignedRemoteTransaction,
64
+ SplashRemoteBuilder
65
+ };
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@splashprotocol/remote-builder",
3
+ "version": "2.0.0-beta.10",
4
+ "type": "module",
5
+ "description": "Api client of splash protocol",
6
+ "scripts": {
7
+ "build": "tsup src/index.ts --format esm,cjs --dts --clean",
8
+ "test": "jest"
9
+ },
10
+ "main": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "require": "./dist/index.cjs",
15
+ "import": "./dist/index.js",
16
+ "types": "./dist/index.d.ts"
17
+ }
18
+ },
19
+ "private": false,
20
+ "devDependencies": {
21
+ "@types/jest": "^29.5.13",
22
+ "jest": "^29.7.0",
23
+ "jest-node-exports-resolver": "^1.1.6",
24
+ "ts-jest": "^29.2.5",
25
+ "tsup": "^8.3.0",
26
+ "typescript": "^5.6.2"
27
+ },
28
+ "jest": {
29
+ "preset": "ts-jest",
30
+ "testEnvironment": "node",
31
+ "testMatch": [
32
+ "**/*.spec.ts"
33
+ ]
34
+ },
35
+ "peerDependencies": {
36
+ "@splashprotocol/api": "2.0.0-beta.10",
37
+ "@splashprotocol/core": "2.0.0-beta.9"
38
+ }
39
+ }
@@ -0,0 +1,41 @@
1
+ import { RemoteBuilder } from '../core/types/RemoteBuilder.ts';
2
+ import { Api, SplashBackend } from '@splashprotocol/api';
3
+ import { RemoteTransaction } from '../core/models/RemoteTransaction/RemoteTransaction.ts';
4
+ import { CborHexString, TransactionHash } from '@splashprotocol/core';
5
+ import { SignedRemoteTransaction } from '../core/models/SignedRemoteTransaction/SignedRemoteTransaction.ts';
6
+
7
+ export class SplashRemoteBuilder
8
+ implements RemoteBuilder<Api<SplashBackend>, CborHexString>
9
+ {
10
+ static new(api: Api<SplashBackend>): SplashRemoteBuilder {
11
+ return new SplashRemoteBuilder(api);
12
+ }
13
+
14
+ readonly api: Api<SplashBackend>;
15
+
16
+ private constructor(api: Api<SplashBackend>) {
17
+ this.api = api;
18
+ }
19
+
20
+ sign(): Promise<
21
+ SignedRemoteTransaction<
22
+ CborHexString,
23
+ RemoteBuilder<Api<SplashBackend>, CborHexString>
24
+ >
25
+ > {
26
+ throw new Error('not implemented.');
27
+ }
28
+
29
+ submit(): Promise<TransactionHash> {
30
+ throw new Error('not implemented.');
31
+ }
32
+
33
+ trade(): Promise<
34
+ RemoteTransaction<
35
+ CborHexString,
36
+ RemoteBuilder<Api<SplashBackend>, CborHexString>
37
+ >
38
+ > {
39
+ return Promise.resolve(RemoteTransaction.new('', this));
40
+ }
41
+ }
@@ -0,0 +1,25 @@
1
+ import { RemoteTransaction } from './RemoteTransaction.ts';
2
+ import { builderEmulator } from '../../../mocks/RemoteBuilderEmulator.ts';
3
+ import { SignedRemoteTransaction } from '../SignedRemoteTransaction/SignedRemoteTransaction.ts';
4
+
5
+ test('should creates valid instance of RemoteTransaction', async () => {
6
+ const remoteTransaction = RemoteTransaction.new('unsigned', builderEmulator);
7
+
8
+ expect(remoteTransaction).toBeInstanceOf(RemoteTransaction);
9
+ expect(remoteTransaction.serialization).toBe('unsigned');
10
+ });
11
+
12
+ test('sign should returns signed transaction', async () => {
13
+ const remoteTransaction = RemoteTransaction.new('unsigned', builderEmulator);
14
+ const signedRemoteTransaction = await remoteTransaction.sign();
15
+
16
+ expect(signedRemoteTransaction).toBeInstanceOf(SignedRemoteTransaction);
17
+ expect(signedRemoteTransaction.serialization).toBe('signed');
18
+ });
19
+
20
+ test('signAndSubmit should returns transaction hash', async () => {
21
+ const remoteTransaction = RemoteTransaction.new('unsigned', builderEmulator);
22
+ const hash = await remoteTransaction.signAndSubmit();
23
+
24
+ expect(hash).toBe('submitted');
25
+ });
@@ -0,0 +1,40 @@
1
+ import { RemoteBuilder } from '../../types/RemoteBuilder.ts';
2
+ import { Api, Backend } from '@splashprotocol/api';
3
+ import { SignedRemoteTransaction } from '../SignedRemoteTransaction/SignedRemoteTransaction.ts';
4
+ import { TransactionHash } from '@splashprotocol/core';
5
+
6
+ /**
7
+ * Remote transaction representation
8
+ */
9
+ export class RemoteTransaction<
10
+ S,
11
+ RB extends RemoteBuilder<Api<Backend<{}>>, S>,
12
+ > {
13
+ static new<S, RB extends RemoteBuilder<Api<Backend<{}>>, S>>(
14
+ serialization: S,
15
+ builder: RB,
16
+ ): RemoteTransaction<S, RB> {
17
+ return new RemoteTransaction(serialization, builder);
18
+ }
19
+
20
+ /**
21
+ * Transaction serialization
22
+ * @type {S}
23
+ */
24
+ readonly serialization: S;
25
+
26
+ private constructor(
27
+ serialization: S,
28
+ private builder: RB,
29
+ ) {
30
+ this.serialization = serialization;
31
+ }
32
+
33
+ sign(): Promise<SignedRemoteTransaction<S, RB>> {
34
+ return this.builder.sign(this) as any;
35
+ }
36
+
37
+ signAndSubmit(): Promise<TransactionHash> {
38
+ return this.sign().then((srt) => srt.submit());
39
+ }
40
+ }
@@ -0,0 +1,21 @@
1
+ import { builderEmulator } from '../../../mocks/RemoteBuilderEmulator.ts';
2
+ import { SignedRemoteTransaction } from './SignedRemoteTransaction.ts';
3
+
4
+ test('should creates valid instance of SignedRemoteTransaction', () => {
5
+ const signedRemoteTransaction = SignedRemoteTransaction.new(
6
+ 'signed',
7
+ builderEmulator,
8
+ );
9
+
10
+ expect(signedRemoteTransaction).toBeInstanceOf(SignedRemoteTransaction);
11
+ expect(signedRemoteTransaction.serialization).toBe('signed');
12
+ });
13
+
14
+ test('submit should returns transaction hash', async () => {
15
+ const signedRemoteTransaction = SignedRemoteTransaction.new(
16
+ 'signed',
17
+ builderEmulator,
18
+ );
19
+
20
+ expect(await signedRemoteTransaction.submit()).toBe('submitted');
21
+ });
@@ -0,0 +1,32 @@
1
+ import { RemoteBuilder } from '../../types/RemoteBuilder.ts';
2
+ import { Api, Backend } from '@splashprotocol/api';
3
+ import { TransactionHash } from '@splashprotocol/core';
4
+
5
+ export class SignedRemoteTransaction<
6
+ S,
7
+ RB extends RemoteBuilder<Api<Backend<{}>>, S>,
8
+ > {
9
+ static new<S, RB extends RemoteBuilder<Api<Backend<{}>>, S>>(
10
+ serialization: S,
11
+ builder: RB,
12
+ ): SignedRemoteTransaction<S, RB> {
13
+ return new SignedRemoteTransaction(serialization, builder);
14
+ }
15
+
16
+ /**
17
+ * Transaction serialization
18
+ * @type {S}
19
+ */
20
+ readonly serialization: S;
21
+
22
+ private constructor(
23
+ serialization: S,
24
+ private builder: RB,
25
+ ) {
26
+ this.serialization = serialization;
27
+ }
28
+
29
+ submit(): Promise<TransactionHash> {
30
+ return this.builder.submit(this);
31
+ }
32
+ }
@@ -0,0 +1,16 @@
1
+ import { Api, Backend } from '@splashprotocol/api';
2
+ import { RemoteTransaction } from '../models/RemoteTransaction/RemoteTransaction.ts';
3
+ import { SignedRemoteTransaction } from '../models/SignedRemoteTransaction/SignedRemoteTransaction.ts';
4
+ import { TransactionHash } from '@splashprotocol/core';
5
+
6
+ export interface RemoteBuilder<A extends Api<Backend<{}>>, S> {
7
+ readonly api: A;
8
+
9
+ sign(
10
+ tx: RemoteTransaction<S, RemoteBuilder<A, S>>,
11
+ ): Promise<SignedRemoteTransaction<S, RemoteBuilder<A, S>>>;
12
+
13
+ submit(
14
+ signedTx: SignedRemoteTransaction<S, RemoteBuilder<A, S>>,
15
+ ): Promise<TransactionHash>;
16
+ }
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './core/types/RemoteBuilder.ts';
2
+ export * from './builders/SplashRemoteBuilder.ts';
3
+ export * from './core/models/SignedRemoteTransaction/SignedRemoteTransaction.ts';
4
+ export * from './core/models/RemoteTransaction/RemoteTransaction.ts';
@@ -0,0 +1,10 @@
1
+ import { Backend } from '@splashprotocol/api';
2
+ import { AssetInfoMetadata, Network } from '@splashprotocol/core';
3
+
4
+ export class BackendEmulator implements Backend<BackendEmulator> {
5
+ network: Network = 'mainnet';
6
+
7
+ getAssetMetadata(): Promise<AssetInfoMetadata | undefined> {
8
+ throw new Error('Method not implemented.');
9
+ }
10
+ }
@@ -0,0 +1,26 @@
1
+ import { RemoteBuilder } from '../core/types/RemoteBuilder.ts';
2
+ import { BackendEmulator } from './BackendEmulator.ts';
3
+ import { HexString, TransactionHash } from '@splashprotocol/core';
4
+ import { Api, createApi } from '@splashprotocol/api';
5
+ import { SignedRemoteTransaction } from '../core/models/SignedRemoteTransaction/SignedRemoteTransaction.ts';
6
+
7
+ export class RemoteBuilderEmulator
8
+ implements RemoteBuilder<Api<BackendEmulator>, HexString>
9
+ {
10
+ sign(): Promise<
11
+ SignedRemoteTransaction<
12
+ HexString,
13
+ RemoteBuilder<Api<BackendEmulator>, HexString>
14
+ >
15
+ > {
16
+ return Promise.resolve(SignedRemoteTransaction.new('signed', this));
17
+ }
18
+ submit(): Promise<TransactionHash> {
19
+ return Promise.resolve('submitted');
20
+ }
21
+
22
+ constructor(public api: Api<BackendEmulator>) {}
23
+ }
24
+
25
+ const api = createApi(new BackendEmulator());
26
+ export const builderEmulator = new RemoteBuilderEmulator(api);
package/tsconfig.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "@splashprotocol/typescript-config/base.json",
3
+ "include": [
4
+ "./src"
5
+ ],
6
+ "exclude": ["dist","node_modules"]
7
+ }