@witnium-tech/witniumchain 0.6.2 → 0.7.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 +59 -1
- package/dist/index.d.ts +59 -1
- package/dist/index.js +53 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +49 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -10168,4 +10168,62 @@ declare class WitniumchainApiError extends Error {
|
|
|
10168
10168
|
});
|
|
10169
10169
|
}
|
|
10170
10170
|
|
|
10171
|
-
|
|
10171
|
+
/**
|
|
10172
|
+
* Canonical owner-operation messages.
|
|
10173
|
+
*
|
|
10174
|
+
* Owner ops (add/revoke a signing key, pause/unpause a contract) are
|
|
10175
|
+
* authorized by an ed25519 signature from the contract OWNER key over a
|
|
10176
|
+
* canonical message. chain-api re-builds the exact same string server-side
|
|
10177
|
+
* and verifies the signature against the contract's stored owner key, so
|
|
10178
|
+
* the bytes MUST match to the character.
|
|
10179
|
+
*
|
|
10180
|
+
* The canonical form is `JSON.stringify({ op, contract, nonce, ...payload })`
|
|
10181
|
+
* with the contract address LOWER-CASED. (Verified against
|
|
10182
|
+
* ContractsV5Service.executeOwnerOp + a live on-chain addSigningKey.)
|
|
10183
|
+
*
|
|
10184
|
+
* Do NOT hand-roll this as `op:contract:nonce` or any other shape — the
|
|
10185
|
+
* signature will be silently rejected by chain-api ("Invalid owner
|
|
10186
|
+
* signature"). Use these helpers so a future chain-spec change is a single
|
|
10187
|
+
* SDK bump, not a silent break in every consumer.
|
|
10188
|
+
*/
|
|
10189
|
+
/** Owner-op type codes — mirror the contract constants (V3–V5). */
|
|
10190
|
+
declare const OWNER_OP: {
|
|
10191
|
+
readonly addSigningKey: 1;
|
|
10192
|
+
readonly revokeSigningKey: 2;
|
|
10193
|
+
readonly pause: 3;
|
|
10194
|
+
readonly unpause: 4;
|
|
10195
|
+
};
|
|
10196
|
+
type OwnerOpName = keyof typeof OWNER_OP;
|
|
10197
|
+
/**
|
|
10198
|
+
* Canonical message to sign for `pause`. `nonce` must be the contract's
|
|
10199
|
+
* current `ownerNonce + 1`.
|
|
10200
|
+
*/
|
|
10201
|
+
declare function buildPausePayload(args: {
|
|
10202
|
+
contractAddress: string;
|
|
10203
|
+
nonce: number;
|
|
10204
|
+
}): string;
|
|
10205
|
+
/** Canonical message to sign for `unpause`. */
|
|
10206
|
+
declare function buildUnpausePayload(args: {
|
|
10207
|
+
contractAddress: string;
|
|
10208
|
+
nonce: number;
|
|
10209
|
+
}): string;
|
|
10210
|
+
/**
|
|
10211
|
+
* Canonical message to sign for `addSigningKey`. `newKey` is the 64-hex-char
|
|
10212
|
+
* ed25519 public key being added (no 0x).
|
|
10213
|
+
*/
|
|
10214
|
+
declare function buildAddSigningKeyPayload(args: {
|
|
10215
|
+
contractAddress: string;
|
|
10216
|
+
nonce: number;
|
|
10217
|
+
newKey: string;
|
|
10218
|
+
}): string;
|
|
10219
|
+
/**
|
|
10220
|
+
* Canonical message to sign for `revokeSigningKey`. `key` is the 64-hex-char
|
|
10221
|
+
* ed25519 public key being revoked (no 0x).
|
|
10222
|
+
*/
|
|
10223
|
+
declare function buildRevokeSigningKeyPayload(args: {
|
|
10224
|
+
contractAddress: string;
|
|
10225
|
+
nonce: number;
|
|
10226
|
+
key: string;
|
|
10227
|
+
}): string;
|
|
10228
|
+
|
|
10229
|
+
export { type AccountResponse, type AccountType, type paths$1 as AccountsPaths, type AddSigningKeyRequest$1 as AddSigningKeyRequest, type AddSigningKeyResponse, type AdjustCreditsRequest, type AdjustCreditsResponse, type BeginOAuthLoginArgs, type BeginOAuthLoginResult, type paths as ChainPaths, type CheckoutRequest, type CheckoutResponse, type CreateOrgRequest, type CreateOrgResponse, type CreateOrganizationRequest, type CreateOrganizationResponse, type CreateUserRequest, type CreateUserResponse, DelegatedKeys, type FinalizeWitnessResponse, type ForgotPasswordRequest, type ForgotPasswordResponse, type GetWitnessResponse, type HealthLiveResponse, type HealthReadyResponse, type LedgerResponse, type ListDelegatedKeysResponse, type ListOauthSessionsResponse, type ListUsersResponse, type LoginRequest, type LoginResponse, type LogoutResponse, MfaNamespace, MfaRecoveryCodes, MfaTotp, type OAuthTokenSnapshot, OWNER_OP, OauthNamespace, OauthSessions, OrgUsers, type OwnerOpName, type OwnerSigner, type PauseRequest$1 as PauseRequest, type PauseResponse, type PkceVerifierStorage, type PortalResponse, type PrepareDelegatedKeyRequest, type PreparedDelegatedKeyResponse, type ProposeWitnessRequest, type ProposeWitnessResponse, type ProvisionContractRequest, type ProvisionContractResponse, type ProvisionDelegatedKeyArgs, type ProvisionDelegatedKeyResult, type PublicOrgResponse, type RecoveryCodesRegenerateResponse, type ResetAccountResponse, type ResetPasswordRequest, type ResetPasswordResponse, type RevokeDelegatedKeyResponse, type RevokeSigningKeyRequest$1 as RevokeSigningKeyRequest, type RevokeSigningKeyResponse, type RevokeWitnessRequest, type RevokeWitnessResponse, type RotateApiKeyResponse, type SetAccountTypeRequest, type SetAccountTypeResponse, type SignRequest, type SignResponse, type SignWitnessRequest, type SignWitnessResponse, type SignedRequestSigner, SigningKeys, type SignupRequest, type SignupResponse, type SubmitDelegatedKeyRequest, type SubmitDelegatedKeyResponse, Subscriptions, type TotpConfirmRequest, type TotpConfirmResponse, type TotpDisableResponse, type TotpEnrollResponse, type UnpauseRequest, type UnpauseResponse, type VerifyEmailResponse, type VerifyOrganizationResponse, WitniumchainAdminClient, type WitniumchainAdminClientConfig, WitniumchainApiError, WitniumchainChainAdminClient, type WitniumchainChainAdminClientConfig, WitniumchainClient, type WitniumchainClientConfig, WitniumchainOrgClient, type WitniumchainOrgClientConfig, buildAddSigningKeyPayload, buildPausePayload, buildRevokeSigningKeyPayload, buildUnpausePayload, defaultVerifierStorage };
|
package/dist/index.d.ts
CHANGED
|
@@ -10168,4 +10168,62 @@ declare class WitniumchainApiError extends Error {
|
|
|
10168
10168
|
});
|
|
10169
10169
|
}
|
|
10170
10170
|
|
|
10171
|
-
|
|
10171
|
+
/**
|
|
10172
|
+
* Canonical owner-operation messages.
|
|
10173
|
+
*
|
|
10174
|
+
* Owner ops (add/revoke a signing key, pause/unpause a contract) are
|
|
10175
|
+
* authorized by an ed25519 signature from the contract OWNER key over a
|
|
10176
|
+
* canonical message. chain-api re-builds the exact same string server-side
|
|
10177
|
+
* and verifies the signature against the contract's stored owner key, so
|
|
10178
|
+
* the bytes MUST match to the character.
|
|
10179
|
+
*
|
|
10180
|
+
* The canonical form is `JSON.stringify({ op, contract, nonce, ...payload })`
|
|
10181
|
+
* with the contract address LOWER-CASED. (Verified against
|
|
10182
|
+
* ContractsV5Service.executeOwnerOp + a live on-chain addSigningKey.)
|
|
10183
|
+
*
|
|
10184
|
+
* Do NOT hand-roll this as `op:contract:nonce` or any other shape — the
|
|
10185
|
+
* signature will be silently rejected by chain-api ("Invalid owner
|
|
10186
|
+
* signature"). Use these helpers so a future chain-spec change is a single
|
|
10187
|
+
* SDK bump, not a silent break in every consumer.
|
|
10188
|
+
*/
|
|
10189
|
+
/** Owner-op type codes — mirror the contract constants (V3–V5). */
|
|
10190
|
+
declare const OWNER_OP: {
|
|
10191
|
+
readonly addSigningKey: 1;
|
|
10192
|
+
readonly revokeSigningKey: 2;
|
|
10193
|
+
readonly pause: 3;
|
|
10194
|
+
readonly unpause: 4;
|
|
10195
|
+
};
|
|
10196
|
+
type OwnerOpName = keyof typeof OWNER_OP;
|
|
10197
|
+
/**
|
|
10198
|
+
* Canonical message to sign for `pause`. `nonce` must be the contract's
|
|
10199
|
+
* current `ownerNonce + 1`.
|
|
10200
|
+
*/
|
|
10201
|
+
declare function buildPausePayload(args: {
|
|
10202
|
+
contractAddress: string;
|
|
10203
|
+
nonce: number;
|
|
10204
|
+
}): string;
|
|
10205
|
+
/** Canonical message to sign for `unpause`. */
|
|
10206
|
+
declare function buildUnpausePayload(args: {
|
|
10207
|
+
contractAddress: string;
|
|
10208
|
+
nonce: number;
|
|
10209
|
+
}): string;
|
|
10210
|
+
/**
|
|
10211
|
+
* Canonical message to sign for `addSigningKey`. `newKey` is the 64-hex-char
|
|
10212
|
+
* ed25519 public key being added (no 0x).
|
|
10213
|
+
*/
|
|
10214
|
+
declare function buildAddSigningKeyPayload(args: {
|
|
10215
|
+
contractAddress: string;
|
|
10216
|
+
nonce: number;
|
|
10217
|
+
newKey: string;
|
|
10218
|
+
}): string;
|
|
10219
|
+
/**
|
|
10220
|
+
* Canonical message to sign for `revokeSigningKey`. `key` is the 64-hex-char
|
|
10221
|
+
* ed25519 public key being revoked (no 0x).
|
|
10222
|
+
*/
|
|
10223
|
+
declare function buildRevokeSigningKeyPayload(args: {
|
|
10224
|
+
contractAddress: string;
|
|
10225
|
+
nonce: number;
|
|
10226
|
+
key: string;
|
|
10227
|
+
}): string;
|
|
10228
|
+
|
|
10229
|
+
export { type AccountResponse, type AccountType, type paths$1 as AccountsPaths, type AddSigningKeyRequest$1 as AddSigningKeyRequest, type AddSigningKeyResponse, type AdjustCreditsRequest, type AdjustCreditsResponse, type BeginOAuthLoginArgs, type BeginOAuthLoginResult, type paths as ChainPaths, type CheckoutRequest, type CheckoutResponse, type CreateOrgRequest, type CreateOrgResponse, type CreateOrganizationRequest, type CreateOrganizationResponse, type CreateUserRequest, type CreateUserResponse, DelegatedKeys, type FinalizeWitnessResponse, type ForgotPasswordRequest, type ForgotPasswordResponse, type GetWitnessResponse, type HealthLiveResponse, type HealthReadyResponse, type LedgerResponse, type ListDelegatedKeysResponse, type ListOauthSessionsResponse, type ListUsersResponse, type LoginRequest, type LoginResponse, type LogoutResponse, MfaNamespace, MfaRecoveryCodes, MfaTotp, type OAuthTokenSnapshot, OWNER_OP, OauthNamespace, OauthSessions, OrgUsers, type OwnerOpName, type OwnerSigner, type PauseRequest$1 as PauseRequest, type PauseResponse, type PkceVerifierStorage, type PortalResponse, type PrepareDelegatedKeyRequest, type PreparedDelegatedKeyResponse, type ProposeWitnessRequest, type ProposeWitnessResponse, type ProvisionContractRequest, type ProvisionContractResponse, type ProvisionDelegatedKeyArgs, type ProvisionDelegatedKeyResult, type PublicOrgResponse, type RecoveryCodesRegenerateResponse, type ResetAccountResponse, type ResetPasswordRequest, type ResetPasswordResponse, type RevokeDelegatedKeyResponse, type RevokeSigningKeyRequest$1 as RevokeSigningKeyRequest, type RevokeSigningKeyResponse, type RevokeWitnessRequest, type RevokeWitnessResponse, type RotateApiKeyResponse, type SetAccountTypeRequest, type SetAccountTypeResponse, type SignRequest, type SignResponse, type SignWitnessRequest, type SignWitnessResponse, type SignedRequestSigner, SigningKeys, type SignupRequest, type SignupResponse, type SubmitDelegatedKeyRequest, type SubmitDelegatedKeyResponse, Subscriptions, type TotpConfirmRequest, type TotpConfirmResponse, type TotpDisableResponse, type TotpEnrollResponse, type UnpauseRequest, type UnpauseResponse, type VerifyEmailResponse, type VerifyOrganizationResponse, WitniumchainAdminClient, type WitniumchainAdminClientConfig, WitniumchainApiError, WitniumchainChainAdminClient, type WitniumchainChainAdminClientConfig, WitniumchainClient, type WitniumchainClientConfig, WitniumchainOrgClient, type WitniumchainOrgClientConfig, buildAddSigningKeyPayload, buildPausePayload, buildRevokeSigningKeyPayload, buildUnpausePayload, defaultVerifierStorage };
|
package/dist/index.js
CHANGED
|
@@ -129,12 +129,13 @@ var WitniumchainClient = class {
|
|
|
129
129
|
this.baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
130
130
|
this.chainBaseUrl = config.chainBaseUrl?.replace(/\/$/, "");
|
|
131
131
|
this.timeout = config.timeout ?? 3e4;
|
|
132
|
-
|
|
133
|
-
if (!
|
|
132
|
+
const resolvedFetch = config.fetch ?? (globalThis.fetch ? globalThis.fetch.bind(globalThis) : void 0);
|
|
133
|
+
if (!resolvedFetch) {
|
|
134
134
|
throw new Error(
|
|
135
135
|
"WitniumchainClient: no fetch implementation available. Pass `config.fetch`."
|
|
136
136
|
);
|
|
137
137
|
}
|
|
138
|
+
this.fetchImpl = resolvedFetch;
|
|
138
139
|
this.accessToken = config.accessToken;
|
|
139
140
|
this.oauthClientId = config.oauthClientId;
|
|
140
141
|
this.verifierStorage = config.verifierStorage;
|
|
@@ -1394,7 +1395,7 @@ var WitniumchainChainAdminClient = class {
|
|
|
1394
1395
|
this.adminToken = config.adminToken;
|
|
1395
1396
|
this.adminTokenProvider = config.adminTokenProvider;
|
|
1396
1397
|
this.timeout = config.timeout ?? 3e4;
|
|
1397
|
-
this.fetchImpl = config.fetch ?? globalThis.fetch;
|
|
1398
|
+
this.fetchImpl = config.fetch ?? globalThis.fetch.bind(globalThis);
|
|
1398
1399
|
}
|
|
1399
1400
|
async deployContract(body) {
|
|
1400
1401
|
return this.req("POST", "/v5/contracts/deploy", body);
|
|
@@ -1515,10 +1516,55 @@ var OrgUsers = class {
|
|
|
1515
1516
|
}
|
|
1516
1517
|
};
|
|
1517
1518
|
|
|
1519
|
+
// src/owner-ops.ts
|
|
1520
|
+
var OWNER_OP = {
|
|
1521
|
+
addSigningKey: 1,
|
|
1522
|
+
revokeSigningKey: 2,
|
|
1523
|
+
pause: 3,
|
|
1524
|
+
unpause: 4
|
|
1525
|
+
};
|
|
1526
|
+
function build(op, contractAddress, nonce, payload = {}) {
|
|
1527
|
+
if (!/^0x[0-9a-fA-F]{40}$/.test(contractAddress)) {
|
|
1528
|
+
throw new Error("contractAddress must be 0x + 40 hex chars");
|
|
1529
|
+
}
|
|
1530
|
+
if (!Number.isInteger(nonce) || nonce < 0) {
|
|
1531
|
+
throw new Error("nonce must be a non-negative integer");
|
|
1532
|
+
}
|
|
1533
|
+
return JSON.stringify({
|
|
1534
|
+
op,
|
|
1535
|
+
contract: contractAddress.toLowerCase(),
|
|
1536
|
+
nonce,
|
|
1537
|
+
...payload
|
|
1538
|
+
});
|
|
1539
|
+
}
|
|
1540
|
+
function buildPausePayload(args) {
|
|
1541
|
+
return build(OWNER_OP.pause, args.contractAddress, args.nonce);
|
|
1542
|
+
}
|
|
1543
|
+
function buildUnpausePayload(args) {
|
|
1544
|
+
return build(OWNER_OP.unpause, args.contractAddress, args.nonce);
|
|
1545
|
+
}
|
|
1546
|
+
function buildAddSigningKeyPayload(args) {
|
|
1547
|
+
if (!/^[0-9a-fA-F]{64}$/.test(args.newKey)) {
|
|
1548
|
+
throw new Error("newKey must be 64 hex chars (no 0x)");
|
|
1549
|
+
}
|
|
1550
|
+
return build(OWNER_OP.addSigningKey, args.contractAddress, args.nonce, {
|
|
1551
|
+
newKey: args.newKey
|
|
1552
|
+
});
|
|
1553
|
+
}
|
|
1554
|
+
function buildRevokeSigningKeyPayload(args) {
|
|
1555
|
+
if (!/^[0-9a-fA-F]{64}$/.test(args.key)) {
|
|
1556
|
+
throw new Error("key must be 64 hex chars (no 0x)");
|
|
1557
|
+
}
|
|
1558
|
+
return build(OWNER_OP.revokeSigningKey, args.contractAddress, args.nonce, {
|
|
1559
|
+
key: args.key
|
|
1560
|
+
});
|
|
1561
|
+
}
|
|
1562
|
+
|
|
1518
1563
|
exports.DelegatedKeys = DelegatedKeys;
|
|
1519
1564
|
exports.MfaNamespace = MfaNamespace;
|
|
1520
1565
|
exports.MfaRecoveryCodes = MfaRecoveryCodes;
|
|
1521
1566
|
exports.MfaTotp = MfaTotp;
|
|
1567
|
+
exports.OWNER_OP = OWNER_OP;
|
|
1522
1568
|
exports.OauthNamespace = OauthNamespace;
|
|
1523
1569
|
exports.OauthSessions = OauthSessions;
|
|
1524
1570
|
exports.OrgUsers = OrgUsers;
|
|
@@ -1529,6 +1575,10 @@ exports.WitniumchainApiError = WitniumchainApiError;
|
|
|
1529
1575
|
exports.WitniumchainChainAdminClient = WitniumchainChainAdminClient;
|
|
1530
1576
|
exports.WitniumchainClient = WitniumchainClient;
|
|
1531
1577
|
exports.WitniumchainOrgClient = WitniumchainOrgClient;
|
|
1578
|
+
exports.buildAddSigningKeyPayload = buildAddSigningKeyPayload;
|
|
1579
|
+
exports.buildPausePayload = buildPausePayload;
|
|
1580
|
+
exports.buildRevokeSigningKeyPayload = buildRevokeSigningKeyPayload;
|
|
1581
|
+
exports.buildUnpausePayload = buildUnpausePayload;
|
|
1532
1582
|
exports.defaultVerifierStorage = defaultVerifierStorage;
|
|
1533
1583
|
//# sourceMappingURL=index.js.map
|
|
1534
1584
|
//# sourceMappingURL=index.js.map
|