Skip to content

Commit

Permalink
fix: postage stamp on api
Browse files Browse the repository at this point in the history
  • Loading branch information
nugaon committed Oct 18, 2024
1 parent d3d44cb commit 2f72ab9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ Information Signal class facilitates GSOC data reading based on the passed conse
import { InformationSignal } from '@anythread/gsoc'

beeUrl = 'http://localhost:1633' // Bee API URL to connect p2p storage network
postageBatchId = '0000000000000000000000000000000000000000000000000000000000000000' // for write operations, the Postage Batch ID (64 length hex) or a Postage Stamp (113 length hex) must be set
postage = '0000000000000000000000000000000000000000000000000000000000000000' // for write operations, the Postage Batch ID (64 length hex) or a Postage Stamp (113 length hex) must be set
resourceId = 'demo' // any string/content hash that represents the resource to which the Personal Storage record will be associated.

// initialize object that will read and write the GSOC according to the passed consensus/configuration
informationSignal = new InformationSignal(beeUrl, {
postageBatchId,
postage,
consensus: {
id,
assertRecord,
Expand Down
2 changes: 1 addition & 1 deletion src/http-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import axios, { AxiosAdapter, AxiosError, AxiosRequestConfig, AxiosResponse } fr
*/
export async function uploadSingleOwnerChunkData(
requestOptions: BeeRequestOptions,
postageBatchId: PostageBatchId,
postageBatchId: PostageBatchId | PostageStamp,
signer: SignerFn,
identifier: Bytes<32>,
payload: Uint8Array,
Expand Down
15 changes: 8 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { gsocSubscribe, SubscriptionHandler, uploadSingleOwnerChunkData } from './http-client'
import { makeSOCAddress, SingleOwnerChunk } from './soc'
import { Bytes, Data, HexString, PostageBatchId, SignerFn } from './types'
import { Bytes, Data, HexString, PostageBatchId, PostageStamp, SignerFn } from './types'
import {
bytesToHex,
getConsensualPrivateKey,
Expand All @@ -21,7 +21,7 @@ const DEFAULT_CONSENSUS_ID = 'SimpleGraffiti:v1' // used at information signalin
* InformationSignal is for reading and writing a GSOC topic
*/
export class InformationSignal<UserPayload = InformationSignalRecord> {
public postageBatchId: PostageBatchId
public postage: PostageBatchId | PostageStamp
private beeApiUrl: string
/** Graffiti Identifier */
private consensusHash: Bytes<32>
Expand All @@ -30,12 +30,12 @@ export class InformationSignal<UserPayload = InformationSignalRecord> {
constructor(beeApiUrl: string, options?: BaseConstructorOptions<UserPayload>) {
assertBeeUrl(beeApiUrl)
this.beeApiUrl = beeApiUrl
this.postageBatchId = (options?.postageBatchId ?? DEFAULT_POSTAGE_BATCH_ID) as PostageBatchId
this.postage = (options?.postage ?? DEFAULT_POSTAGE_BATCH_ID) as PostageBatchId
this.assertGraffitiRecord = options?.consensus?.assertRecord ?? assertInformationSignalRecord
this.consensusHash = keccak256Hash(options?.consensus?.id ?? DEFAULT_CONSENSUS_ID)

if (!isHexString(this.postageBatchId)) {
throw new Error('Postage batch ID has to be a hex string!')
if (!isHexString(this.postage)) {
throw new Error('Postage batch id or postage stamp has to be a hex string!')
}
}

Expand Down Expand Up @@ -109,7 +109,7 @@ export class InformationSignal<UserPayload = InformationSignalRecord> {

return uploadSingleOwnerChunkData(
{ baseURL: this.beeApiUrl },
this.postageBatchId,
this.postage,
graffitiSigner,
this.consensusHash,
serializePayload(data),
Expand Down Expand Up @@ -256,9 +256,10 @@ interface BaseConstructorOptions<T = InformationSignalRecord> {
}
/**
* Swarm Postage Batch ID which is only required when write happens
* It can be the serialized Postage Stamp as well (envelope API EP)
* Default: 000000000000000000000000000000000000000000000
*/
postageBatchId?: string
postage?: string
/**
* API Url of the Ethereum Swarm Bee client
* Default: http://localhost:1633
Expand Down

0 comments on commit 2f72ab9

Please sign in to comment.