@civiwave/mesh-core 0.1.1
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/dist/index.cjs +1221 -0
- package/dist/index.d.cts +163 -0
- package/dist/index.d.ts +163 -0
- package/dist/index.js +1180 -0
- package/package.json +42 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* StorageAdapter — platform-agnostic storage interface.
|
|
3
|
+
*
|
|
4
|
+
* Abstracts over AsyncStorage (React Native), localStorage (web),
|
|
5
|
+
* or any custom implementation (Node.js, testing, etc.).
|
|
6
|
+
*/
|
|
7
|
+
interface StorageAdapter {
|
|
8
|
+
getItem(key: string): Promise<string | null>;
|
|
9
|
+
setItem(key: string, value: string): Promise<void>;
|
|
10
|
+
removeItem(key: string): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Civiwave SS58 address prefix. */
|
|
14
|
+
declare const SS58_PREFIX = 42;
|
|
15
|
+
interface Wallet {
|
|
16
|
+
publicKey: Uint8Array;
|
|
17
|
+
secretKey: Uint8Array;
|
|
18
|
+
ss58Address: string;
|
|
19
|
+
createdAt: string;
|
|
20
|
+
}
|
|
21
|
+
/** Convert Uint8Array to hex string. */
|
|
22
|
+
declare function toHex(bytes: Uint8Array): string;
|
|
23
|
+
/** Convert hex string to Uint8Array. */
|
|
24
|
+
declare function fromHex(hex: string): Uint8Array;
|
|
25
|
+
/** Simple SS58Check encoding (prefix + payload + checksum). */
|
|
26
|
+
declare function publicKeyToSS58(pubkey: Uint8Array, prefix?: number): string;
|
|
27
|
+
/**
|
|
28
|
+
* Generate an Ed25519 keypair.
|
|
29
|
+
* Returns 32-byte public key and 32-byte secret key (seed).
|
|
30
|
+
*/
|
|
31
|
+
declare function generateKeypair(): Promise<{
|
|
32
|
+
publicKey: Uint8Array;
|
|
33
|
+
secretKey: Uint8Array;
|
|
34
|
+
}>;
|
|
35
|
+
/** Sign a message with the Ed25519 secret key (seed). */
|
|
36
|
+
declare function sign(message: Uint8Array, secretKey: Uint8Array): Promise<Uint8Array>;
|
|
37
|
+
/** Verify an Ed25519 signature. */
|
|
38
|
+
declare function verify(signature: Uint8Array, message: Uint8Array, publicKey: Uint8Array): Promise<boolean>;
|
|
39
|
+
/** Save wallet to storage (hex-encoded keys). */
|
|
40
|
+
declare function saveWallet(wallet: Wallet, storage: StorageAdapter): Promise<void>;
|
|
41
|
+
/** Load wallet from storage. Returns null if no wallet saved. */
|
|
42
|
+
declare function loadWallet(storage: StorageAdapter): Promise<Wallet | null>;
|
|
43
|
+
/** Delete wallet from storage. */
|
|
44
|
+
declare function deleteWallet(storage: StorageAdapter): Promise<void>;
|
|
45
|
+
/** Create a full Wallet object from a keypair. */
|
|
46
|
+
declare function createWallet(publicKey: Uint8Array, secretKey: Uint8Array): Wallet;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Chain — HTTP client for civiwave-edge MESH API (keeper).
|
|
50
|
+
*
|
|
51
|
+
* All chain communication goes through the keeper at the configurable endpoint.
|
|
52
|
+
* Matches request/response formats from mesh-desktop chain_stubs.rs.
|
|
53
|
+
* Never throws — returns { success: false, error } on network errors.
|
|
54
|
+
*/
|
|
55
|
+
/** Set the keeper MESH API endpoint URL. */
|
|
56
|
+
declare function setKeeperEndpoint(url: string): void;
|
|
57
|
+
/** Get the current keeper MESH API endpoint URL. */
|
|
58
|
+
declare function getKeeperEndpoint(): string;
|
|
59
|
+
interface BalanceResponse {
|
|
60
|
+
free: string;
|
|
61
|
+
reserved: string;
|
|
62
|
+
total: string;
|
|
63
|
+
}
|
|
64
|
+
interface ExtrinsicResponse {
|
|
65
|
+
success: boolean;
|
|
66
|
+
tx_hash?: string;
|
|
67
|
+
error?: string;
|
|
68
|
+
}
|
|
69
|
+
interface ChainMetadataResponse {
|
|
70
|
+
genesis_hash: string;
|
|
71
|
+
block_hash: string;
|
|
72
|
+
spec_version: number;
|
|
73
|
+
transaction_version: number;
|
|
74
|
+
nonce: number;
|
|
75
|
+
}
|
|
76
|
+
interface ChainResult<T> {
|
|
77
|
+
success: boolean;
|
|
78
|
+
data?: T;
|
|
79
|
+
error?: string;
|
|
80
|
+
}
|
|
81
|
+
declare function balanceQueryUrl(base: string, account: string): string;
|
|
82
|
+
declare function extrinsicUrl(base: string): string;
|
|
83
|
+
declare function metadataUrl(base: string, account: string): string;
|
|
84
|
+
declare function stakingUrl(base: string, op: string): string;
|
|
85
|
+
/**
|
|
86
|
+
* Query balance for an SS58 address.
|
|
87
|
+
* GET /v1/chain/query/balance?account=<address>
|
|
88
|
+
*/
|
|
89
|
+
declare function queryBalance(ss58Address: string): Promise<ChainResult<BalanceResponse>>;
|
|
90
|
+
/**
|
|
91
|
+
* Submit a signed extrinsic (hex-encoded payload).
|
|
92
|
+
* POST /v1/chain/extrinsic
|
|
93
|
+
*/
|
|
94
|
+
declare function submitExtrinsic(hexPayload: string): Promise<ChainResult<ExtrinsicResponse>>;
|
|
95
|
+
/**
|
|
96
|
+
* Get chain metadata (signing params) for an account.
|
|
97
|
+
* GET /v1/chain/metadata?account=<address>
|
|
98
|
+
*/
|
|
99
|
+
declare function getChainMetadata(ss58Address: string): Promise<ChainResult<ChainMetadataResponse>>;
|
|
100
|
+
/**
|
|
101
|
+
* Submit a pallet extrinsic (structured request body).
|
|
102
|
+
* POST /v1/chain/extrinsic
|
|
103
|
+
* Used for register_did, stake, register_device, etc.
|
|
104
|
+
*/
|
|
105
|
+
declare function submitPalletExtrinsic(request: {
|
|
106
|
+
pallet: string;
|
|
107
|
+
call: string;
|
|
108
|
+
params: Record<string, unknown>;
|
|
109
|
+
}): Promise<ChainResult<ExtrinsicResponse>>;
|
|
110
|
+
/**
|
|
111
|
+
* Add stake to a neuron.
|
|
112
|
+
* POST /v1/staking/add-stake
|
|
113
|
+
*/
|
|
114
|
+
declare function addStake(hotkey: string, netuid: number, amount: number): Promise<ChainResult<ExtrinsicResponse>>;
|
|
115
|
+
/**
|
|
116
|
+
* Remove stake from a neuron.
|
|
117
|
+
* POST /v1/staking/remove-stake
|
|
118
|
+
*/
|
|
119
|
+
declare function removeStake(hotkey: string, netuid: number, amount: number): Promise<ChainResult<ExtrinsicResponse>>;
|
|
120
|
+
/**
|
|
121
|
+
* Transfer CIVL tokens.
|
|
122
|
+
* POST /v1/staking/transfer
|
|
123
|
+
*/
|
|
124
|
+
declare function transfer(destination: string, amount: number): Promise<ChainResult<ExtrinsicResponse>>;
|
|
125
|
+
|
|
126
|
+
/** W3C DID Document matching mesh-desktop format. */
|
|
127
|
+
interface DIDDocument {
|
|
128
|
+
'@context': string[];
|
|
129
|
+
id: string;
|
|
130
|
+
authentication: Array<{
|
|
131
|
+
type: string;
|
|
132
|
+
publicKeyMultibase: string;
|
|
133
|
+
}>;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Generate a Blake2b-256 hash of a public key.
|
|
137
|
+
* Returns 32-byte hash as Uint8Array.
|
|
138
|
+
*/
|
|
139
|
+
declare function generateDIDHash(publicKey: Uint8Array): Uint8Array;
|
|
140
|
+
/**
|
|
141
|
+
* Build a W3C DID v1 document matching mesh-desktop's chain_stubs.rs format.
|
|
142
|
+
*
|
|
143
|
+
* The document structure matches build_register_did_request() from chain_stubs.rs:
|
|
144
|
+
* - @context: ["https://www.w3.org/ns/did/v1"]
|
|
145
|
+
* - id: "did:civiwave:{ss58Address}"
|
|
146
|
+
* - authentication: [{ type: "Ed25519VerificationKey2020", publicKeyMultibase: <hex> }]
|
|
147
|
+
*/
|
|
148
|
+
declare function buildDIDDocument(ss58Address: string, publicKey: Uint8Array): DIDDocument;
|
|
149
|
+
/**
|
|
150
|
+
* Register DID on-chain via the keeper MESH API.
|
|
151
|
+
*
|
|
152
|
+
* Matches mesh-desktop's build_register_did_request():
|
|
153
|
+
* - pallet: "IdentityHub"
|
|
154
|
+
* - call: "register_did"
|
|
155
|
+
* - params: { public_key, did_document }
|
|
156
|
+
*/
|
|
157
|
+
declare function registerDID(wallet: Wallet): Promise<ChainResult<ExtrinsicResponse>>;
|
|
158
|
+
/**
|
|
159
|
+
* Format a DID string from an SS58 address.
|
|
160
|
+
*/
|
|
161
|
+
declare function didFromSS58(ss58Address: string): string;
|
|
162
|
+
|
|
163
|
+
export { type BalanceResponse, type ChainMetadataResponse, type ChainResult, type DIDDocument, type ExtrinsicResponse, SS58_PREFIX, type StorageAdapter, type Wallet, addStake, balanceQueryUrl, buildDIDDocument, createWallet, deleteWallet, didFromSS58, extrinsicUrl, fromHex, generateDIDHash, generateKeypair, getChainMetadata, getKeeperEndpoint, loadWallet, metadataUrl, publicKeyToSS58, queryBalance, registerDID, removeStake, saveWallet, setKeeperEndpoint, sign, stakingUrl, submitExtrinsic, submitPalletExtrinsic, toHex, transfer, verify };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* StorageAdapter — platform-agnostic storage interface.
|
|
3
|
+
*
|
|
4
|
+
* Abstracts over AsyncStorage (React Native), localStorage (web),
|
|
5
|
+
* or any custom implementation (Node.js, testing, etc.).
|
|
6
|
+
*/
|
|
7
|
+
interface StorageAdapter {
|
|
8
|
+
getItem(key: string): Promise<string | null>;
|
|
9
|
+
setItem(key: string, value: string): Promise<void>;
|
|
10
|
+
removeItem(key: string): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Civiwave SS58 address prefix. */
|
|
14
|
+
declare const SS58_PREFIX = 42;
|
|
15
|
+
interface Wallet {
|
|
16
|
+
publicKey: Uint8Array;
|
|
17
|
+
secretKey: Uint8Array;
|
|
18
|
+
ss58Address: string;
|
|
19
|
+
createdAt: string;
|
|
20
|
+
}
|
|
21
|
+
/** Convert Uint8Array to hex string. */
|
|
22
|
+
declare function toHex(bytes: Uint8Array): string;
|
|
23
|
+
/** Convert hex string to Uint8Array. */
|
|
24
|
+
declare function fromHex(hex: string): Uint8Array;
|
|
25
|
+
/** Simple SS58Check encoding (prefix + payload + checksum). */
|
|
26
|
+
declare function publicKeyToSS58(pubkey: Uint8Array, prefix?: number): string;
|
|
27
|
+
/**
|
|
28
|
+
* Generate an Ed25519 keypair.
|
|
29
|
+
* Returns 32-byte public key and 32-byte secret key (seed).
|
|
30
|
+
*/
|
|
31
|
+
declare function generateKeypair(): Promise<{
|
|
32
|
+
publicKey: Uint8Array;
|
|
33
|
+
secretKey: Uint8Array;
|
|
34
|
+
}>;
|
|
35
|
+
/** Sign a message with the Ed25519 secret key (seed). */
|
|
36
|
+
declare function sign(message: Uint8Array, secretKey: Uint8Array): Promise<Uint8Array>;
|
|
37
|
+
/** Verify an Ed25519 signature. */
|
|
38
|
+
declare function verify(signature: Uint8Array, message: Uint8Array, publicKey: Uint8Array): Promise<boolean>;
|
|
39
|
+
/** Save wallet to storage (hex-encoded keys). */
|
|
40
|
+
declare function saveWallet(wallet: Wallet, storage: StorageAdapter): Promise<void>;
|
|
41
|
+
/** Load wallet from storage. Returns null if no wallet saved. */
|
|
42
|
+
declare function loadWallet(storage: StorageAdapter): Promise<Wallet | null>;
|
|
43
|
+
/** Delete wallet from storage. */
|
|
44
|
+
declare function deleteWallet(storage: StorageAdapter): Promise<void>;
|
|
45
|
+
/** Create a full Wallet object from a keypair. */
|
|
46
|
+
declare function createWallet(publicKey: Uint8Array, secretKey: Uint8Array): Wallet;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Chain — HTTP client for civiwave-edge MESH API (keeper).
|
|
50
|
+
*
|
|
51
|
+
* All chain communication goes through the keeper at the configurable endpoint.
|
|
52
|
+
* Matches request/response formats from mesh-desktop chain_stubs.rs.
|
|
53
|
+
* Never throws — returns { success: false, error } on network errors.
|
|
54
|
+
*/
|
|
55
|
+
/** Set the keeper MESH API endpoint URL. */
|
|
56
|
+
declare function setKeeperEndpoint(url: string): void;
|
|
57
|
+
/** Get the current keeper MESH API endpoint URL. */
|
|
58
|
+
declare function getKeeperEndpoint(): string;
|
|
59
|
+
interface BalanceResponse {
|
|
60
|
+
free: string;
|
|
61
|
+
reserved: string;
|
|
62
|
+
total: string;
|
|
63
|
+
}
|
|
64
|
+
interface ExtrinsicResponse {
|
|
65
|
+
success: boolean;
|
|
66
|
+
tx_hash?: string;
|
|
67
|
+
error?: string;
|
|
68
|
+
}
|
|
69
|
+
interface ChainMetadataResponse {
|
|
70
|
+
genesis_hash: string;
|
|
71
|
+
block_hash: string;
|
|
72
|
+
spec_version: number;
|
|
73
|
+
transaction_version: number;
|
|
74
|
+
nonce: number;
|
|
75
|
+
}
|
|
76
|
+
interface ChainResult<T> {
|
|
77
|
+
success: boolean;
|
|
78
|
+
data?: T;
|
|
79
|
+
error?: string;
|
|
80
|
+
}
|
|
81
|
+
declare function balanceQueryUrl(base: string, account: string): string;
|
|
82
|
+
declare function extrinsicUrl(base: string): string;
|
|
83
|
+
declare function metadataUrl(base: string, account: string): string;
|
|
84
|
+
declare function stakingUrl(base: string, op: string): string;
|
|
85
|
+
/**
|
|
86
|
+
* Query balance for an SS58 address.
|
|
87
|
+
* GET /v1/chain/query/balance?account=<address>
|
|
88
|
+
*/
|
|
89
|
+
declare function queryBalance(ss58Address: string): Promise<ChainResult<BalanceResponse>>;
|
|
90
|
+
/**
|
|
91
|
+
* Submit a signed extrinsic (hex-encoded payload).
|
|
92
|
+
* POST /v1/chain/extrinsic
|
|
93
|
+
*/
|
|
94
|
+
declare function submitExtrinsic(hexPayload: string): Promise<ChainResult<ExtrinsicResponse>>;
|
|
95
|
+
/**
|
|
96
|
+
* Get chain metadata (signing params) for an account.
|
|
97
|
+
* GET /v1/chain/metadata?account=<address>
|
|
98
|
+
*/
|
|
99
|
+
declare function getChainMetadata(ss58Address: string): Promise<ChainResult<ChainMetadataResponse>>;
|
|
100
|
+
/**
|
|
101
|
+
* Submit a pallet extrinsic (structured request body).
|
|
102
|
+
* POST /v1/chain/extrinsic
|
|
103
|
+
* Used for register_did, stake, register_device, etc.
|
|
104
|
+
*/
|
|
105
|
+
declare function submitPalletExtrinsic(request: {
|
|
106
|
+
pallet: string;
|
|
107
|
+
call: string;
|
|
108
|
+
params: Record<string, unknown>;
|
|
109
|
+
}): Promise<ChainResult<ExtrinsicResponse>>;
|
|
110
|
+
/**
|
|
111
|
+
* Add stake to a neuron.
|
|
112
|
+
* POST /v1/staking/add-stake
|
|
113
|
+
*/
|
|
114
|
+
declare function addStake(hotkey: string, netuid: number, amount: number): Promise<ChainResult<ExtrinsicResponse>>;
|
|
115
|
+
/**
|
|
116
|
+
* Remove stake from a neuron.
|
|
117
|
+
* POST /v1/staking/remove-stake
|
|
118
|
+
*/
|
|
119
|
+
declare function removeStake(hotkey: string, netuid: number, amount: number): Promise<ChainResult<ExtrinsicResponse>>;
|
|
120
|
+
/**
|
|
121
|
+
* Transfer CIVL tokens.
|
|
122
|
+
* POST /v1/staking/transfer
|
|
123
|
+
*/
|
|
124
|
+
declare function transfer(destination: string, amount: number): Promise<ChainResult<ExtrinsicResponse>>;
|
|
125
|
+
|
|
126
|
+
/** W3C DID Document matching mesh-desktop format. */
|
|
127
|
+
interface DIDDocument {
|
|
128
|
+
'@context': string[];
|
|
129
|
+
id: string;
|
|
130
|
+
authentication: Array<{
|
|
131
|
+
type: string;
|
|
132
|
+
publicKeyMultibase: string;
|
|
133
|
+
}>;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Generate a Blake2b-256 hash of a public key.
|
|
137
|
+
* Returns 32-byte hash as Uint8Array.
|
|
138
|
+
*/
|
|
139
|
+
declare function generateDIDHash(publicKey: Uint8Array): Uint8Array;
|
|
140
|
+
/**
|
|
141
|
+
* Build a W3C DID v1 document matching mesh-desktop's chain_stubs.rs format.
|
|
142
|
+
*
|
|
143
|
+
* The document structure matches build_register_did_request() from chain_stubs.rs:
|
|
144
|
+
* - @context: ["https://www.w3.org/ns/did/v1"]
|
|
145
|
+
* - id: "did:civiwave:{ss58Address}"
|
|
146
|
+
* - authentication: [{ type: "Ed25519VerificationKey2020", publicKeyMultibase: <hex> }]
|
|
147
|
+
*/
|
|
148
|
+
declare function buildDIDDocument(ss58Address: string, publicKey: Uint8Array): DIDDocument;
|
|
149
|
+
/**
|
|
150
|
+
* Register DID on-chain via the keeper MESH API.
|
|
151
|
+
*
|
|
152
|
+
* Matches mesh-desktop's build_register_did_request():
|
|
153
|
+
* - pallet: "IdentityHub"
|
|
154
|
+
* - call: "register_did"
|
|
155
|
+
* - params: { public_key, did_document }
|
|
156
|
+
*/
|
|
157
|
+
declare function registerDID(wallet: Wallet): Promise<ChainResult<ExtrinsicResponse>>;
|
|
158
|
+
/**
|
|
159
|
+
* Format a DID string from an SS58 address.
|
|
160
|
+
*/
|
|
161
|
+
declare function didFromSS58(ss58Address: string): string;
|
|
162
|
+
|
|
163
|
+
export { type BalanceResponse, type ChainMetadataResponse, type ChainResult, type DIDDocument, type ExtrinsicResponse, SS58_PREFIX, type StorageAdapter, type Wallet, addStake, balanceQueryUrl, buildDIDDocument, createWallet, deleteWallet, didFromSS58, extrinsicUrl, fromHex, generateDIDHash, generateKeypair, getChainMetadata, getKeeperEndpoint, loadWallet, metadataUrl, publicKeyToSS58, queryBalance, registerDID, removeStake, saveWallet, setKeeperEndpoint, sign, stakingUrl, submitExtrinsic, submitPalletExtrinsic, toHex, transfer, verify };
|