Authorization Service
The authorization service provides cryptographic message signing and validation using Ed25519 signatures. It's automatically available on the client and adapts based on whether a wallet is configured.
Behavior
- With Wallet: When a wallet is set, the authorization service provides all methods including
generate,validate,generateHeaders, andvalidateHeaders. - Without Wallet: When no wallet is set, the authorization service only provides
validateandvalidateHeadersmethods (read-only validation).
Methods
Generate Message Signature
ts
generate(message: string | Uint8Array, options?: GenerateOptions): Promise<string>1
Generating message signatures (requires wallet).
Validate Message Signature
ts
validate(
validationString: string,
address: string,
options?: Partial<ValidateOptions>
): boolean1
2
3
4
5
2
3
4
5
Validate a signed message against the signer's address (its public key in base58).
Generate HTTP Header Signatures
ts
generateHeaders(
method: string,
path: string,
body?: string | Uint8Array,
options?: GenerateHeaderOptions
): Promise<Headers>1
2
3
4
5
6
2
3
4
5
6
Signing HTTP headers requires wallet.
Validate HTTP Header Signatures
ts
validateHeaders(
headers: IncomingHttpHeaders,
address: string,
options?: Partial<Pick<GenerateHeaderOptions, 'key'>> & Partial<ValidateOptions>
): boolean1
2
3
4
5
2
3
4
5
Validate a signed HTTP header against the signer's address.
Examples
ts
// Set wallet first to enable signing
const client: NosanaClientclient.NosanaClient.wallet: Wallet | undefinedThe wallet. Must be a Wallet (supports both message and transaction signing).
Set this property directly to configure the wallet.@example```ts
import { createNosanaClient, NosanaNetwork } from '@nosana/kit';
const client = createNosanaClient(NosanaNetwork.MAINNET);
client.wallet = myWallet;
```wallet = const myWallet: Readonly<{
address: Address<string>;
signMessages(messages: readonly SignableMessage[], config?: MessagePartialSignerConfig): Promise<readonly SignatureDictionary[]>;
}> & Readonly<{
address: Address<string>;
signTransactions(transactions: readonly (Transaction & TransactionWithinSizeLimit & TransactionWithLifetime)[], config?: TransactionPartialSignerConfig): Promise<readonly SignatureDictionary[]>;
}>
myWallet;
// Generate message signature
const const messageToSign: "Hello, Nosana!"messageToSign = 'Hello, Nosana!';
const const messageSignature: stringmessageSignature: string = await const client: NosanaClientclient.NosanaClient.authorization: NosanaAuthorizationauthorization.NosanaAuthorization.generate: (message: string, options?: Partial<GenerateOptions>) => Promise<string>generate(const messageToSign: "Hello, Nosana!"messageToSign);
var console: ConsoleThe `console` module provides a simple debugging console that is similar to the
JavaScript console mechanism provided by web browsers.
The module exports two specific components:
* A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream.
* A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v24.x/api/process.html#processstdout) and
[`process.stderr`](https://nodejs.org/docs/latest-v24.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module.
_**Warning**_: The global console object's methods are neither consistently
synchronous like the browser APIs they resemble, nor are they consistently
asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v24.x/api/process.html#a-note-on-process-io) for
more information.
Example using the global `console`:
```js
console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr
```
Example using the `Console` class:
```js
const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err
```@see[source](https://github.com/nodejs/node/blob/v24.x/lib/console.js)console.Console.log(message?: any, ...optionalParams: any[]): void (+1 overload)Prints to `stdout` with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html)
(the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)).
```js
const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout
```
See [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args) for more information.@sincev0.1.100log('Message signature:', const messageSignature: stringmessageSignature);
// Validate message signature (requires validationString with message+signature, and the signer's address)
// Note: validationString typically contains both message and signature separated
const const validationString: stringvalidationString = `${const messageToSign: "Hello, Nosana!"messageToSign}:${const messageSignature: stringmessageSignature}`; // Format may vary
const const isValid: booleanisValid: boolean = const client: NosanaClientclient.NosanaClient.authorization: NosanaAuthorizationauthorization.NosanaAuthorization.validate: (validationString: string, address: string, options?: Partial<ValidateOptions>) => booleanWhether `validationString` was signed by the wallet at `address` (its
public key in base58).validate(const validationString: stringvalidationString, const myWallet: Readonly<{
address: Address<string>;
signMessages(messages: readonly SignableMessage[], config?: MessagePartialSignerConfig): Promise<readonly SignatureDictionary[]>;
}> & Readonly<{
address: Address<string>;
signTransactions(transactions: readonly (Transaction & TransactionWithinSizeLimit & TransactionWithLifetime)[], config?: TransactionPartialSignerConfig): Promise<readonly SignatureDictionary[]>;
}>
myWallet.address: NominalType<"brand", "Address"> & NominalType<"stringEncoding", "base58"> & stringaddress);
var console: ConsoleThe `console` module provides a simple debugging console that is similar to the
JavaScript console mechanism provided by web browsers.
The module exports two specific components:
* A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream.
* A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v24.x/api/process.html#processstdout) and
[`process.stderr`](https://nodejs.org/docs/latest-v24.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module.
_**Warning**_: The global console object's methods are neither consistently
synchronous like the browser APIs they resemble, nor are they consistently
asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v24.x/api/process.html#a-note-on-process-io) for
more information.
Example using the global `console`:
```js
console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr
```
Example using the `Console` class:
```js
const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err
```@see[source](https://github.com/nodejs/node/blob/v24.x/lib/console.js)console.Console.log(message?: any, ...optionalParams: any[]): void (+1 overload)Prints to `stdout` with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html)
(the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)).
```js
const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout
```
See [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args) for more information.@sincev0.1.100log('Message is valid:', const isValid: booleanisValid);
// Generate HTTP header signatures for API requests
// generateHeaders takes a message string and optional options
const const requestMessage: "POST /jobs"requestMessage = 'POST /jobs';
const const headers: Headersheaders: Headers = await const client: NosanaClientclient.NosanaClient.authorization: NosanaAuthorizationauthorization.NosanaAuthorization.generateHeaders: (message: string, options?: Partial<GenerateHeaderOptions>) => Promise<Headers>generateHeaders(const requestMessage: "POST /jobs"requestMessage, {
expiry?: number | undefinedexpiry: var Date: DateConstructorEnables basic storage and retrieval of dates and times.Date.DateConstructor.now(): numberReturns the number of milliseconds elapsed since midnight, January 1, 1970 Universal Coordinated Time (UTC).now() + 3600000, // 1 hour from now
key?: string | undefinedkey: 'authorization',
includeTime?: boolean | undefinedincludeTime: true,
separator?: string | undefinedseparator: ':',
});
// Use headers in HTTP request
function fetch(input: string | URL | Request, init?: RequestInit): Promise<Response> (+1 overload)[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/fetch)fetch('https://api.nosana.com/jobs', {
RequestInit.method?: string | undefinedA string to set request's method.method: 'POST',
RequestInit.headers?: HeadersInit | undefinedA Headers object, an object literal, or an array of two-item arrays to set request's headers.headers: const headers: Headersheaders,
RequestInit.body?: BodyInit | null | undefinedA BodyInit object or null to set request's body.body: var JSON: JSONAn intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format.JSON.JSON.stringify(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string (+1 overload)Converts a JavaScript value to a JavaScript Object Notation (JSON) string.@paramvalue A JavaScript value, usually an object or array, to be converted.@paramreplacer A function that transforms the results.@paramspace Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.@throws{TypeError} If a circular reference or a BigInt value is found.stringify({ data: stringdata: 'example' }),
});
// Validate incoming HTTP header signatures (requires headers as IncomingHttpHeaders and the signer's address)
// Convert Headers to IncomingHttpHeaders format (Record<string, string | string[] | undefined>)
const const isValidRequest: booleanisValidRequest: boolean = const client: NosanaClientclient.NosanaClient.authorization: NosanaAuthorizationauthorization.NosanaAuthorization.validateHeaders: (headers: IncomingHttpHeaders, address: string, options?: Partial<Pick<GenerateHeaderOptions, "key">> & Partial<ValidateOptions>) => booleanWhether the `key` header (`authorization` by default) was signed by the
wallet at `address` (its public key in base58).validateHeaders(const requestHeaders: Record<string, string | string[] | undefined>requestHeaders, const myWallet: Readonly<{
address: Address<string>;
signMessages(messages: readonly SignableMessage[], config?: MessagePartialSignerConfig): Promise<readonly SignatureDictionary[]>;
}> & Readonly<{
address: Address<string>;
signTransactions(transactions: readonly (Transaction & TransactionWithinSizeLimit & TransactionWithLifetime)[], config?: TransactionPartialSignerConfig): Promise<readonly SignatureDictionary[]>;
}>
myWallet.address: NominalType<"brand", "Address"> & NominalType<"stringEncoding", "base58"> & stringaddress);
if (!const isValidRequest: booleanisValidRequest) {
throw new var Error: ErrorConstructor
new (message?: string, options?: ErrorOptions) => Error (+1 overload)
Error('Invalid authorization');
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
Use Cases
- API Authentication: Sign requests to Nosana APIs using message signatures
- Message Verification: Verify message signatures from other parties
- Secure Communication: Establish authenticated communication channels
- Request Authorization: Validate incoming API requests