@rialo/ts-cdk 0.4.1 → 0.5.0-alpha.0
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.d.mts +266 -1
- package/dist/index.d.ts +266 -1
- package/dist/index.js +296 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +293 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -10874,6 +10874,298 @@ var KeypairSigner = class {
|
|
|
10874
10874
|
}
|
|
10875
10875
|
};
|
|
10876
10876
|
|
|
10877
|
+
// src/generated/keyring.ts
|
|
10878
|
+
var Keyring = class {
|
|
10879
|
+
};
|
|
10880
|
+
|
|
10881
|
+
// src/keyring/validation.ts
|
|
10882
|
+
var U32_MAX = 4294967295;
|
|
10883
|
+
function validateKeypairIndex(index) {
|
|
10884
|
+
if (!Number.isInteger(index) || index < 0 || index > U32_MAX) {
|
|
10885
|
+
throw new RialoError(
|
|
10886
|
+
"INVALID_INPUT" /* INVALID_INPUT */,
|
|
10887
|
+
`Invalid keypair index: ${index}. Must be a non-negative integer <= ${U32_MAX}.`
|
|
10888
|
+
);
|
|
10889
|
+
}
|
|
10890
|
+
}
|
|
10891
|
+
|
|
10892
|
+
// src/keyring/keyring.ts
|
|
10893
|
+
var RialoKeyring = class extends Keyring {
|
|
10894
|
+
keypairs;
|
|
10895
|
+
derivationPaths;
|
|
10896
|
+
activeIndex;
|
|
10897
|
+
constructor(keypairs, derivationPaths) {
|
|
10898
|
+
super();
|
|
10899
|
+
this.keypairs = keypairs;
|
|
10900
|
+
this.derivationPaths = derivationPaths;
|
|
10901
|
+
this.activeIndex = 0;
|
|
10902
|
+
}
|
|
10903
|
+
/**
|
|
10904
|
+
* Sets the active keypair index (facade operation, not in WIT contract).
|
|
10905
|
+
*
|
|
10906
|
+
* @param index - The keypair index to make active
|
|
10907
|
+
* @throws {RialoError} If the index does not exist in this keyring
|
|
10908
|
+
*/
|
|
10909
|
+
setActiveKeypair(index) {
|
|
10910
|
+
validateKeypairIndex(index);
|
|
10911
|
+
if (!this.keypairs.has(index)) {
|
|
10912
|
+
throw new RialoError(
|
|
10913
|
+
"WALLET" /* WALLET */,
|
|
10914
|
+
`Keypair ${index} not found in keyring`
|
|
10915
|
+
);
|
|
10916
|
+
}
|
|
10917
|
+
this.activeIndex = index;
|
|
10918
|
+
}
|
|
10919
|
+
activeKeypair() {
|
|
10920
|
+
const kp = this.keypairs.get(this.activeIndex);
|
|
10921
|
+
if (!kp) {
|
|
10922
|
+
throw new RialoError("WALLET" /* WALLET */, "Active keypair does not exist");
|
|
10923
|
+
}
|
|
10924
|
+
return kp;
|
|
10925
|
+
}
|
|
10926
|
+
sign(message) {
|
|
10927
|
+
return this.activeKeypair().sign(message).toBytes();
|
|
10928
|
+
}
|
|
10929
|
+
verify(message, sig) {
|
|
10930
|
+
return this.activeKeypair().verify(message, Signature.fromBytes(sig));
|
|
10931
|
+
}
|
|
10932
|
+
pubkeyString() {
|
|
10933
|
+
return this.activeKeypair().publicKey.toString();
|
|
10934
|
+
}
|
|
10935
|
+
pubkey() {
|
|
10936
|
+
return this.activeKeypair().publicKey;
|
|
10937
|
+
}
|
|
10938
|
+
getKeypairInfo(index) {
|
|
10939
|
+
validateKeypairIndex(index);
|
|
10940
|
+
const kp = this.keypairs.get(index);
|
|
10941
|
+
if (!kp) return void 0;
|
|
10942
|
+
return {
|
|
10943
|
+
index,
|
|
10944
|
+
pubkey: kp.publicKey,
|
|
10945
|
+
pubkeyString: kp.publicKey.toString(),
|
|
10946
|
+
derivationPath: this.derivationPaths.get(index) ?? void 0
|
|
10947
|
+
};
|
|
10948
|
+
}
|
|
10949
|
+
listKeypairs() {
|
|
10950
|
+
return Array.from(this.keypairs.keys()).sort((a, b) => a - b);
|
|
10951
|
+
}
|
|
10952
|
+
getKeypairsInfo() {
|
|
10953
|
+
return this.listKeypairs().map((index) => this.getKeypairInfo(index));
|
|
10954
|
+
}
|
|
10955
|
+
signWithKeypair(message, index) {
|
|
10956
|
+
validateKeypairIndex(index);
|
|
10957
|
+
const kp = this.keypairs.get(index);
|
|
10958
|
+
if (!kp) {
|
|
10959
|
+
throw new RialoError(
|
|
10960
|
+
"WALLET" /* WALLET */,
|
|
10961
|
+
`Keypair ${index} not found in keyring`
|
|
10962
|
+
);
|
|
10963
|
+
}
|
|
10964
|
+
return kp.sign(message).toBytes();
|
|
10965
|
+
}
|
|
10966
|
+
/**
|
|
10967
|
+
* Securely erases all secret key material from this keyring snapshot.
|
|
10968
|
+
*
|
|
10969
|
+
* Calls {@link Keypair.dispose} on every keypair, zeroing private key bytes.
|
|
10970
|
+
* After disposal, signing and secret-key export will throw. Verification
|
|
10971
|
+
* still works (uses only the public key). Does not affect provider-stored
|
|
10972
|
+
* state or other snapshots.
|
|
10973
|
+
*/
|
|
10974
|
+
dispose() {
|
|
10975
|
+
for (const kp of this.keypairs.values()) {
|
|
10976
|
+
kp.dispose();
|
|
10977
|
+
}
|
|
10978
|
+
}
|
|
10979
|
+
};
|
|
10980
|
+
|
|
10981
|
+
// src/generated/keyring-provider.ts
|
|
10982
|
+
var KeyringProvider = class {
|
|
10983
|
+
};
|
|
10984
|
+
|
|
10985
|
+
// src/keyring/keyring-provider.ts
|
|
10986
|
+
var InMemoryKeyringProvider = class extends KeyringProvider {
|
|
10987
|
+
keyrings = /* @__PURE__ */ new Map();
|
|
10988
|
+
getStored(name) {
|
|
10989
|
+
const stored = this.keyrings.get(name);
|
|
10990
|
+
if (!stored) {
|
|
10991
|
+
throw new RialoError("WALLET" /* WALLET */, `Keyring not found: ${name}`);
|
|
10992
|
+
}
|
|
10993
|
+
return stored;
|
|
10994
|
+
}
|
|
10995
|
+
checkPassword(stored, password) {
|
|
10996
|
+
if (stored.password !== password) {
|
|
10997
|
+
throw new RialoError("PASSWORD" /* PASSWORD */, "Invalid password");
|
|
10998
|
+
}
|
|
10999
|
+
}
|
|
11000
|
+
buildKeyring(stored) {
|
|
11001
|
+
const keypairsCopy = /* @__PURE__ */ new Map();
|
|
11002
|
+
for (const [idx, kp] of stored.keypairs) {
|
|
11003
|
+
keypairsCopy.set(idx, Keypair.fromSecretKey(kp.secretKeyBytes()));
|
|
11004
|
+
}
|
|
11005
|
+
const pathsCopy = new Map(stored.derivationPaths);
|
|
11006
|
+
return new RialoKeyring(keypairsCopy, pathsCopy);
|
|
11007
|
+
}
|
|
11008
|
+
toInfo(index, kp, derivationPath) {
|
|
11009
|
+
return {
|
|
11010
|
+
index,
|
|
11011
|
+
pubkey: kp.publicKey,
|
|
11012
|
+
pubkeyString: kp.publicKey.toString(),
|
|
11013
|
+
derivationPath
|
|
11014
|
+
};
|
|
11015
|
+
}
|
|
11016
|
+
nextIndex(stored) {
|
|
11017
|
+
if (stored.keypairs.size === 0) return 0;
|
|
11018
|
+
return Math.max(...stored.keypairs.keys()) + 1;
|
|
11019
|
+
}
|
|
11020
|
+
async create(name, password) {
|
|
11021
|
+
if (this.keyrings.has(name)) {
|
|
11022
|
+
throw new RialoError("WALLET" /* WALLET */, `Keyring already exists: ${name}`);
|
|
11023
|
+
}
|
|
11024
|
+
const kp = Keypair.generate();
|
|
11025
|
+
const keypairs = /* @__PURE__ */ new Map([[0, kp]]);
|
|
11026
|
+
const derivationPaths = /* @__PURE__ */ new Map([[0, void 0]]);
|
|
11027
|
+
this.keyrings.set(name, { keypairs, derivationPaths, mnemonic: void 0, password });
|
|
11028
|
+
return this.buildKeyring(this.getStored(name));
|
|
11029
|
+
}
|
|
11030
|
+
async createWithMnemonic(name, strengthBits, password) {
|
|
11031
|
+
if (this.keyrings.has(name)) {
|
|
11032
|
+
throw new RialoError("WALLET" /* WALLET */, `Keyring already exists: ${name}`);
|
|
11033
|
+
}
|
|
11034
|
+
if (strengthBits !== 128 && strengthBits !== 256) {
|
|
11035
|
+
throw new RialoError(
|
|
11036
|
+
"INVALID_INPUT" /* INVALID_INPUT */,
|
|
11037
|
+
`Invalid mnemonic strength: ${strengthBits}. Must be 128 or 256.`
|
|
11038
|
+
);
|
|
11039
|
+
}
|
|
11040
|
+
const mnemonic = Mnemonic.generate(strengthBits);
|
|
11041
|
+
const kp = await mnemonic.toKeypair(0);
|
|
11042
|
+
const path = `${BASE_DERIVATION_PATH}0'/0'`;
|
|
11043
|
+
const keypairs = /* @__PURE__ */ new Map([[0, kp]]);
|
|
11044
|
+
const derivationPaths = /* @__PURE__ */ new Map([[0, path]]);
|
|
11045
|
+
this.keyrings.set(name, {
|
|
11046
|
+
keypairs,
|
|
11047
|
+
derivationPaths,
|
|
11048
|
+
mnemonic: mnemonic.toString(),
|
|
11049
|
+
password
|
|
11050
|
+
});
|
|
11051
|
+
return [this.buildKeyring(this.getStored(name)), mnemonic.toString()];
|
|
11052
|
+
}
|
|
11053
|
+
async recoverFromMnemonic(name, mnemonicPhrase, password) {
|
|
11054
|
+
if (this.keyrings.has(name)) {
|
|
11055
|
+
throw new RialoError("WALLET" /* WALLET */, `Keyring already exists: ${name}`);
|
|
11056
|
+
}
|
|
11057
|
+
if (!Mnemonic.isValid(mnemonicPhrase)) {
|
|
11058
|
+
throw new RialoError("INVALID_INPUT" /* INVALID_INPUT */, "Invalid BIP39 mnemonic phrase");
|
|
11059
|
+
}
|
|
11060
|
+
const mnemonic = Mnemonic.fromPhrase(mnemonicPhrase);
|
|
11061
|
+
const kp = await mnemonic.toKeypair(0);
|
|
11062
|
+
const path = `${BASE_DERIVATION_PATH}0'/0'`;
|
|
11063
|
+
const keypairs = /* @__PURE__ */ new Map([[0, kp]]);
|
|
11064
|
+
const derivationPaths = /* @__PURE__ */ new Map([[0, path]]);
|
|
11065
|
+
this.keyrings.set(name, {
|
|
11066
|
+
keypairs,
|
|
11067
|
+
derivationPaths,
|
|
11068
|
+
mnemonic: mnemonicPhrase,
|
|
11069
|
+
password
|
|
11070
|
+
});
|
|
11071
|
+
return this.buildKeyring(this.getStored(name));
|
|
11072
|
+
}
|
|
11073
|
+
async load(name, password) {
|
|
11074
|
+
const stored = this.getStored(name);
|
|
11075
|
+
this.checkPassword(stored, password);
|
|
11076
|
+
return this.buildKeyring(stored);
|
|
11077
|
+
}
|
|
11078
|
+
async list() {
|
|
11079
|
+
return Array.from(this.keyrings.keys()).sort();
|
|
11080
|
+
}
|
|
11081
|
+
async exists(name) {
|
|
11082
|
+
return this.keyrings.has(name);
|
|
11083
|
+
}
|
|
11084
|
+
async getPublicKey(name) {
|
|
11085
|
+
const stored = this.getStored(name);
|
|
11086
|
+
const kp = stored.keypairs.get(0);
|
|
11087
|
+
if (!kp) throw new RialoError("WALLET" /* WALLET */, `Keyring ${name} has no keypair at index 0`);
|
|
11088
|
+
return kp.publicKey;
|
|
11089
|
+
}
|
|
11090
|
+
async listPublicKeys() {
|
|
11091
|
+
const results = [];
|
|
11092
|
+
for (const [name, stored] of this.keyrings) {
|
|
11093
|
+
const kp = stored.keypairs.get(0);
|
|
11094
|
+
if (kp) {
|
|
11095
|
+
results.push([name, this.toInfo(0, kp, stored.derivationPaths.get(0))]);
|
|
11096
|
+
}
|
|
11097
|
+
}
|
|
11098
|
+
results.sort((a, b) => a[0].localeCompare(b[0]));
|
|
11099
|
+
return results;
|
|
11100
|
+
}
|
|
11101
|
+
async listKeypairs(keyringName) {
|
|
11102
|
+
const stored = this.getStored(keyringName);
|
|
11103
|
+
const indices = Array.from(stored.keypairs.keys()).sort((a, b) => a - b);
|
|
11104
|
+
return indices.map((idx) => {
|
|
11105
|
+
const kp = stored.keypairs.get(idx);
|
|
11106
|
+
return this.toInfo(idx, kp, stored.derivationPaths.get(idx));
|
|
11107
|
+
});
|
|
11108
|
+
}
|
|
11109
|
+
async deriveKeypair(keyringName, keypairIndex, password) {
|
|
11110
|
+
validateKeypairIndex(keypairIndex);
|
|
11111
|
+
const stored = this.getStored(keyringName);
|
|
11112
|
+
this.checkPassword(stored, password);
|
|
11113
|
+
if (stored.keypairs.has(keypairIndex)) {
|
|
11114
|
+
throw new RialoError(
|
|
11115
|
+
"WALLET" /* WALLET */,
|
|
11116
|
+
`Keypair with index ${keypairIndex} already exists`
|
|
11117
|
+
);
|
|
11118
|
+
}
|
|
11119
|
+
let kp;
|
|
11120
|
+
let derivationPath;
|
|
11121
|
+
if (stored.mnemonic) {
|
|
11122
|
+
const mnemonic = Mnemonic.fromPhrase(stored.mnemonic);
|
|
11123
|
+
kp = await mnemonic.toKeypair(keypairIndex);
|
|
11124
|
+
derivationPath = `${BASE_DERIVATION_PATH}${keypairIndex}'/0'`;
|
|
11125
|
+
} else {
|
|
11126
|
+
kp = Keypair.generate();
|
|
11127
|
+
derivationPath = void 0;
|
|
11128
|
+
}
|
|
11129
|
+
stored.keypairs.set(keypairIndex, kp);
|
|
11130
|
+
stored.derivationPaths.set(keypairIndex, derivationPath);
|
|
11131
|
+
return this.toInfo(keypairIndex, kp, derivationPath);
|
|
11132
|
+
}
|
|
11133
|
+
async importSecretKey(keyringName, secretKey, derivationPath, password) {
|
|
11134
|
+
if (secretKey.length !== 32) {
|
|
11135
|
+
throw new RialoError(
|
|
11136
|
+
"INVALID_INPUT" /* INVALID_INPUT */,
|
|
11137
|
+
`Invalid secret key length: expected 32 bytes, got ${secretKey.length}`
|
|
11138
|
+
);
|
|
11139
|
+
}
|
|
11140
|
+
const stored = this.getStored(keyringName);
|
|
11141
|
+
this.checkPassword(stored, password);
|
|
11142
|
+
const kp = Keypair.fromSecretKey(secretKey);
|
|
11143
|
+
const nextIdx = this.nextIndex(stored);
|
|
11144
|
+
stored.keypairs.set(nextIdx, kp);
|
|
11145
|
+
stored.derivationPaths.set(nextIdx, derivationPath);
|
|
11146
|
+
return this.toInfo(nextIdx, kp, derivationPath);
|
|
11147
|
+
}
|
|
11148
|
+
async getKeypairsInfo(name) {
|
|
11149
|
+
return this.listKeypairs(name);
|
|
11150
|
+
}
|
|
11151
|
+
async getKeypairInfo(name, keypairIndex) {
|
|
11152
|
+
validateKeypairIndex(keypairIndex);
|
|
11153
|
+
const stored = this.getStored(name);
|
|
11154
|
+
const kp = stored.keypairs.get(keypairIndex);
|
|
11155
|
+
if (!kp) {
|
|
11156
|
+
throw new RialoError(
|
|
11157
|
+
"WALLET" /* WALLET */,
|
|
11158
|
+
`Keypair ${keypairIndex} not found in keyring ${name}`
|
|
11159
|
+
);
|
|
11160
|
+
}
|
|
11161
|
+
return this.toInfo(keypairIndex, kp, stored.derivationPaths.get(keypairIndex));
|
|
11162
|
+
}
|
|
11163
|
+
async nextKeypairIndex(name) {
|
|
11164
|
+
const stored = this.getStored(name);
|
|
11165
|
+
return this.nextIndex(stored);
|
|
11166
|
+
}
|
|
11167
|
+
};
|
|
11168
|
+
|
|
10877
11169
|
// src/program/constants.ts
|
|
10878
11170
|
var RISCV_LOADER_PROGRAM_ID = "RiscVLoader11111111111111111111111111111111";
|
|
10879
11171
|
var LOADER_V4_PROGRAM_ID = "LoaderV411111111111111111111111111111111111";
|
|
@@ -11247,6 +11539,6 @@ var ProgramDeployment = class {
|
|
|
11247
11539
|
(*! scure-bip39 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) *)
|
|
11248
11540
|
*/
|
|
11249
11541
|
|
|
11250
|
-
export { AccountMetaTable, BASE_DERIVATION_PATH, BUFFER_BALANCE_FACTOR, BaseRpcClient, BincodeReader, BincodeWriter, CHACHA20_POLY1305_TAG_LENGTH, CryptoError, CryptoErrorCode, DEFAULT_CHUNK_SIZE, DEFAULT_CONFIRMATION_BATCH_SIZE, DEFAULT_MAX_RETRIES2 as DEFAULT_MAX_RETRIES, DEFAULT_NUM_ACCOUNTS, DEFAULT_RETRY_BASE_DELAY_MS, DEFAULT_RETRY_MAX_DELAY_MS, DeploymentError, DeploymentErrorCode, ED25519_PUBLIC_KEY_LENGTH, HPKE_ENC_LENGTH, HPKE_OVERHEAD_LENGTH, HpkeError, HpkeErrorCode, HttpTransport, KELVIN_PER_RLO, Keypair, KeypairSigner, LOADER_V4_PROGRAM_ID, Message, Mnemonic, PROGRAM_DATA_OFFSET, PUBLIC_KEY_LENGTH, ProgramDeployment, PublicKey, QueryRpcClient, RIALO_DEVNET_CHAIN, RIALO_LOCALNET_CHAIN, RIALO_MAINNET_CHAIN, RIALO_TESTNET_CHAIN, RISCV_LOADER_PROGRAM_ID, RexValue, RexValueVariant, RialoClient, RialoError, RialoErrorType, RiscVLoaderInstruction, RpcError, RpcErrorCode, SECRET_KEY_LENGTH, SECRET_SHARING_HPKE_INFO, SIGNATURE_LENGTH, SYSTEM_PROGRAM_ID, Schema, Signature, SystemInstruction, Transaction, TransactionBuilder, TransactionError, TransactionErrorCode, TransactionRpcClient, URL_DEVNET, URL_LOCALNET, URL_MAINNET, URL_TESTNET, USER_SECRET_AAD, X25519_PUBLIC_KEY_LENGTH, allocateInstruction, assignInstruction, calculateBackoff, concatBytes2 as concatBytes, createAccount, createBorshInstruction, createRialoClient, deployInstruction, deserialize, deserializeBorsh, deserializeCompactU162 as deserializeCompactU16, deserializeStrict, encodeBorshData, encryptForRex, field, fixedArray, fromBase64, getCiphertextLength, getDefaultRialoClientConfig, getDevnetUrl, getLocalnetUrl, getMainnetUrl, getTestnetUrl, hpkeEncrypt, isOnCurve, isValidCiphertextLength, option, retractInstruction, seedToBytes, serialize, serializeBorsh, serializeCompactU16, setProgramLengthInstruction, sleep, toBase64, transferInstruction, vec, writeCompactU16, writeInstruction };
|
|
11542
|
+
export { AccountMetaTable, BASE_DERIVATION_PATH, BUFFER_BALANCE_FACTOR, BaseRpcClient, BincodeReader, BincodeWriter, CHACHA20_POLY1305_TAG_LENGTH, CryptoError, CryptoErrorCode, DEFAULT_CHUNK_SIZE, DEFAULT_CONFIRMATION_BATCH_SIZE, DEFAULT_MAX_RETRIES2 as DEFAULT_MAX_RETRIES, DEFAULT_NUM_ACCOUNTS, DEFAULT_RETRY_BASE_DELAY_MS, DEFAULT_RETRY_MAX_DELAY_MS, DeploymentError, DeploymentErrorCode, ED25519_PUBLIC_KEY_LENGTH, HPKE_ENC_LENGTH, HPKE_OVERHEAD_LENGTH, HpkeError, HpkeErrorCode, HttpTransport, InMemoryKeyringProvider, KELVIN_PER_RLO, Keypair, KeypairSigner, Keyring, KeyringProvider, LOADER_V4_PROGRAM_ID, Message, Mnemonic, PROGRAM_DATA_OFFSET, PUBLIC_KEY_LENGTH, ProgramDeployment, PublicKey, QueryRpcClient, RIALO_DEVNET_CHAIN, RIALO_LOCALNET_CHAIN, RIALO_MAINNET_CHAIN, RIALO_TESTNET_CHAIN, RISCV_LOADER_PROGRAM_ID, RexValue, RexValueVariant, RialoClient, RialoError, RialoErrorType, RialoKeyring, RiscVLoaderInstruction, RpcError, RpcErrorCode, SECRET_KEY_LENGTH, SECRET_SHARING_HPKE_INFO, SIGNATURE_LENGTH, SYSTEM_PROGRAM_ID, Schema, Signature, SystemInstruction, Transaction, TransactionBuilder, TransactionError, TransactionErrorCode, TransactionRpcClient, URL_DEVNET, URL_LOCALNET, URL_MAINNET, URL_TESTNET, USER_SECRET_AAD, X25519_PUBLIC_KEY_LENGTH, allocateInstruction, assignInstruction, calculateBackoff, concatBytes2 as concatBytes, createAccount, createBorshInstruction, createRialoClient, deployInstruction, deserialize, deserializeBorsh, deserializeCompactU162 as deserializeCompactU16, deserializeStrict, encodeBorshData, encryptForRex, field, fixedArray, fromBase64, getCiphertextLength, getDefaultRialoClientConfig, getDevnetUrl, getLocalnetUrl, getMainnetUrl, getTestnetUrl, hpkeEncrypt, isOnCurve, isValidCiphertextLength, option, retractInstruction, seedToBytes, serialize, serializeBorsh, serializeCompactU16, setProgramLengthInstruction, sleep, toBase64, transferInstruction, vec, writeCompactU16, writeInstruction };
|
|
11251
11543
|
//# sourceMappingURL=index.mjs.map
|
|
11252
11544
|
//# sourceMappingURL=index.mjs.map
|