@nosana/kit 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitlab-ci.yml +6 -5
- package/dist/config/defaultConfigs.js +15 -18
- package/dist/config/index.js +3 -19
- package/dist/config/types.d.ts +1 -3
- package/dist/config/types.js +4 -7
- package/dist/config/utils.js +8 -13
- package/dist/errors/NosanaError.d.ts +1 -0
- package/dist/errors/NosanaError.js +3 -6
- package/dist/generated_clients/jobs/accounts/index.js +3 -19
- package/dist/generated_clients/jobs/accounts/jobAccount.js +46 -59
- package/dist/generated_clients/jobs/accounts/marketAccount.js +45 -57
- package/dist/generated_clients/jobs/accounts/runAccount.js +36 -49
- package/dist/generated_clients/jobs/errors/index.js +1 -17
- package/dist/generated_clients/jobs/errors/nosanaJobs.js +43 -48
- package/dist/generated_clients/jobs/index.js +5 -21
- package/dist/generated_clients/jobs/instructions/claim.js +17 -26
- package/dist/generated_clients/jobs/instructions/clean.js +17 -26
- package/dist/generated_clients/jobs/instructions/cleanAdmin.js +17 -26
- package/dist/generated_clients/jobs/instructions/close.js +17 -26
- package/dist/generated_clients/jobs/instructions/closeAdmin.js +17 -26
- package/dist/generated_clients/jobs/instructions/complete.js +21 -30
- package/dist/generated_clients/jobs/instructions/delist.js +17 -26
- package/dist/generated_clients/jobs/instructions/end.js +17 -26
- package/dist/generated_clients/jobs/instructions/extend.js +21 -30
- package/dist/generated_clients/jobs/instructions/finish.js +21 -30
- package/dist/generated_clients/jobs/instructions/index.js +18 -34
- package/dist/generated_clients/jobs/instructions/list.js +23 -32
- package/dist/generated_clients/jobs/instructions/open.js +29 -38
- package/dist/generated_clients/jobs/instructions/quit.js +17 -26
- package/dist/generated_clients/jobs/instructions/quitAdmin.js +17 -26
- package/dist/generated_clients/jobs/instructions/recover.js +17 -26
- package/dist/generated_clients/jobs/instructions/stop.js +17 -26
- package/dist/generated_clients/jobs/instructions/update.js +29 -38
- package/dist/generated_clients/jobs/instructions/work.js +17 -26
- package/dist/generated_clients/jobs/programs/index.js +1 -17
- package/dist/generated_clients/jobs/programs/nosanaJobs.js +29 -34
- package/dist/generated_clients/jobs/shared/index.js +13 -21
- package/dist/generated_clients/jobs/types/index.js +3 -19
- package/dist/generated_clients/jobs/types/jobState.js +9 -15
- package/dist/generated_clients/jobs/types/jobType.js +9 -15
- package/dist/generated_clients/jobs/types/queueType.js +9 -15
- package/dist/index.d.ts +5 -1
- package/dist/index.js +149 -35
- package/dist/ipfs/IPFS.js +5 -12
- package/dist/logger/Logger.js +1 -5
- package/dist/programs/BaseProgram.js +1 -5
- package/dist/programs/JobsProgram.d.ts +2 -3
- package/dist/programs/JobsProgram.js +35 -99
- package/dist/solana/SolanaUtils.d.ts +15 -1
- package/dist/solana/SolanaUtils.js +81 -14
- package/dist/utils/index.js +1 -4
- package/examples/browser/.gitlab-ci.yml +78 -0
- package/examples/browser/FEATURES.md +141 -0
- package/examples/browser/QUICK_START.md +76 -0
- package/examples/browser/README.md +182 -0
- package/examples/browser/app.vue +1840 -0
- package/examples/browser/assets/css/main.css +7 -0
- package/examples/browser/nuxt.config.ts +24 -0
- package/examples/browser/package-lock.json +11855 -0
- package/examples/browser/package.json +31 -0
- package/examples/browser/public/favicon.ico +0 -0
- package/examples/browser/public/robots.txt +2 -0
- package/examples/browser/start.sh +38 -0
- package/examples/browser/tailwind.config.js +26 -0
- package/examples/node/README.md +146 -0
- package/examples/node/example-keypair.json +1 -0
- package/examples/node/package-lock.json +500 -156
- package/examples/node/package.json +5 -3
- package/examples/node/post-job.ts +160 -0
- package/examples/node/set-wallet.ts +87 -0
- package/package.json +3 -1
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* This code was AUTOGENERATED using the codama library.
|
|
4
3
|
* Please DO NOT EDIT THIS FILE, instead use visitors
|
|
@@ -6,19 +5,12 @@
|
|
|
6
5
|
*
|
|
7
6
|
* @see https://github.com/codama-idl/codama
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
|
-
exports.expectSome = expectSome;
|
|
11
|
-
exports.expectAddress = expectAddress;
|
|
12
|
-
exports.expectProgramDerivedAddress = expectProgramDerivedAddress;
|
|
13
|
-
exports.expectTransactionSigner = expectTransactionSigner;
|
|
14
|
-
exports.getAccountMetaFactory = getAccountMetaFactory;
|
|
15
|
-
exports.isTransactionSigner = isTransactionSigner;
|
|
16
|
-
const kit_1 = require("@solana/kit");
|
|
8
|
+
import { AccountRole, isProgramDerivedAddress, isTransactionSigner as kitIsTransactionSigner, upgradeRoleToSigner, } from '@solana/kit';
|
|
17
9
|
/**
|
|
18
10
|
* Asserts that the given value is not null or undefined.
|
|
19
11
|
* @internal
|
|
20
12
|
*/
|
|
21
|
-
function expectSome(value) {
|
|
13
|
+
export function expectSome(value) {
|
|
22
14
|
if (value == null) {
|
|
23
15
|
throw new Error('Expected a value but received null or undefined.');
|
|
24
16
|
}
|
|
@@ -28,7 +20,7 @@ function expectSome(value) {
|
|
|
28
20
|
* Asserts that the given value is a PublicKey.
|
|
29
21
|
* @internal
|
|
30
22
|
*/
|
|
31
|
-
function expectAddress(value) {
|
|
23
|
+
export function expectAddress(value) {
|
|
32
24
|
if (!value) {
|
|
33
25
|
throw new Error('Expected a Address.');
|
|
34
26
|
}
|
|
@@ -44,8 +36,8 @@ function expectAddress(value) {
|
|
|
44
36
|
* Asserts that the given value is a PDA.
|
|
45
37
|
* @internal
|
|
46
38
|
*/
|
|
47
|
-
function expectProgramDerivedAddress(value) {
|
|
48
|
-
if (!value || !Array.isArray(value) || !
|
|
39
|
+
export function expectProgramDerivedAddress(value) {
|
|
40
|
+
if (!value || !Array.isArray(value) || !isProgramDerivedAddress(value)) {
|
|
49
41
|
throw new Error('Expected a ProgramDerivedAddress.');
|
|
50
42
|
}
|
|
51
43
|
return value;
|
|
@@ -54,7 +46,7 @@ function expectProgramDerivedAddress(value) {
|
|
|
54
46
|
* Asserts that the given value is a TransactionSigner.
|
|
55
47
|
* @internal
|
|
56
48
|
*/
|
|
57
|
-
function expectTransactionSigner(value) {
|
|
49
|
+
export function expectTransactionSigner(value) {
|
|
58
50
|
if (!value || !isTransactionSigner(value)) {
|
|
59
51
|
throw new Error('Expected a TransactionSigner.');
|
|
60
52
|
}
|
|
@@ -64,31 +56,31 @@ function expectTransactionSigner(value) {
|
|
|
64
56
|
* Get account metas and signers from resolved accounts.
|
|
65
57
|
* @internal
|
|
66
58
|
*/
|
|
67
|
-
function getAccountMetaFactory(programAddress, optionalAccountStrategy) {
|
|
59
|
+
export function getAccountMetaFactory(programAddress, optionalAccountStrategy) {
|
|
68
60
|
return (account) => {
|
|
69
61
|
if (!account.value) {
|
|
70
62
|
if (optionalAccountStrategy === 'omitted')
|
|
71
63
|
return;
|
|
72
64
|
return Object.freeze({
|
|
73
65
|
address: programAddress,
|
|
74
|
-
role:
|
|
66
|
+
role: AccountRole.READONLY,
|
|
75
67
|
});
|
|
76
68
|
}
|
|
77
69
|
const writableRole = account.isWritable
|
|
78
|
-
?
|
|
79
|
-
:
|
|
70
|
+
? AccountRole.WRITABLE
|
|
71
|
+
: AccountRole.READONLY;
|
|
80
72
|
return Object.freeze({
|
|
81
73
|
address: expectAddress(account.value),
|
|
82
74
|
role: isTransactionSigner(account.value)
|
|
83
|
-
?
|
|
75
|
+
? upgradeRoleToSigner(writableRole)
|
|
84
76
|
: writableRole,
|
|
85
77
|
...(isTransactionSigner(account.value) ? { signer: account.value } : {}),
|
|
86
78
|
});
|
|
87
79
|
};
|
|
88
80
|
}
|
|
89
|
-
function isTransactionSigner(value) {
|
|
81
|
+
export function isTransactionSigner(value) {
|
|
90
82
|
return (!!value &&
|
|
91
83
|
typeof value === 'object' &&
|
|
92
84
|
'address' in value &&
|
|
93
|
-
(
|
|
85
|
+
kitIsTransactionSigner(value));
|
|
94
86
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* This code was AUTOGENERATED using the codama library.
|
|
4
3
|
* Please DO NOT EDIT THIS FILE, instead use visitors
|
|
@@ -6,21 +5,6 @@
|
|
|
6
5
|
*
|
|
7
6
|
* @see https://github.com/codama-idl/codama
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
13
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
14
|
-
}
|
|
15
|
-
Object.defineProperty(o, k2, desc);
|
|
16
|
-
}) : (function(o, m, k, k2) {
|
|
17
|
-
if (k2 === undefined) k2 = k;
|
|
18
|
-
o[k2] = m[k];
|
|
19
|
-
}));
|
|
20
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
21
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
22
|
-
};
|
|
23
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
__exportStar(require("./jobState"), exports);
|
|
25
|
-
__exportStar(require("./jobType"), exports);
|
|
26
|
-
__exportStar(require("./queueType"), exports);
|
|
8
|
+
export * from './jobState';
|
|
9
|
+
export * from './jobType';
|
|
10
|
+
export * from './queueType';
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* This code was AUTOGENERATED using the codama library.
|
|
4
3
|
* Please DO NOT EDIT THIS FILE, instead use visitors
|
|
@@ -6,25 +5,20 @@
|
|
|
6
5
|
*
|
|
7
6
|
* @see https://github.com/codama-idl/codama
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
|
-
exports.JobState = void 0;
|
|
11
|
-
exports.getJobStateEncoder = getJobStateEncoder;
|
|
12
|
-
exports.getJobStateDecoder = getJobStateDecoder;
|
|
13
|
-
exports.getJobStateCodec = getJobStateCodec;
|
|
14
|
-
const kit_1 = require("@solana/kit");
|
|
8
|
+
import { combineCodec, getEnumDecoder, getEnumEncoder, } from '@solana/kit';
|
|
15
9
|
/** The `JobState` describes the status of a job. */
|
|
16
|
-
var JobState;
|
|
10
|
+
export var JobState;
|
|
17
11
|
(function (JobState) {
|
|
18
12
|
JobState[JobState["Queued"] = 0] = "Queued";
|
|
19
13
|
JobState[JobState["Done"] = 1] = "Done";
|
|
20
14
|
JobState[JobState["Stopped"] = 2] = "Stopped";
|
|
21
|
-
})(JobState || (
|
|
22
|
-
function getJobStateEncoder() {
|
|
23
|
-
return
|
|
15
|
+
})(JobState || (JobState = {}));
|
|
16
|
+
export function getJobStateEncoder() {
|
|
17
|
+
return getEnumEncoder(JobState);
|
|
24
18
|
}
|
|
25
|
-
function getJobStateDecoder() {
|
|
26
|
-
return
|
|
19
|
+
export function getJobStateDecoder() {
|
|
20
|
+
return getEnumDecoder(JobState);
|
|
27
21
|
}
|
|
28
|
-
function getJobStateCodec() {
|
|
29
|
-
return
|
|
22
|
+
export function getJobStateCodec() {
|
|
23
|
+
return combineCodec(getJobStateEncoder(), getJobStateDecoder());
|
|
30
24
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* This code was AUTOGENERATED using the codama library.
|
|
4
3
|
* Please DO NOT EDIT THIS FILE, instead use visitors
|
|
@@ -6,14 +5,9 @@
|
|
|
6
5
|
*
|
|
7
6
|
* @see https://github.com/codama-idl/codama
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
|
-
exports.JobType = void 0;
|
|
11
|
-
exports.getJobTypeEncoder = getJobTypeEncoder;
|
|
12
|
-
exports.getJobTypeDecoder = getJobTypeDecoder;
|
|
13
|
-
exports.getJobTypeCodec = getJobTypeCodec;
|
|
14
|
-
const kit_1 = require("@solana/kit");
|
|
8
|
+
import { combineCodec, getEnumDecoder, getEnumEncoder, } from '@solana/kit';
|
|
15
9
|
/** The `JobType` describes the type of any job. */
|
|
16
|
-
var JobType;
|
|
10
|
+
export var JobType;
|
|
17
11
|
(function (JobType) {
|
|
18
12
|
JobType[JobType["Default"] = 0] = "Default";
|
|
19
13
|
JobType[JobType["Small"] = 1] = "Small";
|
|
@@ -21,13 +15,13 @@ var JobType;
|
|
|
21
15
|
JobType[JobType["Large"] = 3] = "Large";
|
|
22
16
|
JobType[JobType["Gpu"] = 4] = "Gpu";
|
|
23
17
|
JobType[JobType["Unknown"] = 5] = "Unknown";
|
|
24
|
-
})(JobType || (
|
|
25
|
-
function getJobTypeEncoder() {
|
|
26
|
-
return
|
|
18
|
+
})(JobType || (JobType = {}));
|
|
19
|
+
export function getJobTypeEncoder() {
|
|
20
|
+
return getEnumEncoder(JobType);
|
|
27
21
|
}
|
|
28
|
-
function getJobTypeDecoder() {
|
|
29
|
-
return
|
|
22
|
+
export function getJobTypeDecoder() {
|
|
23
|
+
return getEnumDecoder(JobType);
|
|
30
24
|
}
|
|
31
|
-
function getJobTypeCodec() {
|
|
32
|
-
return
|
|
25
|
+
export function getJobTypeCodec() {
|
|
26
|
+
return combineCodec(getJobTypeEncoder(), getJobTypeDecoder());
|
|
33
27
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* This code was AUTOGENERATED using the codama library.
|
|
4
3
|
* Please DO NOT EDIT THIS FILE, instead use visitors
|
|
@@ -6,25 +5,20 @@
|
|
|
6
5
|
*
|
|
7
6
|
* @see https://github.com/codama-idl/codama
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
|
-
exports.QueueType = void 0;
|
|
11
|
-
exports.getQueueTypeEncoder = getQueueTypeEncoder;
|
|
12
|
-
exports.getQueueTypeDecoder = getQueueTypeDecoder;
|
|
13
|
-
exports.getQueueTypeCodec = getQueueTypeCodec;
|
|
14
|
-
const kit_1 = require("@solana/kit");
|
|
8
|
+
import { combineCodec, getEnumDecoder, getEnumEncoder, } from '@solana/kit';
|
|
15
9
|
/** The `QueueType` describes the type of queue */
|
|
16
|
-
var QueueType;
|
|
10
|
+
export var QueueType;
|
|
17
11
|
(function (QueueType) {
|
|
18
12
|
QueueType[QueueType["Job"] = 0] = "Job";
|
|
19
13
|
QueueType[QueueType["Node"] = 1] = "Node";
|
|
20
14
|
QueueType[QueueType["Empty"] = 2] = "Empty";
|
|
21
|
-
})(QueueType || (
|
|
22
|
-
function getQueueTypeEncoder() {
|
|
23
|
-
return
|
|
15
|
+
})(QueueType || (QueueType = {}));
|
|
16
|
+
export function getQueueTypeEncoder() {
|
|
17
|
+
return getEnumEncoder(QueueType);
|
|
24
18
|
}
|
|
25
|
-
function getQueueTypeDecoder() {
|
|
26
|
-
return
|
|
19
|
+
export function getQueueTypeDecoder() {
|
|
20
|
+
return getEnumDecoder(QueueType);
|
|
27
21
|
}
|
|
28
|
-
function getQueueTypeCodec() {
|
|
29
|
-
return
|
|
22
|
+
export function getQueueTypeCodec() {
|
|
23
|
+
return combineCodec(getQueueTypeEncoder(), getQueueTypeDecoder());
|
|
30
24
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import { ClientConfig, NosanaNetwork, PartialClientConfig } from './config/index.js';
|
|
1
|
+
import { ClientConfig, NosanaNetwork, PartialClientConfig, WalletConfig } from './config/index.js';
|
|
2
2
|
import { Logger } from './logger/Logger.js';
|
|
3
3
|
import { JobsProgram } from './programs/JobsProgram.js';
|
|
4
4
|
import { SolanaUtils } from './solana/SolanaUtils.js';
|
|
5
|
+
import { KeyPairSigner } from 'gill';
|
|
5
6
|
export declare class NosanaClient {
|
|
6
7
|
readonly config: ClientConfig;
|
|
7
8
|
readonly jobs: JobsProgram;
|
|
8
9
|
readonly solana: SolanaUtils;
|
|
9
10
|
readonly logger: Logger;
|
|
11
|
+
wallet: KeyPairSigner | undefined;
|
|
10
12
|
constructor(network?: NosanaNetwork, customConfig?: PartialClientConfig);
|
|
13
|
+
setWallet(wallet: WalletConfig): Promise<KeyPairSigner | undefined>;
|
|
14
|
+
private isValidFilePath;
|
|
11
15
|
}
|
|
12
16
|
export * from './config/index.js';
|
|
13
17
|
export * from './errors/NosanaError.js';
|
package/dist/index.js
CHANGED
|
@@ -1,43 +1,157 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { Buffer } from 'buffer';
|
|
2
|
+
if (typeof window !== 'undefined' && typeof window.Buffer === 'undefined') {
|
|
3
|
+
window.Buffer = Buffer;
|
|
4
|
+
}
|
|
5
|
+
import { getNosanaConfig, NosanaNetwork } from './config/index.js';
|
|
6
|
+
import { Logger } from './logger/Logger.js';
|
|
7
|
+
import { JobsProgram } from './programs/JobsProgram.js';
|
|
8
|
+
import { SolanaUtils } from './solana/SolanaUtils.js';
|
|
9
|
+
import { createKeyPairSignerFromBytes } from 'gill';
|
|
10
|
+
import { NosanaError, ErrorCodes } from './errors/NosanaError.js';
|
|
11
|
+
import bs58 from 'bs58';
|
|
12
|
+
export class NosanaClient {
|
|
13
|
+
constructor(network = NosanaNetwork.MAINNET, customConfig) {
|
|
14
|
+
this.config = getNosanaConfig(network, customConfig);
|
|
15
|
+
if (this.config.wallet) {
|
|
16
|
+
this.setWallet(this.config.wallet);
|
|
17
|
+
}
|
|
18
|
+
this.jobs = new JobsProgram(this);
|
|
19
|
+
this.logger = Logger.getInstance();
|
|
20
|
+
this.solana = new SolanaUtils(this);
|
|
21
|
+
}
|
|
22
|
+
async setWallet(wallet) {
|
|
23
|
+
try {
|
|
24
|
+
// Check if we already have a KeyPairSigner type
|
|
25
|
+
if (wallet && typeof wallet === 'object' && 'address' in wallet && 'signMessages' in wallet) {
|
|
26
|
+
this.wallet = wallet;
|
|
27
|
+
return this.wallet;
|
|
28
|
+
}
|
|
29
|
+
// Check if it's a browser wallet adapter (has publicKey and signTransaction/signMessage)
|
|
30
|
+
if (wallet && typeof wallet === 'object' && 'publicKey' in wallet && ('signTransaction' in wallet || 'signMessage' in wallet)) {
|
|
31
|
+
// Convert browser wallet adapter to KeyPairSigner-like interface
|
|
32
|
+
const browserWallet = wallet;
|
|
33
|
+
this.wallet = {
|
|
34
|
+
address: browserWallet.publicKey.toString(),
|
|
35
|
+
signMessages: async (messages) => {
|
|
36
|
+
if (browserWallet.signMessage) {
|
|
37
|
+
return Promise.all(messages.map(msg => browserWallet.signMessage(msg)));
|
|
38
|
+
}
|
|
39
|
+
throw new Error('Browser wallet does not support message signing');
|
|
40
|
+
},
|
|
41
|
+
signTransactions: async (transactions) => {
|
|
42
|
+
if (browserWallet.signTransaction) {
|
|
43
|
+
return Promise.all(transactions.map(tx => browserWallet.signTransaction(tx)));
|
|
44
|
+
}
|
|
45
|
+
throw new Error('Browser wallet does not support transaction signing');
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
return this.wallet;
|
|
49
|
+
}
|
|
50
|
+
// If it's a string, try multiple conversion methods
|
|
51
|
+
if (typeof wallet === 'string') {
|
|
52
|
+
// Only try file/environment loading in Node.js environment
|
|
53
|
+
if (typeof window === 'undefined') {
|
|
54
|
+
try {
|
|
55
|
+
const { loadKeypairSignerFromFile, loadKeypairSignerFromEnvironment, loadKeypairSignerFromEnvironmentBase58 } = await import('gill/node');
|
|
56
|
+
// Try to load from file path
|
|
57
|
+
if (await this.isValidFilePath(wallet)) {
|
|
58
|
+
try {
|
|
59
|
+
this.wallet = await loadKeypairSignerFromFile(wallet);
|
|
60
|
+
return this.wallet;
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
this.logger.debug(`Failed to load keypair from file: ${error}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// Try to load from environment variable
|
|
67
|
+
try {
|
|
68
|
+
this.wallet = await loadKeypairSignerFromEnvironment(wallet);
|
|
69
|
+
return this.wallet;
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
this.logger.debug(`Failed to load keypair from environment: ${error}`);
|
|
73
|
+
}
|
|
74
|
+
// Try to load from environment variable as base58
|
|
75
|
+
try {
|
|
76
|
+
this.wallet = await loadKeypairSignerFromEnvironmentBase58(wallet);
|
|
77
|
+
return this.wallet;
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
this.logger.debug(`Failed to load keypair from environment base58: ${error}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
this.logger.debug(`Node.js modules not available: ${error}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// Try to parse as JSON array
|
|
88
|
+
if (wallet.startsWith('[')) {
|
|
89
|
+
try {
|
|
90
|
+
const key = JSON.parse(wallet);
|
|
91
|
+
this.wallet = await createKeyPairSignerFromBytes(new Uint8Array(key));
|
|
92
|
+
return this.wallet;
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
this.logger.debug(`Failed to parse as JSON array: ${error}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// Try to decode as base58
|
|
99
|
+
try {
|
|
100
|
+
const key = Buffer.from(bs58.decode(wallet)).toJSON().data;
|
|
101
|
+
this.wallet = await createKeyPairSignerFromBytes(new Uint8Array(key));
|
|
102
|
+
return this.wallet;
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
this.logger.debug(`Failed to decode as base58: ${error}`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// If it's an array, try to create from bytes
|
|
109
|
+
if (Array.isArray(wallet)) {
|
|
110
|
+
try {
|
|
111
|
+
this.wallet = await createKeyPairSignerFromBytes(new Uint8Array(wallet));
|
|
112
|
+
return this.wallet;
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
this.logger.debug(`Failed to create from byte array: ${error}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
// If we get here, none of the conversion methods worked
|
|
119
|
+
throw new Error('Unable to convert wallet to KeyPairSigner using any available method');
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
throw new NosanaError(`Failed to convert wallet to KeyPairSigner: ${error instanceof Error ? error.message : 'Unknown error'}`, ErrorCodes.WALLET_CONVERSION_ERROR, error);
|
|
123
|
+
}
|
|
7
124
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
this.solana = new SolanaUtils_js_1.SolanaUtils(this);
|
|
125
|
+
async isValidFilePath(filePath) {
|
|
126
|
+
// Only validate file paths in Node.js environment
|
|
127
|
+
if (typeof window !== 'undefined') {
|
|
128
|
+
return false; // Browser environment, no file system access
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
const [fs, path] = await Promise.all([
|
|
132
|
+
import('fs'),
|
|
133
|
+
import('path')
|
|
134
|
+
]);
|
|
135
|
+
if (!path.isAbsolute(filePath) && !filePath.startsWith('./') && !filePath.startsWith('../')) {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
const stats = await fs.promises.stat(filePath);
|
|
139
|
+
return stats.isFile();
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
28
144
|
}
|
|
29
145
|
}
|
|
30
|
-
exports.NosanaClient = NosanaClient;
|
|
31
146
|
// Export types and configuration
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
147
|
+
export * from './config/index.js';
|
|
148
|
+
export * from './errors/NosanaError.js';
|
|
149
|
+
export * from './logger/Logger.js';
|
|
35
150
|
// Export JobsProgram and related types
|
|
36
|
-
|
|
37
|
-
Object.defineProperty(exports, "JobsProgram", { enumerable: true, get: function () { return JobsProgram_js_2.JobsProgram; } });
|
|
151
|
+
export { JobsProgram } from './programs/JobsProgram.js';
|
|
38
152
|
// Export IPFS utilities
|
|
39
|
-
|
|
153
|
+
export * from './ipfs/IPFS.js';
|
|
40
154
|
// Export all generated client types and functions
|
|
41
|
-
|
|
155
|
+
export * from './generated_clients/jobs/index.js';
|
|
42
156
|
// Export dependencies
|
|
43
|
-
|
|
157
|
+
export * from 'gill';
|
package/dist/ipfs/IPFS.js
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.IPFS = void 0;
|
|
7
|
-
const bs58_1 = __importDefault(require("bs58"));
|
|
1
|
+
import bs58 from 'bs58';
|
|
8
2
|
/**
|
|
9
3
|
* Class to interact with Pinata Cloud
|
|
10
4
|
* https://www.pinata.cloud/
|
|
11
5
|
*/
|
|
12
|
-
class IPFS {
|
|
6
|
+
export class IPFS {
|
|
13
7
|
/**
|
|
14
8
|
* Convert the ipfs bytes from a solana job to a CID
|
|
15
9
|
* It prepends the 0x1220 (18,32) to make it 34 bytes and Base58 encodes it.
|
|
@@ -28,7 +22,7 @@ class IPFS {
|
|
|
28
22
|
// Use the array as-is if it's not 32 bytes
|
|
29
23
|
finalArray = new Uint8Array(hashArray);
|
|
30
24
|
}
|
|
31
|
-
return
|
|
25
|
+
return bs58.encode(Buffer.from(finalArray));
|
|
32
26
|
}
|
|
33
27
|
/**
|
|
34
28
|
* Converts IPFS hash to byte array needed to submit results
|
|
@@ -37,11 +31,10 @@ class IPFS {
|
|
|
37
31
|
*/
|
|
38
32
|
static IpfsHashToByteArray(hash) {
|
|
39
33
|
if (hash.length === 34) {
|
|
40
|
-
return new Uint8Array([...
|
|
34
|
+
return new Uint8Array([...bs58.decode(hash).subarray(2)]);
|
|
41
35
|
}
|
|
42
36
|
else {
|
|
43
|
-
return new Uint8Array([...
|
|
37
|
+
return new Uint8Array([...bs58.decode(hash)]);
|
|
44
38
|
}
|
|
45
39
|
}
|
|
46
40
|
}
|
|
47
|
-
exports.IPFS = IPFS;
|
package/dist/logger/Logger.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Logger = void 0;
|
|
4
|
-
class Logger {
|
|
1
|
+
export class Logger {
|
|
5
2
|
constructor(options) {
|
|
6
3
|
this.level = 'info';
|
|
7
4
|
this.prefix = '[Nosana]';
|
|
@@ -60,4 +57,3 @@ class Logger {
|
|
|
60
57
|
this.enabled = false;
|
|
61
58
|
}
|
|
62
59
|
}
|
|
63
|
-
exports.Logger = Logger;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseProgram = void 0;
|
|
4
|
-
class BaseProgram {
|
|
1
|
+
export class BaseProgram {
|
|
5
2
|
/**
|
|
6
3
|
* Gets the static accounts, initializing them if needed.
|
|
7
4
|
*/
|
|
@@ -36,4 +33,3 @@ class BaseProgram {
|
|
|
36
33
|
this.sdk = sdk;
|
|
37
34
|
}
|
|
38
35
|
}
|
|
39
|
-
exports.BaseProgram = BaseProgram;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseProgram } from './BaseProgram.js';
|
|
2
|
-
import { Address,
|
|
2
|
+
import { Address, Account } from 'gill';
|
|
3
3
|
import { NosanaClient } from '../index.js';
|
|
4
4
|
import * as programClient from "../generated_clients/jobs/index.js";
|
|
5
5
|
import { ConvertTypesForDb } from '../utils/index.js';
|
|
@@ -62,8 +62,7 @@ export declare class JobsProgram extends BaseProgram {
|
|
|
62
62
|
timeout: number | bigint;
|
|
63
63
|
ipfsHash: string;
|
|
64
64
|
node?: Address;
|
|
65
|
-
|
|
66
|
-
}): Promise<ReturnType<typeof this.client.getListInstruction> | Signature>;
|
|
65
|
+
}): Promise<ReturnType<typeof this.client.getListInstruction>>;
|
|
67
66
|
/**
|
|
68
67
|
* Monitor program account updates using callback functions
|
|
69
68
|
* Uses WebSocket subscriptions with automatic restart on failure
|