@medialane/sdk 0.39.0 → 0.40.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.cjs +145 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +128 -1
- package/dist/index.d.ts +128 -1
- package/dist/index.js +136 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -5625,10 +5625,10 @@ function normalizeEvm(address) {
|
|
|
5625
5625
|
const m = /^0x([0-9a-fA-F]{40})$/.exec(address);
|
|
5626
5626
|
if (!m) throw new Error(`Invalid ETHEREUM/BASE address: "${address}"`);
|
|
5627
5627
|
const lower = m[1].toLowerCase();
|
|
5628
|
-
const
|
|
5628
|
+
const hash4 = sha3_js.keccak_256(new TextEncoder().encode(lower));
|
|
5629
5629
|
let out = "0x";
|
|
5630
5630
|
for (let i = 0; i < 40; i++) {
|
|
5631
|
-
const nibble =
|
|
5631
|
+
const nibble = hash4[i >> 1] >> (i % 2 === 0 ? 4 : 0) & 15;
|
|
5632
5632
|
out += nibble >= 8 ? lower[i].toUpperCase() : lower[i];
|
|
5633
5633
|
}
|
|
5634
5634
|
return out;
|
|
@@ -5642,12 +5642,12 @@ function normalizeSolana(address) {
|
|
|
5642
5642
|
throw new Error(`Invalid SOLANA address: "${address}"`);
|
|
5643
5643
|
}
|
|
5644
5644
|
}
|
|
5645
|
-
function normalizeHash(
|
|
5645
|
+
function normalizeHash(hash4) {
|
|
5646
5646
|
try {
|
|
5647
|
-
const hex = starknet.num.toHex(BigInt(
|
|
5647
|
+
const hex = starknet.num.toHex(BigInt(hash4));
|
|
5648
5648
|
return "0x" + hex.slice(2).padStart(64, "0").toLowerCase();
|
|
5649
5649
|
} catch {
|
|
5650
|
-
throw new Error(`Invalid hash: "${
|
|
5650
|
+
throw new Error(`Invalid hash: "${hash4}"`);
|
|
5651
5651
|
}
|
|
5652
5652
|
}
|
|
5653
5653
|
function shortenAddress(chain, address, chars = 4) {
|
|
@@ -6730,6 +6730,135 @@ var MedialaneClient = class {
|
|
|
6730
6730
|
}
|
|
6731
6731
|
};
|
|
6732
6732
|
|
|
6733
|
+
// src/admin-auth/types.ts
|
|
6734
|
+
var ADMIN_SCOPE = "admin-api";
|
|
6735
|
+
function adminRequestDigest(req) {
|
|
6736
|
+
return starknet.hash.computePoseidonHashOnElements([
|
|
6737
|
+
starknet.hash.starknetKeccak(req.method.toUpperCase()),
|
|
6738
|
+
starknet.hash.starknetKeccak(req.path),
|
|
6739
|
+
starknet.hash.starknetKeccak(req.body ?? ""),
|
|
6740
|
+
starknet.num.toBigInt(req.nonce),
|
|
6741
|
+
BigInt(req.ts)
|
|
6742
|
+
]);
|
|
6743
|
+
}
|
|
6744
|
+
function signAdminRequest(sessionPrivateKey, req) {
|
|
6745
|
+
const digest = adminRequestDigest(req);
|
|
6746
|
+
return starknet.ec.starkCurve.sign(digest, sessionPrivateKey).toCompactHex();
|
|
6747
|
+
}
|
|
6748
|
+
function verifyAdminRequestSig(sessionPublicKey, req, sig) {
|
|
6749
|
+
try {
|
|
6750
|
+
return starknet.ec.starkCurve.verify(sig, adminRequestDigest(req), sessionPublicKey);
|
|
6751
|
+
} catch {
|
|
6752
|
+
return false;
|
|
6753
|
+
}
|
|
6754
|
+
}
|
|
6755
|
+
function buildAdminSessionTypedData(p) {
|
|
6756
|
+
return {
|
|
6757
|
+
types: {
|
|
6758
|
+
StarknetDomain: [
|
|
6759
|
+
{ name: "name", type: "shortstring" },
|
|
6760
|
+
{ name: "version", type: "shortstring" },
|
|
6761
|
+
{ name: "chainId", type: "shortstring" },
|
|
6762
|
+
{ name: "revision", type: "shortstring" }
|
|
6763
|
+
],
|
|
6764
|
+
AdminSession: [
|
|
6765
|
+
{ name: "sessionKeyHash", type: "felt" },
|
|
6766
|
+
{ name: "scope", type: "shortstring" },
|
|
6767
|
+
{ name: "issuedAt", type: "felt" },
|
|
6768
|
+
{ name: "expiresAt", type: "felt" }
|
|
6769
|
+
]
|
|
6770
|
+
},
|
|
6771
|
+
primaryType: "AdminSession",
|
|
6772
|
+
domain: { name: "Medialane Admin", version: "1", chainId: p.chainId ?? "SN_MAIN", revision: "1" },
|
|
6773
|
+
message: {
|
|
6774
|
+
sessionKeyHash: p.sessionKeyHash,
|
|
6775
|
+
scope: p.scope,
|
|
6776
|
+
issuedAt: String(p.issuedAt),
|
|
6777
|
+
expiresAt: String(p.expiresAt)
|
|
6778
|
+
}
|
|
6779
|
+
};
|
|
6780
|
+
}
|
|
6781
|
+
function sessionKeyHashOf(sessionPublicKey) {
|
|
6782
|
+
return starknet.num.toHex(starknet.hash.starknetKeccak(sessionPublicKey));
|
|
6783
|
+
}
|
|
6784
|
+
async function createAdminSessionGrant(signTypedData, opts) {
|
|
6785
|
+
const priv = starknet.ec.starkCurve.utils.randomPrivateKey();
|
|
6786
|
+
const sessionPrivateKey = "0x" + starknet.encode.buf2hex(priv);
|
|
6787
|
+
const sessionPublicKey = "0x" + starknet.encode.buf2hex(starknet.ec.starkCurve.getPublicKey(sessionPrivateKey, false));
|
|
6788
|
+
const sessionKeyHash = sessionKeyHashOf(sessionPublicKey);
|
|
6789
|
+
const nowSec = Math.floor((opts.now?.() ?? Date.now()) / 1e3);
|
|
6790
|
+
const issuedAt = nowSec;
|
|
6791
|
+
const expiresAt = nowSec + (opts.ttlSeconds ?? 7200);
|
|
6792
|
+
const data = buildAdminSessionTypedData({ sessionKeyHash, scope: ADMIN_SCOPE, issuedAt, expiresAt, chainId: opts.chainId });
|
|
6793
|
+
const walletSig = await signTypedData(data);
|
|
6794
|
+
const grant = {
|
|
6795
|
+
wallet: opts.wallet,
|
|
6796
|
+
chain: opts.chain ?? "STARKNET",
|
|
6797
|
+
sessionPublicKey,
|
|
6798
|
+
sessionKeyHash,
|
|
6799
|
+
scope: ADMIN_SCOPE,
|
|
6800
|
+
issuedAt,
|
|
6801
|
+
expiresAt,
|
|
6802
|
+
walletSig
|
|
6803
|
+
};
|
|
6804
|
+
return { grant, sessionPrivateKey };
|
|
6805
|
+
}
|
|
6806
|
+
|
|
6807
|
+
// src/admin-auth/headers.ts
|
|
6808
|
+
var ADMIN_HEADERS = {
|
|
6809
|
+
grant: "x-ml-admin-grant",
|
|
6810
|
+
sig: "x-ml-admin-sig",
|
|
6811
|
+
nonce: "x-ml-admin-nonce",
|
|
6812
|
+
ts: "x-ml-admin-ts"
|
|
6813
|
+
};
|
|
6814
|
+
function b64urlEncode(s) {
|
|
6815
|
+
const bytes = new TextEncoder().encode(s);
|
|
6816
|
+
let bin = "";
|
|
6817
|
+
for (const b of bytes) bin += String.fromCharCode(b);
|
|
6818
|
+
return btoa(bin).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
6819
|
+
}
|
|
6820
|
+
function b64urlDecode(s) {
|
|
6821
|
+
const pad = s.length % 4 ? "=".repeat(4 - s.length % 4) : "";
|
|
6822
|
+
const bin = atob(s.replace(/-/g, "+").replace(/_/g, "/") + pad);
|
|
6823
|
+
const bytes = Uint8Array.from(bin, (c) => c.charCodeAt(0));
|
|
6824
|
+
return new TextDecoder().decode(bytes);
|
|
6825
|
+
}
|
|
6826
|
+
function randomNonce() {
|
|
6827
|
+
const b = new Uint8Array(16);
|
|
6828
|
+
crypto.getRandomValues(b);
|
|
6829
|
+
let hex = "";
|
|
6830
|
+
for (const x of b) hex += x.toString(16).padStart(2, "0");
|
|
6831
|
+
return "0x" + hex;
|
|
6832
|
+
}
|
|
6833
|
+
function encodeAdminHeaders(session, reqInit) {
|
|
6834
|
+
const nonce = randomNonce();
|
|
6835
|
+
const ts = Math.floor((reqInit.now?.() ?? Date.now()) / 1e3);
|
|
6836
|
+
const req = { method: reqInit.method, path: reqInit.path, body: reqInit.body ?? "", nonce, ts };
|
|
6837
|
+
const sig = signAdminRequest(session.sessionPrivateKey, req);
|
|
6838
|
+
return {
|
|
6839
|
+
[ADMIN_HEADERS.grant]: b64urlEncode(JSON.stringify(session.grant)),
|
|
6840
|
+
[ADMIN_HEADERS.sig]: sig,
|
|
6841
|
+
[ADMIN_HEADERS.nonce]: nonce,
|
|
6842
|
+
[ADMIN_HEADERS.ts]: String(ts)
|
|
6843
|
+
};
|
|
6844
|
+
}
|
|
6845
|
+
function parseAdminHeaders(get) {
|
|
6846
|
+
const rawGrant = get(ADMIN_HEADERS.grant);
|
|
6847
|
+
const sig = get(ADMIN_HEADERS.sig);
|
|
6848
|
+
const nonce = get(ADMIN_HEADERS.nonce);
|
|
6849
|
+
const tsRaw = get(ADMIN_HEADERS.ts);
|
|
6850
|
+
if (!rawGrant || !sig || !nonce || !tsRaw) return null;
|
|
6851
|
+
try {
|
|
6852
|
+
const grant = JSON.parse(b64urlDecode(rawGrant));
|
|
6853
|
+
if (!grant.wallet || !grant.sessionPublicKey || !grant.sessionKeyHash || !Array.isArray(grant.walletSig) || typeof grant.expiresAt !== "number") return null;
|
|
6854
|
+
const ts = Number(tsRaw);
|
|
6855
|
+
if (!Number.isFinite(ts)) return null;
|
|
6856
|
+
return { grant, sig, nonce, ts };
|
|
6857
|
+
} catch {
|
|
6858
|
+
return null;
|
|
6859
|
+
}
|
|
6860
|
+
}
|
|
6861
|
+
|
|
6733
6862
|
// src/types/api.ts
|
|
6734
6863
|
var OPEN_LICENSES = ["CC0", "CC BY", "CC BY-SA", "CC BY-NC"];
|
|
6735
6864
|
|
|
@@ -6979,6 +7108,8 @@ function getServicesByCapability(cap) {
|
|
|
6979
7108
|
);
|
|
6980
7109
|
}
|
|
6981
7110
|
|
|
7111
|
+
exports.ADMIN_HEADERS = ADMIN_HEADERS;
|
|
7112
|
+
exports.ADMIN_SCOPE = ADMIN_SCOPE;
|
|
6982
7113
|
exports.ApiClient = ApiClient;
|
|
6983
7114
|
exports.CHAINS = CHAINS;
|
|
6984
7115
|
exports.COIN_MAX_SUPPLY = MAX_SUPPLY;
|
|
@@ -7036,8 +7167,10 @@ exports.PUBLIC_RPC_FALLBACKS = PUBLIC_RPC_FALLBACKS;
|
|
|
7036
7167
|
exports.PopService = PopService;
|
|
7037
7168
|
exports.SUPPORTED_TOKENS = SUPPORTED_TOKENS;
|
|
7038
7169
|
exports.VALIDATED_EKUBO_PARAMS = VALIDATED_EKUBO_PARAMS;
|
|
7170
|
+
exports.adminRequestDigest = adminRequestDigest;
|
|
7039
7171
|
exports.build1155CancellationTypedData = build1155CancellationTypedData;
|
|
7040
7172
|
exports.build1155OrderTypedData = build1155OrderTypedData;
|
|
7173
|
+
exports.buildAdminSessionTypedData = buildAdminSessionTypedData;
|
|
7041
7174
|
exports.buildCancellationTypedData = buildCancellationTypedData;
|
|
7042
7175
|
exports.buildCreateCreatorCoinCall = buildCreateCreatorCoinCall;
|
|
7043
7176
|
exports.buildFeeCall = buildFeeCall;
|
|
@@ -7045,7 +7178,9 @@ exports.buildLaunchOnEkuboCalls = buildLaunchOnEkuboCalls;
|
|
|
7045
7178
|
exports.buildOrderTypedData = buildOrderTypedData;
|
|
7046
7179
|
exports.buybackQuoteRaw = buybackQuoteRaw;
|
|
7047
7180
|
exports.coinToRaw = toRaw;
|
|
7181
|
+
exports.createAdminSessionGrant = createAdminSessionGrant;
|
|
7048
7182
|
exports.createFailoverFetch = createFailoverFetch;
|
|
7183
|
+
exports.encodeAdminHeaders = encodeAdminHeaders;
|
|
7049
7184
|
exports.encodeByteArray = encodeByteArray;
|
|
7050
7185
|
exports.fdvHuman = fdvHuman;
|
|
7051
7186
|
exports.formatAmount = formatAmount;
|
|
@@ -7061,16 +7196,21 @@ exports.isTransientRpcError = isTransientRpcError;
|
|
|
7061
7196
|
exports.listServices = listServices;
|
|
7062
7197
|
exports.normalizeAddress = normalizeAddress;
|
|
7063
7198
|
exports.normalizeHash = normalizeHash;
|
|
7199
|
+
exports.parseAdminHeaders = parseAdminHeaders;
|
|
7064
7200
|
exports.parseAmount = parseAmount;
|
|
7065
7201
|
exports.parseCreatorCoinCreated = parseCreatorCoinCreated;
|
|
7202
|
+
exports.randomNonce = randomNonce;
|
|
7066
7203
|
exports.resolveConfig = resolveConfig;
|
|
7067
7204
|
exports.resolveFeeConfig = resolveFeeConfig;
|
|
7205
|
+
exports.sessionKeyHashOf = sessionKeyHashOf;
|
|
7068
7206
|
exports.shortenAddress = shortenAddress;
|
|
7207
|
+
exports.signAdminRequest = signAdminRequest;
|
|
7069
7208
|
exports.stringifyBigInts = stringifyBigInts;
|
|
7070
7209
|
exports.teamCoinsRaw = teamCoinsRaw;
|
|
7071
7210
|
exports.u256ToBigInt = u256ToBigInt;
|
|
7072
7211
|
exports.validateCoinName = validateName;
|
|
7073
7212
|
exports.validateCoinSupply = validateSupply;
|
|
7074
7213
|
exports.validateCoinSymbol = validateSymbol;
|
|
7214
|
+
exports.verifyAdminRequestSig = verifyAdminRequestSig;
|
|
7075
7215
|
//# sourceMappingURL=index.cjs.map
|
|
7076
7216
|
//# sourceMappingURL=index.cjs.map
|