uvd-x402-sdk 2.110.0 → 2.111.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/providers/near/index.d.mts +237 -1
- package/dist/providers/near/index.d.ts +237 -1
- package/dist/providers/near/index.js +523 -4
- package/dist/providers/near/index.js.map +1 -1
- package/dist/providers/near/index.mjs +495 -5
- package/dist/providers/near/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/providers/near/index.ts +1 -0
- package/src/providers/near/registry.ts +454 -0
- package/src/providers/near/vectors/near-registry.json +126 -0
|
@@ -1484,7 +1484,7 @@ function validateEscrowAuthorizationDelegate(d, o) {
|
|
|
1484
1484
|
if (gas < NEAR_ESCROW_MIN_GAS || gas > NEAR_ESCROW_MAX_GAS) throw new Error("FT gas outside 38..100 TGas");
|
|
1485
1485
|
}
|
|
1486
1486
|
async function signDelegate(o, d, scheme = "escrow") {
|
|
1487
|
-
const
|
|
1487
|
+
const network2 = o.network;
|
|
1488
1488
|
const pk = new Uint8Array(o.signer.publicKey);
|
|
1489
1489
|
if (pk.length !== 32) throw new Error("Expected 32-byte Ed25519 public key");
|
|
1490
1490
|
const a = d.actions[0];
|
|
@@ -1511,7 +1511,7 @@ async function signDelegate(o, d, scheme = "escrow") {
|
|
|
1511
1511
|
return {
|
|
1512
1512
|
x402Version: 2,
|
|
1513
1513
|
scheme,
|
|
1514
|
-
network,
|
|
1514
|
+
network: network2,
|
|
1515
1515
|
payload: { signedDelegateAction: btoa(Array.from(signed, (b) => String.fromCharCode(b)).join("")) }
|
|
1516
1516
|
};
|
|
1517
1517
|
}
|
|
@@ -1726,6 +1726,496 @@ function parseArrasEvents(logs) {
|
|
|
1726
1726
|
}
|
|
1727
1727
|
return result;
|
|
1728
1728
|
}
|
|
1729
|
+
var NEAR_REGISTRY_CONTRACTS = Object.freeze({
|
|
1730
|
+
"near:mainnet": Object.freeze(["registry.arras-escrow.near"]),
|
|
1731
|
+
"near:testnet": Object.freeze([])
|
|
1732
|
+
});
|
|
1733
|
+
var NEAR_REGISTRY_ESCROWS = Object.freeze({
|
|
1734
|
+
"near:mainnet": Object.freeze(["v1.arras-escrow.near"]),
|
|
1735
|
+
"near:testnet": Object.freeze([])
|
|
1736
|
+
});
|
|
1737
|
+
var REGISTER_DEPOSIT = "17510000000000000000000";
|
|
1738
|
+
var FEEDBACK_DEPOSIT = "18640000000000000000000";
|
|
1739
|
+
var REGISTRY_GAS = "30000000000000";
|
|
1740
|
+
var GIVE_FEEDBACK_GAS = "100000000000000";
|
|
1741
|
+
var MIN_GIVE_FEEDBACK_GAS = "60000000000000";
|
|
1742
|
+
var RegistryErrorCode = /* @__PURE__ */ ((RegistryErrorCode2) => {
|
|
1743
|
+
RegistryErrorCode2["E01"] = "E01_AGENT_URI_INVALIDA";
|
|
1744
|
+
RegistryErrorCode2["E02"] = "E02_METADATA_INVALIDA";
|
|
1745
|
+
RegistryErrorCode2["E03"] = "E03_YA_REGISTRADO";
|
|
1746
|
+
RegistryErrorCode2["E04"] = "E04_NO_REGISTRADO";
|
|
1747
|
+
RegistryErrorCode2["E05"] = "E05_DEPOSITO_INSUFICIENTE";
|
|
1748
|
+
RegistryErrorCode2["E06"] = "E06_REQUIERE_DEPOSITO";
|
|
1749
|
+
RegistryErrorCode2["E10"] = "E10_ESCROW_NO_PERMITIDO";
|
|
1750
|
+
RegistryErrorCode2["E11"] = "E11_PAYMENT_ID_INVALIDO";
|
|
1751
|
+
RegistryErrorCode2["E12"] = "E12_SCORE_INVALIDO";
|
|
1752
|
+
RegistryErrorCode2["E13"] = "E13_TAG_INVALIDO";
|
|
1753
|
+
RegistryErrorCode2["E14"] = "E14_FEEDBACK_URI_INVALIDA";
|
|
1754
|
+
RegistryErrorCode2["E15"] = "E15_FEEDBACK_HASH_INVALIDO";
|
|
1755
|
+
RegistryErrorCode2["E16"] = "E16_DEPOSITO_FEEDBACK";
|
|
1756
|
+
RegistryErrorCode2["E17"] = "E17_GAS_INSUFICIENTE";
|
|
1757
|
+
RegistryErrorCode2["E18"] = "E18_YA_CALIFICADO";
|
|
1758
|
+
RegistryErrorCode2["E19"] = "E19_EN_VUELO";
|
|
1759
|
+
RegistryErrorCode2["E20"] = "E20_GET_PAYMENT_FALLO";
|
|
1760
|
+
RegistryErrorCode2["E21"] = "E21_RESPUESTA_INVALIDA";
|
|
1761
|
+
RegistryErrorCode2["E22"] = "E22_PAGO_INEXISTENTE";
|
|
1762
|
+
RegistryErrorCode2["E23"] = "E23_PAGO_SIN_LIBERAR";
|
|
1763
|
+
RegistryErrorCode2["E24"] = "E24_NO_ES_PARTE";
|
|
1764
|
+
RegistryErrorCode2["E25"] = "E25_AUTO_CALIFICACION";
|
|
1765
|
+
RegistryErrorCode2["E26"] = "E26_REEMPLAZADO";
|
|
1766
|
+
RegistryErrorCode2["E30"] = "E30_FEEDBACK_INEXISTENTE";
|
|
1767
|
+
RegistryErrorCode2["E31"] = "E31_YA_REVOCADO";
|
|
1768
|
+
RegistryErrorCode2["E40"] = "E40_ESCROWS_INVALIDOS";
|
|
1769
|
+
return RegistryErrorCode2;
|
|
1770
|
+
})(RegistryErrorCode || {});
|
|
1771
|
+
var RegistryValidationError = class extends Error {
|
|
1772
|
+
constructor(code) {
|
|
1773
|
+
super(`ARRAS_REG_${code.slice(0, 3)}: ${code}`);
|
|
1774
|
+
this.code = code;
|
|
1775
|
+
}
|
|
1776
|
+
};
|
|
1777
|
+
function requireRule(ok, code) {
|
|
1778
|
+
if (!ok) throw new RegistryValidationError(code);
|
|
1779
|
+
}
|
|
1780
|
+
function validUri(value) {
|
|
1781
|
+
return typeof value === "string" && value.length <= 512 && fullMatch(/^[A-Za-z][A-Za-z0-9+.-]*:[\x21-\x7e]+$/, value);
|
|
1782
|
+
}
|
|
1783
|
+
function validMetadata(value) {
|
|
1784
|
+
return typeof value === "string" && value.length > 0 && new TextEncoder().encode(value).length <= 1024 && !/[\x00-\x1f\x7f]/u.test(value) && !/[\ud800-\udfff]/u.test(value);
|
|
1785
|
+
}
|
|
1786
|
+
function validTag(value) {
|
|
1787
|
+
return typeof value === "string" && fullMatch(/^[A-Za-z0-9._:/-]{1,64}$/, value);
|
|
1788
|
+
}
|
|
1789
|
+
function validPaymentId(value) {
|
|
1790
|
+
return typeof value === "string" && fullMatch(/^[\x21-\x7e]{1,64}$/, value);
|
|
1791
|
+
}
|
|
1792
|
+
function validHash(value) {
|
|
1793
|
+
return typeof value === "string" && fullMatch(/^[0-9a-f]{64}$/, value);
|
|
1794
|
+
}
|
|
1795
|
+
function validScore(value) {
|
|
1796
|
+
return typeof value === "number" && Number.isInteger(value) && value >= 0 && value <= 100;
|
|
1797
|
+
}
|
|
1798
|
+
function network(value) {
|
|
1799
|
+
if (value !== "near:mainnet" && value !== "near:testnet") throw new Error("Unsupported NEAR network");
|
|
1800
|
+
}
|
|
1801
|
+
function receiver(o) {
|
|
1802
|
+
network(o.network);
|
|
1803
|
+
const id = o.registryContract ?? NEAR_REGISTRY_CONTRACTS[o.network][0];
|
|
1804
|
+
if (!NEAR_REGISTRY_CONTRACTS[o.network].includes(id)) throw new Error("receiverId: unregistered registry for network");
|
|
1805
|
+
return id;
|
|
1806
|
+
}
|
|
1807
|
+
function escrow(value, net) {
|
|
1808
|
+
requireRule(NEAR_REGISTRY_ESCROWS[net].includes(value), "E10_ESCROW_NO_PERMITIDO" /* E10 */);
|
|
1809
|
+
}
|
|
1810
|
+
function codedUint(value, bits, code) {
|
|
1811
|
+
try {
|
|
1812
|
+
return uint(value, bits, code);
|
|
1813
|
+
} catch {
|
|
1814
|
+
throw new RegistryValidationError(code);
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1817
|
+
function canonicalArgs(method, input, net) {
|
|
1818
|
+
const allowed = method === "register" || method === "update" ? ["agent_uri", "metadata"] : method === "give_feedback" ? ["escrow", "payment_id", "score", "tag1", "tag2", "feedback_uri", "feedback_hash"] : ["escrow", "payment_id"];
|
|
1819
|
+
if (Object.keys(input).some((key) => !allowed.includes(key))) throw new Error("Unexpected registry argument");
|
|
1820
|
+
const args = {};
|
|
1821
|
+
if (method === "register" || method === "update") {
|
|
1822
|
+
requireRule(validUri(input.agent_uri), "E01_AGENT_URI_INVALIDA" /* E01 */);
|
|
1823
|
+
args.agent_uri = input.agent_uri;
|
|
1824
|
+
if (input.metadata != null) {
|
|
1825
|
+
requireRule(validMetadata(input.metadata), "E02_METADATA_INVALIDA" /* E02 */);
|
|
1826
|
+
args.metadata = input.metadata;
|
|
1827
|
+
}
|
|
1828
|
+
} else {
|
|
1829
|
+
escrow(input.escrow, net);
|
|
1830
|
+
requireRule(validPaymentId(input.payment_id), "E11_PAYMENT_ID_INVALIDO" /* E11 */);
|
|
1831
|
+
args.escrow = input.escrow;
|
|
1832
|
+
args.payment_id = input.payment_id;
|
|
1833
|
+
if (method === "give_feedback") {
|
|
1834
|
+
requireRule(validScore(input.score), "E12_SCORE_INVALIDO" /* E12 */);
|
|
1835
|
+
args.score = input.score;
|
|
1836
|
+
for (const field of ["tag1", "tag2"]) {
|
|
1837
|
+
if (input[field] != null) {
|
|
1838
|
+
requireRule(validTag(input[field]), "E13_TAG_INVALIDO" /* E13 */);
|
|
1839
|
+
args[field] = input[field];
|
|
1840
|
+
}
|
|
1841
|
+
}
|
|
1842
|
+
if (input.feedback_uri != null) {
|
|
1843
|
+
requireRule(validUri(input.feedback_uri), "E14_FEEDBACK_URI_INVALIDA" /* E14 */);
|
|
1844
|
+
args.feedback_uri = input.feedback_uri;
|
|
1845
|
+
}
|
|
1846
|
+
if (input.feedback_hash != null) {
|
|
1847
|
+
requireRule(validHash(input.feedback_hash), "E15_FEEDBACK_HASH_INVALIDO" /* E15 */);
|
|
1848
|
+
args.feedback_hash = input.feedback_hash;
|
|
1849
|
+
}
|
|
1850
|
+
}
|
|
1851
|
+
}
|
|
1852
|
+
return args;
|
|
1853
|
+
}
|
|
1854
|
+
function build(method, options, input) {
|
|
1855
|
+
const o = { ...options };
|
|
1856
|
+
const receiverId = receiver(o);
|
|
1857
|
+
account(o.signerId, "signerId");
|
|
1858
|
+
const updateDeposit = method === "update" ? codedUint(o.deposit === void 0 ? REGISTER_DEPOSIT : o.deposit, 128, "E06_REQUIERE_DEPOSITO" /* E06 */) : void 0;
|
|
1859
|
+
if (updateDeposit !== void 0) requireRule(updateDeposit > 0n, "E06_REQUIERE_DEPOSITO" /* E06 */);
|
|
1860
|
+
const args = canonicalArgs(method, { ...input }, o.network);
|
|
1861
|
+
const depositCode = method === "give_feedback" ? "E16_DEPOSITO_FEEDBACK" /* E16 */ : "E05_DEPOSITO_INSUFICIENTE" /* E05 */;
|
|
1862
|
+
const minimum = method === "give_feedback" ? FEEDBACK_DEPOSIT : REGISTER_DEPOSIT;
|
|
1863
|
+
const deposit = updateDeposit ?? (method === "revoke_feedback" ? uint(o.deposit === void 0 ? "1" : o.deposit, 128, "deposit") : codedUint(o.deposit === void 0 ? minimum : o.deposit, 128, depositCode));
|
|
1864
|
+
if (method === "revoke_feedback") {
|
|
1865
|
+
if (deposit !== 1n) throw new Error("revoke_feedback deposit must be exactly 1 yocto");
|
|
1866
|
+
} else if (method !== "update") {
|
|
1867
|
+
requireRule(deposit >= BigInt(minimum), depositCode);
|
|
1868
|
+
}
|
|
1869
|
+
const gas = uint(o.gas === void 0 ? method === "give_feedback" ? GIVE_FEEDBACK_GAS : REGISTRY_GAS : o.gas, 64, "gas");
|
|
1870
|
+
if (method === "give_feedback") requireRule(gas >= BigInt(MIN_GIVE_FEEDBACK_GAS), "E17_GAS_INSUFICIENTE" /* E17 */);
|
|
1871
|
+
else if (gas < 1n) throw new Error("gas must be positive");
|
|
1872
|
+
if (gas > 300000000000000n) throw new Error("gas exceeds 300 TGas");
|
|
1873
|
+
return { signerId: o.signerId, receiverId, actions: [{ type: "FunctionCall", params: {
|
|
1874
|
+
methodName: method,
|
|
1875
|
+
args,
|
|
1876
|
+
gas: gas.toString(),
|
|
1877
|
+
deposit: deposit.toString()
|
|
1878
|
+
} }] };
|
|
1879
|
+
}
|
|
1880
|
+
var buildRegistryRegister = (options) => {
|
|
1881
|
+
const { agent_uri, metadata, ...o } = options;
|
|
1882
|
+
return build("register", o, { agent_uri, metadata });
|
|
1883
|
+
};
|
|
1884
|
+
var buildRegistryUpdate = (options) => {
|
|
1885
|
+
const { agent_uri, metadata, ...o } = options;
|
|
1886
|
+
return build("update", o, { agent_uri, metadata });
|
|
1887
|
+
};
|
|
1888
|
+
var buildGiveFeedback = (options) => {
|
|
1889
|
+
const { escrow: escrow2, payment_id, score, tag1, tag2, feedback_uri, feedback_hash, ...o } = options;
|
|
1890
|
+
return build("give_feedback", o, { escrow: escrow2, payment_id, score, tag1, tag2, feedback_uri, feedback_hash });
|
|
1891
|
+
};
|
|
1892
|
+
var buildRevokeFeedback = (options) => {
|
|
1893
|
+
const { escrow: escrow2, payment_id, ...o } = options;
|
|
1894
|
+
return build("revoke_feedback", o, { escrow: escrow2, payment_id });
|
|
1895
|
+
};
|
|
1896
|
+
function base64(bytes) {
|
|
1897
|
+
return btoa(Array.from(bytes, (b) => String.fromCharCode(b)).join(""));
|
|
1898
|
+
}
|
|
1899
|
+
function fromBase64(value) {
|
|
1900
|
+
if (!fullMatch(/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/, value)) throw new Error("Invalid base64");
|
|
1901
|
+
return Uint8Array.from(atob(value), (c) => c.charCodeAt(0));
|
|
1902
|
+
}
|
|
1903
|
+
async function signRegistryTransaction(descriptor, signer, nonce, blockHash) {
|
|
1904
|
+
const { signerId, receiverId, actions } = descriptor;
|
|
1905
|
+
const net = Object.keys(NEAR_REGISTRY_CONTRACTS).find((n2) => NEAR_REGISTRY_CONTRACTS[n2].includes(receiverId));
|
|
1906
|
+
if (!net) throw new Error("receiverId: unregistered registry");
|
|
1907
|
+
if (!Array.isArray(actions) || actions.length !== 1) throw new Error("Expected exactly one registry action");
|
|
1908
|
+
const action = { ...actions[0] };
|
|
1909
|
+
if (action.type !== "FunctionCall") throw new Error("Expected FunctionCall");
|
|
1910
|
+
const p = { ...action.params };
|
|
1911
|
+
if (!["register", "update", "give_feedback", "revoke_feedback"].includes(p.methodName)) throw new Error("Unknown registry method");
|
|
1912
|
+
if (typeof p.gas !== "string" || typeof p.deposit !== "string") throw new Error("Expected gas and deposit strings");
|
|
1913
|
+
if (!object2(p.args)) throw new Error("Expected registry args object");
|
|
1914
|
+
const d = build(p.methodName, { network: net, registryContract: receiverId, signerId, deposit: p.deposit, gas: p.gas }, { ...p.args });
|
|
1915
|
+
const a = d.actions[0].params;
|
|
1916
|
+
const n = uint(nonce, 64, "nonce");
|
|
1917
|
+
if (n === 0n) throw new Error("nonce must be positive");
|
|
1918
|
+
const hash = unbase58(blockHash);
|
|
1919
|
+
if (hash.length !== 32) throw new Error("Expected 32-byte block hash");
|
|
1920
|
+
const pk = new Uint8Array(signer.publicKey);
|
|
1921
|
+
if (pk.length !== 32) throw new Error("Expected 32-byte Ed25519 public key");
|
|
1922
|
+
const bytes = concat(
|
|
1923
|
+
str(d.signerId),
|
|
1924
|
+
Uint8Array.of(0),
|
|
1925
|
+
pk,
|
|
1926
|
+
le(n, 8),
|
|
1927
|
+
str(d.receiverId),
|
|
1928
|
+
hash,
|
|
1929
|
+
le(1n, 4),
|
|
1930
|
+
Uint8Array.of(2),
|
|
1931
|
+
str(a.methodName),
|
|
1932
|
+
str(JSON.stringify(a.args)),
|
|
1933
|
+
le(BigInt(a.gas), 8),
|
|
1934
|
+
le(BigInt(a.deposit), 16)
|
|
1935
|
+
);
|
|
1936
|
+
const digest = sha256.sha256(bytes);
|
|
1937
|
+
const signature = await signer.sign(digest.slice());
|
|
1938
|
+
if (!(signature instanceof Uint8Array) || signature.length !== 64 || !ed25519.ed25519.verify(signature, digest, pk)) {
|
|
1939
|
+
throw new Error("Invalid Ed25519 transaction signature");
|
|
1940
|
+
}
|
|
1941
|
+
return base64(concat(bytes, Uint8Array.of(0), signature));
|
|
1942
|
+
}
|
|
1943
|
+
var object2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1944
|
+
var string2 = (v) => typeof v === "string";
|
|
1945
|
+
var boolean2 = (v) => typeof v === "boolean";
|
|
1946
|
+
var nullable = (check) => (v) => v === null || check(v);
|
|
1947
|
+
var array = (check) => (v) => Array.isArray(v) && v.every(check);
|
|
1948
|
+
function record2(required, optional = {}) {
|
|
1949
|
+
return (v) => object2(v) && Object.entries(required).every(([k, check]) => Object.hasOwn(v, k) && check(v[k])) && Object.entries(optional).every(([k, check]) => !Object.hasOwn(v, k) || check(v[k]));
|
|
1950
|
+
}
|
|
1951
|
+
var integer2 = (bits) => (v) => {
|
|
1952
|
+
if (typeof v !== "string") return false;
|
|
1953
|
+
try {
|
|
1954
|
+
uint(v, bits, "view integer");
|
|
1955
|
+
return true;
|
|
1956
|
+
} catch {
|
|
1957
|
+
return false;
|
|
1958
|
+
}
|
|
1959
|
+
};
|
|
1960
|
+
var u32 = (v) => typeof v === "number" && Number.isInteger(v) && v >= 0 && v <= 4294967295;
|
|
1961
|
+
var u642 = integer2(64);
|
|
1962
|
+
var u1282 = integer2(128);
|
|
1963
|
+
var accountCheck = (v) => {
|
|
1964
|
+
try {
|
|
1965
|
+
account(v, "account");
|
|
1966
|
+
return true;
|
|
1967
|
+
} catch {
|
|
1968
|
+
return false;
|
|
1969
|
+
}
|
|
1970
|
+
};
|
|
1971
|
+
var operator2 = (v) => typeof v === "string" && new TextEncoder().encode(v).length <= 64 && !/[\ud800-\udfff]/u.test(v);
|
|
1972
|
+
var role = (v) => v === "payer" || v === "receiver";
|
|
1973
|
+
var agentFields = { account_id: accountCheck, agent_uri: validUri, metadata: nullable(validMetadata) };
|
|
1974
|
+
var feedbackFields = {
|
|
1975
|
+
feedback_id: u32,
|
|
1976
|
+
rater: accountCheck,
|
|
1977
|
+
ratee: accountCheck,
|
|
1978
|
+
ratee_role: role,
|
|
1979
|
+
escrow: accountCheck,
|
|
1980
|
+
payment_id: validPaymentId,
|
|
1981
|
+
operator_id: operator2,
|
|
1982
|
+
released: u1282,
|
|
1983
|
+
score: validScore,
|
|
1984
|
+
tag1: nullable(validTag),
|
|
1985
|
+
tag2: nullable(validTag),
|
|
1986
|
+
feedback_uri: nullable(validUri),
|
|
1987
|
+
feedback_hash: nullable(validHash),
|
|
1988
|
+
created_at: u642
|
|
1989
|
+
};
|
|
1990
|
+
var agentCheck = record2({ ...agentFields, registered_at: u642, updated_at: u642 });
|
|
1991
|
+
var feedbackCheck = record2({ ...feedbackFields, revoked: boolean2, revoked_at: nullable(u642) });
|
|
1992
|
+
var average = (v) => typeof v === "number" && Number.isInteger(v) && v >= 0 && v <= 1e4;
|
|
1993
|
+
var summaryFields = { count: u32, revoked: u32, score_sum: u642, average_x100: nullable(average) };
|
|
1994
|
+
var summaryCheck = record2({
|
|
1995
|
+
...summaryFields,
|
|
1996
|
+
account_id: accountCheck,
|
|
1997
|
+
as_payer: record2(summaryFields),
|
|
1998
|
+
as_receiver: record2(summaryFields),
|
|
1999
|
+
last_feedback_id: nullable(u32),
|
|
2000
|
+
last_at: nullable(u642)
|
|
2001
|
+
}, { operator_id: string2 });
|
|
2002
|
+
var configCheck = record2({
|
|
2003
|
+
version: (v) => v === "arras-registry-v1",
|
|
2004
|
+
escrows: array(accountCheck),
|
|
2005
|
+
agents: u32,
|
|
2006
|
+
feedbacks: u32,
|
|
2007
|
+
register_deposit: u1282,
|
|
2008
|
+
feedback_deposit: u1282,
|
|
2009
|
+
min_gas_give_feedback: u642,
|
|
2010
|
+
limits: record2({
|
|
2011
|
+
max_agent_uri_len: u32,
|
|
2012
|
+
max_metadata_len: u32,
|
|
2013
|
+
max_feedback_uri_len: u32,
|
|
2014
|
+
max_tag_len: u32,
|
|
2015
|
+
max_payment_id_len: u32,
|
|
2016
|
+
max_score: (v) => u32(v) && v <= 255,
|
|
2017
|
+
max_list_limit: u32,
|
|
2018
|
+
pending_ttl_blocks: u642
|
|
2019
|
+
})
|
|
2020
|
+
});
|
|
2021
|
+
var rpcUrls = {
|
|
2022
|
+
"near:mainnet": "https://rpc.mainnet.near.org",
|
|
2023
|
+
"near:testnet": "https://rpc.testnet.near.org"
|
|
2024
|
+
};
|
|
2025
|
+
async function view(options, method, args, check) {
|
|
2026
|
+
const o = { ...options };
|
|
2027
|
+
const id = receiver(o);
|
|
2028
|
+
const rpc = o.rpc ?? (async (method2, params) => {
|
|
2029
|
+
const response2 = await fetch(rpcUrls[o.network], {
|
|
2030
|
+
method: "POST",
|
|
2031
|
+
headers: { "Content-Type": "application/json" },
|
|
2032
|
+
body: JSON.stringify({ jsonrpc: "2.0", id: "registry", method: method2, params })
|
|
2033
|
+
});
|
|
2034
|
+
if (!response2.ok) throw new Error(`NEAR RPC HTTP ${response2.status}`);
|
|
2035
|
+
const data = await response2.json();
|
|
2036
|
+
if (!object2(data) || data.error || !Object.hasOwn(data, "result")) throw new Error("Invalid NEAR RPC response");
|
|
2037
|
+
return data.result;
|
|
2038
|
+
});
|
|
2039
|
+
const response = await rpc("query", {
|
|
2040
|
+
request_type: "call_function",
|
|
2041
|
+
finality: "final",
|
|
2042
|
+
account_id: id,
|
|
2043
|
+
method_name: method,
|
|
2044
|
+
args_base64: base64(new TextEncoder().encode(JSON.stringify(args)))
|
|
2045
|
+
});
|
|
2046
|
+
if (!object2(response) || !Array.isArray(response.result) || !response.result.every((v) => Number.isInteger(v) && v >= 0 && v <= 255)) throw new Error("Invalid call_function response");
|
|
2047
|
+
const value = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(Uint8Array.from(response.result)));
|
|
2048
|
+
if (!check(value)) throw new Error(`Invalid ${method} response shape`);
|
|
2049
|
+
return value;
|
|
2050
|
+
}
|
|
2051
|
+
function accountArgs(accountId) {
|
|
2052
|
+
account(accountId, "account_id");
|
|
2053
|
+
return { account_id: accountId };
|
|
2054
|
+
}
|
|
2055
|
+
function page(p) {
|
|
2056
|
+
const result = {};
|
|
2057
|
+
for (const k of ["from_index", "limit"]) {
|
|
2058
|
+
const v = p[k];
|
|
2059
|
+
if (v !== void 0) {
|
|
2060
|
+
if (!u32(v)) throw new Error(`Invalid ${k}`);
|
|
2061
|
+
result[k] = v;
|
|
2062
|
+
}
|
|
2063
|
+
}
|
|
2064
|
+
return result;
|
|
2065
|
+
}
|
|
2066
|
+
function paymentArgs(o, input) {
|
|
2067
|
+
network(o.network);
|
|
2068
|
+
escrow(input.escrow, o.network);
|
|
2069
|
+
requireRule(validPaymentId(input.payment_id), "E11_PAYMENT_ID_INVALIDO" /* E11 */);
|
|
2070
|
+
account(input.rater, "rater");
|
|
2071
|
+
return { escrow: input.escrow, payment_id: input.payment_id, rater: input.rater };
|
|
2072
|
+
}
|
|
2073
|
+
var getConfig = async (o) => view(o, "get_config", {}, configCheck);
|
|
2074
|
+
var getAgent = async (o, accountId) => view(o, "get_agent", accountArgs(accountId), nullable(agentCheck));
|
|
2075
|
+
var listAgents = async (o, p = {}) => view(o, "list_agents", page(p), array(agentCheck));
|
|
2076
|
+
var getFeedback = async (o, feedbackId) => {
|
|
2077
|
+
if (!u32(feedbackId)) throw new Error("Invalid feedback_id");
|
|
2078
|
+
return view(o, "get_feedback", { feedback_id: feedbackId }, nullable(feedbackCheck));
|
|
2079
|
+
};
|
|
2080
|
+
var getFeedbackForPayment = async (o, p) => view(o, "get_feedback_for_payment", paymentArgs(o, p), nullable(feedbackCheck));
|
|
2081
|
+
var listFeedback = async (o, accountId, p = {}) => view(o, "list_feedback", { ...accountArgs(accountId), ...page(p) }, array(feedbackCheck));
|
|
2082
|
+
var getSummary = async (o, accountId) => view(o, "get_summary", accountArgs(accountId), (v) => summaryCheck(v) && object2(v) && !Object.hasOwn(v, "operator_id"));
|
|
2083
|
+
var getSummaryByOperator = async (o, accountId, operatorId) => {
|
|
2084
|
+
if (typeof operatorId !== "string") throw new Error("Invalid operator_id");
|
|
2085
|
+
return view(
|
|
2086
|
+
o,
|
|
2087
|
+
"get_summary_by_operator",
|
|
2088
|
+
{ ...accountArgs(accountId), operator_id: operatorId },
|
|
2089
|
+
(v) => summaryCheck(v) && object2(v) && Object.hasOwn(v, "operator_id")
|
|
2090
|
+
);
|
|
2091
|
+
};
|
|
2092
|
+
var isFeedbackPending = async (o, p) => view(o, "is_feedback_pending", paymentArgs(o, p), boolean2);
|
|
2093
|
+
var eventChecks = {
|
|
2094
|
+
agent_registered: record2({ ...agentFields, at: u642 }),
|
|
2095
|
+
agent_updated: record2({ ...agentFields, at: u642 }),
|
|
2096
|
+
feedback_given: record2(feedbackFields),
|
|
2097
|
+
feedback_revoked: record2({
|
|
2098
|
+
feedback_id: u32,
|
|
2099
|
+
rater: accountCheck,
|
|
2100
|
+
ratee: accountCheck,
|
|
2101
|
+
escrow: accountCheck,
|
|
2102
|
+
payment_id: validPaymentId,
|
|
2103
|
+
revoked_at: u642
|
|
2104
|
+
})
|
|
2105
|
+
};
|
|
2106
|
+
function parseRegistryEvents(logs) {
|
|
2107
|
+
const result = [];
|
|
2108
|
+
if (!Array.isArray(logs)) return result;
|
|
2109
|
+
for (const log of logs) {
|
|
2110
|
+
if (typeof log !== "string" || !log.startsWith("EVENT_JSON:")) continue;
|
|
2111
|
+
let v;
|
|
2112
|
+
try {
|
|
2113
|
+
v = JSON.parse(log.slice(11));
|
|
2114
|
+
} catch {
|
|
2115
|
+
continue;
|
|
2116
|
+
}
|
|
2117
|
+
if (!object2(v) || v.standard !== "arras-registry" || v.version !== "1.0.0" || typeof v.event !== "string" || !Object.hasOwn(eventChecks, v.event) || !Array.isArray(v.data)) continue;
|
|
2118
|
+
if (!v.data.every(eventChecks[v.event])) continue;
|
|
2119
|
+
result.push({ standard: "arras-registry", version: "1.0.0", event: v.event, data: v.data });
|
|
2120
|
+
}
|
|
2121
|
+
return result;
|
|
2122
|
+
}
|
|
2123
|
+
function parseRegistryReceiptEvents(receiptsOutcome, net) {
|
|
2124
|
+
network(net);
|
|
2125
|
+
const result = [];
|
|
2126
|
+
if (!Array.isArray(receiptsOutcome)) return result;
|
|
2127
|
+
for (const receipt of receiptsOutcome) {
|
|
2128
|
+
if (!object2(receipt) || !object2(receipt.outcome)) continue;
|
|
2129
|
+
const outcome = receipt.outcome;
|
|
2130
|
+
if (!NEAR_REGISTRY_CONTRACTS[net].includes(outcome.executor_id)) continue;
|
|
2131
|
+
const status = outcome.status;
|
|
2132
|
+
if (!object2(status) || Object.hasOwn(status, "Failure") || typeof status.SuccessValue !== "string" && typeof status.SuccessReceiptId !== "string") continue;
|
|
2133
|
+
result.push(...parseRegistryEvents(outcome.logs));
|
|
2134
|
+
}
|
|
2135
|
+
return result;
|
|
2136
|
+
}
|
|
2137
|
+
var rejectionCodes = [
|
|
2138
|
+
"E18_YA_CALIFICADO" /* E18 */,
|
|
2139
|
+
"E20_GET_PAYMENT_FALLO" /* E20 */,
|
|
2140
|
+
"E21_RESPUESTA_INVALIDA" /* E21 */,
|
|
2141
|
+
"E22_PAGO_INEXISTENTE" /* E22 */,
|
|
2142
|
+
"E23_PAGO_SIN_LIBERAR" /* E23 */,
|
|
2143
|
+
"E24_NO_ES_PARTE" /* E24 */,
|
|
2144
|
+
"E25_AUTO_CALIFICACION" /* E25 */,
|
|
2145
|
+
"E26_REEMPLAZADO" /* E26 */
|
|
2146
|
+
];
|
|
2147
|
+
function panic(value) {
|
|
2148
|
+
const text = typeof value === "string" ? value : JSON.stringify(value);
|
|
2149
|
+
const number = text?.match(/ARRAS_REG_(E[0-9]{2}):/)?.[1];
|
|
2150
|
+
const code = Object.values(RegistryErrorCode).find((c) => c.slice(0, 3) === number);
|
|
2151
|
+
if (code) return { status: "error", code, message: text };
|
|
2152
|
+
return void 0;
|
|
2153
|
+
}
|
|
2154
|
+
function parseGiveFeedbackOutcome(outcome) {
|
|
2155
|
+
let value = outcome;
|
|
2156
|
+
let logs = [];
|
|
2157
|
+
if (typeof outcome === "string") {
|
|
2158
|
+
const error = panic(outcome);
|
|
2159
|
+
if (error) return error;
|
|
2160
|
+
}
|
|
2161
|
+
if (object2(outcome)) {
|
|
2162
|
+
if (object2(outcome.status) && Object.hasOwn(outcome.status, "Failure")) {
|
|
2163
|
+
const error = panic(outcome.status.Failure);
|
|
2164
|
+
if (error) return error;
|
|
2165
|
+
throw new Error("NEAR transaction failed without a registry code");
|
|
2166
|
+
}
|
|
2167
|
+
if (object2(outcome.status) && typeof outcome.status.SuccessValue === "string") {
|
|
2168
|
+
value = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(fromBase64(outcome.status.SuccessValue)));
|
|
2169
|
+
if (Array.isArray(outcome.receipts_outcome)) {
|
|
2170
|
+
logs = outcome.receipts_outcome.flatMap((r) => object2(r) && object2(r.outcome) && Array.isArray(r.outcome.logs) ? r.outcome.logs : []);
|
|
2171
|
+
}
|
|
2172
|
+
} else if (Object.hasOwn(outcome, "value")) {
|
|
2173
|
+
value = outcome.value;
|
|
2174
|
+
logs = Array.isArray(outcome.logs) ? outcome.logs : [];
|
|
2175
|
+
} else throw new Error("Expected final give_feedback outcome");
|
|
2176
|
+
}
|
|
2177
|
+
if (u32(value)) return { status: "accepted", feedbackId: value };
|
|
2178
|
+
if (value === null) {
|
|
2179
|
+
const codes = new Set(logs.filter((l) => typeof l === "string").filter((l) => l.startsWith("arras-registry:rechazo:")).map((l) => l.slice(23)));
|
|
2180
|
+
if (codes.size === 1) {
|
|
2181
|
+
const code = [...codes][0];
|
|
2182
|
+
if (rejectionCodes.includes(code)) return { status: "rejected", code };
|
|
2183
|
+
}
|
|
2184
|
+
}
|
|
2185
|
+
throw new Error("Malformed or incomplete give_feedback outcome");
|
|
2186
|
+
}
|
|
2187
|
+
function summarizeFeedback(feedbacks, escrow2, operatorId) {
|
|
2188
|
+
let count = 0, revoked = 0, score = 0n, released = 0n, weighted = 0n;
|
|
2189
|
+
const raters = /* @__PURE__ */ new Set();
|
|
2190
|
+
for (const f of feedbacks) {
|
|
2191
|
+
if (!feedbackCheck(f)) throw new Error("Invalid FeedbackView");
|
|
2192
|
+
if (f.escrow !== escrow2 || f.operator_id !== operatorId) continue;
|
|
2193
|
+
if (f.revoked) {
|
|
2194
|
+
revoked++;
|
|
2195
|
+
continue;
|
|
2196
|
+
}
|
|
2197
|
+
count++;
|
|
2198
|
+
raters.add(f.rater);
|
|
2199
|
+
const amount = BigInt(f.released);
|
|
2200
|
+
score += BigInt(f.score);
|
|
2201
|
+
released += amount;
|
|
2202
|
+
weighted += BigInt(f.score) * amount;
|
|
2203
|
+
}
|
|
2204
|
+
return {
|
|
2205
|
+
count,
|
|
2206
|
+
distinct_raters: raters.size,
|
|
2207
|
+
revoked,
|
|
2208
|
+
released_total: released.toString(),
|
|
2209
|
+
average_x100: count ? Number(score * 100n / BigInt(count)) : null,
|
|
2210
|
+
weighted_average_x100: released ? Number(weighted * 100n / released) : null
|
|
2211
|
+
};
|
|
2212
|
+
}
|
|
2213
|
+
function safeLink(uri) {
|
|
2214
|
+
return validUri(uri) && /^(https|ipfs|ar):/i.test(uri) ? uri : null;
|
|
2215
|
+
}
|
|
2216
|
+
function displayText(s) {
|
|
2217
|
+
return s.replace(/[\p{Cc}\p{Cf}\p{Cs}\p{Default_Ignorable_Code_Point}]/gu, "");
|
|
2218
|
+
}
|
|
1729
2219
|
|
|
1730
2220
|
// src/providers/near/index.ts
|
|
1731
2221
|
var NEAR_CONFIG = {
|
|
@@ -1806,7 +2296,7 @@ function serializeSignedDelegateAction(delegateActionBytes, signatureBytes) {
|
|
|
1806
2296
|
ser.writeFixedBytes(signatureBytes);
|
|
1807
2297
|
return ser.getBytes();
|
|
1808
2298
|
}
|
|
1809
|
-
async function
|
|
2299
|
+
async function sha2564(data) {
|
|
1810
2300
|
const hashBuffer = await crypto.subtle.digest("SHA-256", data);
|
|
1811
2301
|
return new Uint8Array(hashBuffer);
|
|
1812
2302
|
}
|
|
@@ -2050,7 +2540,7 @@ var NEARProvider = class {
|
|
|
2050
2540
|
const hashInput = new Uint8Array(NEP366_PREFIX.length + delegateActionBytes.length);
|
|
2051
2541
|
hashInput.set(NEP366_PREFIX, 0);
|
|
2052
2542
|
hashInput.set(delegateActionBytes, NEP366_PREFIX.length);
|
|
2053
|
-
const delegateHash = await
|
|
2543
|
+
const delegateHash = await sha2564(hashInput);
|
|
2054
2544
|
const signature = await this.signMessage(delegateHash);
|
|
2055
2545
|
const signedDelegateActionBytes = serializeSignedDelegateAction(
|
|
2056
2546
|
delegateActionBytes,
|
|
@@ -2258,30 +2748,59 @@ var NEARProvider = class {
|
|
|
2258
2748
|
};
|
|
2259
2749
|
var near_default = NEARProvider;
|
|
2260
2750
|
|
|
2751
|
+
exports.FEEDBACK_DEPOSIT = FEEDBACK_DEPOSIT;
|
|
2752
|
+
exports.GIVE_FEEDBACK_GAS = GIVE_FEEDBACK_GAS;
|
|
2753
|
+
exports.MIN_GIVE_FEEDBACK_GAS = MIN_GIVE_FEEDBACK_GAS;
|
|
2261
2754
|
exports.NEARProvider = NEARProvider;
|
|
2262
2755
|
exports.NEAR_ARRAS_STORAGE_DEPOSIT = NEAR_ARRAS_STORAGE_DEPOSIT;
|
|
2263
2756
|
exports.NEAR_ESCROW_CONTRACTS = NEAR_ESCROW_CONTRACTS;
|
|
2264
2757
|
exports.NEAR_ESCROW_MAX_GAS = NEAR_ESCROW_MAX_GAS;
|
|
2265
2758
|
exports.NEAR_ESCROW_MIN_GAS = NEAR_ESCROW_MIN_GAS;
|
|
2266
2759
|
exports.NEAR_ESCROW_TOKENS = NEAR_ESCROW_TOKENS;
|
|
2760
|
+
exports.NEAR_REGISTRY_CONTRACTS = NEAR_REGISTRY_CONTRACTS;
|
|
2761
|
+
exports.NEAR_REGISTRY_ESCROWS = NEAR_REGISTRY_ESCROWS;
|
|
2267
2762
|
exports.NEAR_USDC_STORAGE_DEPOSIT = NEAR_USDC_STORAGE_DEPOSIT;
|
|
2763
|
+
exports.REGISTER_DEPOSIT = REGISTER_DEPOSIT;
|
|
2764
|
+
exports.REGISTRY_GAS = REGISTRY_GAS;
|
|
2765
|
+
exports.RegistryErrorCode = RegistryErrorCode;
|
|
2766
|
+
exports.RegistryValidationError = RegistryValidationError;
|
|
2268
2767
|
exports.buildArrasStorageDeposit = buildArrasStorageDeposit;
|
|
2269
2768
|
exports.buildEscrowAuthorizationDelegate = buildEscrowAuthorizationDelegate;
|
|
2270
2769
|
exports.buildEscrowMsg = buildEscrowMsg;
|
|
2770
|
+
exports.buildGiveFeedback = buildGiveFeedback;
|
|
2771
|
+
exports.buildRegistryRegister = buildRegistryRegister;
|
|
2772
|
+
exports.buildRegistryUpdate = buildRegistryUpdate;
|
|
2773
|
+
exports.buildRevokeFeedback = buildRevokeFeedback;
|
|
2271
2774
|
exports.buildUsdcStorageDeposit = buildUsdcStorageDeposit;
|
|
2272
2775
|
exports.computePaymentId = computePaymentId;
|
|
2273
2776
|
exports.createNearLocalSigner = createNearLocalSigner;
|
|
2274
2777
|
exports.default = near_default;
|
|
2778
|
+
exports.displayText = displayText;
|
|
2779
|
+
exports.getAgent = getAgent;
|
|
2780
|
+
exports.getConfig = getConfig;
|
|
2781
|
+
exports.getFeedback = getFeedback;
|
|
2782
|
+
exports.getFeedbackForPayment = getFeedbackForPayment;
|
|
2783
|
+
exports.getSummary = getSummary;
|
|
2784
|
+
exports.getSummaryByOperator = getSummaryByOperator;
|
|
2785
|
+
exports.isFeedbackPending = isFeedbackPending;
|
|
2786
|
+
exports.listAgents = listAgents;
|
|
2787
|
+
exports.listFeedback = listFeedback;
|
|
2275
2788
|
exports.nep413Preimage = nep413Preimage;
|
|
2276
2789
|
exports.parseArrasEvents = parseArrasEvents;
|
|
2790
|
+
exports.parseGiveFeedbackOutcome = parseGiveFeedbackOutcome;
|
|
2791
|
+
exports.parseRegistryEvents = parseRegistryEvents;
|
|
2792
|
+
exports.parseRegistryReceiptEvents = parseRegistryReceiptEvents;
|
|
2277
2793
|
exports.paymentIdPreimage = paymentIdPreimage;
|
|
2278
2794
|
exports.reclaim = reclaim;
|
|
2279
2795
|
exports.refund = refund;
|
|
2280
2796
|
exports.release = release;
|
|
2797
|
+
exports.safeLink = safeLink;
|
|
2281
2798
|
exports.signEscrowAuthorization = signEscrowAuthorization;
|
|
2282
2799
|
exports.signEscrowLifecycle = signEscrowLifecycle;
|
|
2283
2800
|
exports.signExactNearDelegate = signExactNearDelegate;
|
|
2284
2801
|
exports.signNep413 = signNep413;
|
|
2802
|
+
exports.signRegistryTransaction = signRegistryTransaction;
|
|
2803
|
+
exports.summarizeFeedback = summarizeFeedback;
|
|
2285
2804
|
exports.validateEscrowAuthorizationDelegate = validateEscrowAuthorizationDelegate;
|
|
2286
2805
|
exports.withdraw = withdraw;
|
|
2287
2806
|
exports.withdrawFor = withdrawFor;
|