Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
eff50d4
feat: Random clientDataSetId (#298)
wjmelements Oct 10, 2025
33cda75
Merge remote-tracking branch 'origin/master' into update-abi
wjmelements Oct 10, 2025
89b6fc8
feat: Update ABI (#303)
wjmelements Oct 11, 2025
6557daf
Merge remote-tracking branch 'origin/master' into next
wjmelements Oct 13, 2025
35d247a
Merge remote-tracking branch 'origin/master' into next
wjmelements Oct 14, 2025
4745ea6
SessionKeyRegistry.login: origin (#318)
wjmelements Oct 15, 2025
f250f64
excludeProviderIds (#317)
wjmelements Oct 15, 2025
1e3a5b4
wip
wjmelements Oct 15, 2025
46cb269
createWithSelectedProvider
wjmelements Oct 15, 2025
b32e85c
wip
wjmelements Oct 16, 2025
633bfdf
chore: update to M3 calibnet contracts in next-branch (#319)
rjan90 Oct 16, 2025
87bb94c
use ADDRESSES.calibration.spRegistry
wjmelements Oct 16, 2025
74b98f9
fix sp-registry-service-test mocking
wjmelements Oct 16, 2025
9c7ba74
setupProviderRegistryMocks
wjmelements Oct 17, 2025
2342ab1
mockServiceProviderRegistry
wjmelements Oct 17, 2025
e0c5a27
remove other getProviderProducts mocking
wjmelements Oct 17, 2025
4bdb0eb
fix mockServiceProviderRegistry
wjmelements Oct 18, 2025
74dfb55
mock createDataSet handler
wjmelements Oct 18, 2025
32e108b
select by providerAddresses
wjmelements Oct 18, 2025
a31dc6a
Merge branch 'next' into create-contexts
wjmelements Oct 21, 2025
5dc991a
resolveByDataSetId
wjmelements Oct 21, 2025
62d1a45
test: fails when provided an invalid data set id
wjmelements Oct 21, 2025
f1dd119
test: fails when provided an invalid provider address
wjmelements Oct 21, 2025
5570bb6
test: fails when provided an invalid providerId
wjmelements Oct 22, 2025
9b39c40
mock failed batch jsonrpc result with message id
wjmelements Oct 22, 2025
cc84686
error message must match /revert/i or it will fail to spelunk in ethers
wjmelements Oct 22, 2025
6298076
code is 11
wjmelements Oct 22, 2025
1031705
expect the error
wjmelements Oct 22, 2025
6393997
private createWithSelectedProvider
wjmelements Oct 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
763 changes: 583 additions & 180 deletions packages/synapse-sdk/src/abis/gen.ts

Large diffs are not rendered by default.

13 changes: 6 additions & 7 deletions packages/synapse-sdk/src/payments/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -919,16 +919,15 @@ export class PaymentsService {
try {
// Use staticCall to simulate the transaction and get the return values
// Include the settlement fee (NETWORK_FEE in contract) in the simulation
const result = await paymentsContract.settleRail.staticCall(railIdBigint, untilEpochBigint, {
value: SETTLEMENT_FEE,
})
const result = await paymentsContract.settleRail.staticCall(railIdBigint, untilEpochBigint)

return {
totalSettledAmount: result[0],
totalNetPayeeAmount: result[1],
totalOperatorCommission: result[2],
finalSettledEpoch: result[3],
note: result[4],
totalNetworkFee: result[3],
finalSettledEpoch: result[4],
note: result[5],
}
} catch (error) {
throw createError(
Expand Down Expand Up @@ -1075,7 +1074,7 @@ export class PaymentsService {
const paymentsContract = this._getPaymentsContract()

try {
const rails = await paymentsContract.getRailsForPayerAndToken(signerAddress, this._usdfcAddress)
const [rails] = await paymentsContract.getRailsForPayerAndToken(signerAddress, this._usdfcAddress, 0n, 0n)

return rails.map((rail: any) => ({
railId: Number(rail.railId),
Expand Down Expand Up @@ -1105,7 +1104,7 @@ export class PaymentsService {
const paymentsContract = this._getPaymentsContract()

try {
const rails = await paymentsContract.getRailsForPayeeAndToken(signerAddress, this._usdfcAddress)
const [rails] = await paymentsContract.getRailsForPayeeAndToken(signerAddress, this._usdfcAddress, 0n, 0n)

return rails.map((rail: any) => ({
railId: Number(rail.railId),
Expand Down
16 changes: 13 additions & 3 deletions packages/synapse-sdk/src/pdp/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export class PDPServer {
* @returns Promise that resolves with transaction hash and status URL
*/
async createDataSet(
clientDataSetId: number,
clientDataSetId: number | bigint,
payee: string,
payer: string,
metadata: MetadataEntry[],
Expand All @@ -198,6 +198,7 @@ export class PDPServer {
// This needs to match the DataSetCreateData struct in Warm Storage contract
const extraData = this._encodeDataSetCreateData({
payer,
clientDataSetId,
metadata,
signature: authData.signature,
})
Expand Down Expand Up @@ -669,20 +670,29 @@ export class PDPServer {
* Encode DataSetCreateData for extraData field
* This matches the Solidity struct DataSetCreateData in Warm Storage contract
*/
private _encodeDataSetCreateData(data: { payer: string; metadata: MetadataEntry[]; signature: string }): string {
private _encodeDataSetCreateData(data: {
payer: string
clientDataSetId: number | bigint
metadata: MetadataEntry[]
signature: string
}): string {
// Ensure signature has 0x prefix
const signature = data.signature.startsWith('0x') ? data.signature : `0x${data.signature}`

// ABI encode the struct as a tuple
// DataSetCreateData struct:
// - address payer
// - uint256 clientDataSetId
// - string[] metadataKeys
// - string[] metadataValues
// - bytes signature
const keys = data.metadata.map((item) => item.key)
const values = data.metadata.map((item) => item.value)
const abiCoder = ethers.AbiCoder.defaultAbiCoder()
const encoded = abiCoder.encode(['address', 'string[]', 'string[]', 'bytes'], [data.payer, keys, values, signature])
const encoded = abiCoder.encode(
['address', 'uint256', 'string[]', 'string[]', 'bytes'],
[data.payer, data.clientDataSetId, keys, values, signature]
)

// Return hex string without 0x prefix (since we add it in the calling code)
return encoded.slice(2)
Expand Down
13 changes: 10 additions & 3 deletions packages/synapse-sdk/src/session/key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* const expiries = await sessionKey.fetchExpiries([ADD_PIECES_TYPEHASH])
* if (expiries[ADD_PIECES_TYPEHASH] * BigInt(1000) < BigInt(Date.now()) + HOUR_MILLIS) {
* const DAY_MILLIS = BigInt(24) * HOUR_MILLIS
* const loginTx = await sessionKey.login(BigInt(Date.now()) / BigInt(1000 + 30 * DAY_MILLIS), PDP_PERMISSIONS)
* const loginTx = await sessionKey.login(BigInt(Date.now()) / BigInt(1000 + 30 * DAY_MILLIS), PDP_PERMISSIONS, "example.com")
* const loginReceipt = await loginTx.wait()
* }
* synapse.setSession(sessionKey)
Expand Down Expand Up @@ -46,6 +46,8 @@ export const PDP_PERMISSION_NAMES: Record<string, string> = {
[DELETE_DATA_SET_TYPEHASH]: 'DeleteDataSet',
}

const DEFAULT_ORIGIN: string = (globalThis as any).location?.hostname || 'unknown'

export class SessionKey {
private readonly _provider: ethers.Provider
private readonly _registry: ethers.Contract
Expand Down Expand Up @@ -122,10 +124,15 @@ export class SessionKey {
*
* @param expiry unix time (block.timestamp) that the permissions expire
* @param permissions list of permissions granted to the signer, as a list of bytes32 hex strings
* @param origin the name of the application prompting this login
* @return signed and broadcasted login transaction details
*/
async login(expiry: bigint, permissions: string[] = PDP_PERMISSIONS): Promise<ethers.TransactionResponse> {
return await this._registry.login(await this._signer.getAddress(), expiry, permissions)
async login(
expiry: bigint,
permissions: string[] = PDP_PERMISSIONS,
origin = DEFAULT_ORIGIN
): Promise<ethers.TransactionResponse> {
return await this._registry.login(await this._signer.getAddress(), expiry, permissions, origin)
}

/**
Expand Down
22 changes: 11 additions & 11 deletions packages/synapse-sdk/src/sp-registry/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,14 @@ export class SPRegistryService {
const contract = this._getRegistryContract()
const rawProvider = await contract.getProvider(providerId)

if (rawProvider.serviceProvider === ethers.ZeroAddress) {
if (rawProvider.info.serviceProvider === ethers.ZeroAddress) {
return null
}

// Get products for this provider
const products = await this._getProviderProducts(providerId)

return this._convertToProviderInfo(providerId, rawProvider, products)
return this._convertToProviderInfo(providerId, rawProvider.info, products)
} catch (error) {
if (error instanceof Error && error.message.includes('Provider not found')) {
return null
Expand All @@ -211,15 +211,15 @@ export class SPRegistryService {
])

// Check if provider exists (beneficiary address will be zero if not found)
if (rawProvider.serviceProvider === ethers.ZeroAddress) {
if (rawProvider.info.serviceProvider === ethers.ZeroAddress) {
return null
}

// Get products for this provider
const products = await this._getProviderProducts(Number(providerId))

// Convert to ProviderInfo
return this._convertToProviderInfo(Number(providerId), rawProvider, products)
return this._convertToProviderInfo(Number(providerId), rawProvider.info, products)
} catch {
return null
}
Expand Down Expand Up @@ -569,7 +569,7 @@ export class SPRegistryService {
const products = this._extractProductsFromMulticallResult(results[pdpServiceResultIndex], iface)

// Convert to ProviderInfo
const providerInfo = this._convertToProviderInfo(providerIds[i], rawProvider, products)
const providerInfo = this._convertToProviderInfo(providerIds[i], rawProvider.info, products)
providers.push(providerInfo)
} catch {
// Skip failed decoding
Expand Down Expand Up @@ -695,7 +695,7 @@ export class SPRegistryService {
/**
* Convert raw provider data to ProviderInfo
*/
private _convertToProviderInfo(providerId: number, rawProvider: any, productsArray: ServiceProduct[]): ProviderInfo {
private _convertToProviderInfo(providerId: number, providerInfo: any, productsArray: ServiceProduct[]): ProviderInfo {
// Convert products array to Record for direct access by type
const products: Partial<Record<'PDP', ServiceProduct>> = {}

Expand All @@ -707,11 +707,11 @@ export class SPRegistryService {

return {
id: providerId,
serviceProvider: rawProvider.serviceProvider,
payee: rawProvider.payee,
name: rawProvider.name,
description: rawProvider.description,
active: rawProvider.isActive,
serviceProvider: providerInfo.serviceProvider,
payee: providerInfo.payee,
name: providerInfo.name,
description: providerInfo.description,
active: providerInfo.isActive,
products,
}
}
Expand Down
Loading
Loading