Skip to content

Commit e16c6f8

Browse files
authored
Refactor Naming of Lifetime to TTL (#4)
1 parent 446e16e commit e16c6f8

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/index.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import type { CID } from 'multiformats/cid'
1616

1717
const log = logger('ipns')
1818
const ID_MULTIHASH_CODE = identity.code
19-
const DEFAULT_TTL = BigInt(3.6e+12) // 1 Hour or 3600 Seconds
19+
const DEFAULT_TTL_NS = BigInt(3.6e+12) // 1 Hour or 3600 Seconds
2020

2121
export const namespace = '/ipns/'
2222
export const namespaceLength = namespace.length
@@ -129,7 +129,7 @@ export interface IDKeys {
129129
}
130130

131131
export interface CreateOptions {
132-
lifetimeNs?: bigint
132+
ttlNs?: bigint
133133
v1Compatible?: boolean
134134
}
135135

@@ -143,7 +143,7 @@ export interface CreateV2Options {
143143

144144
const defaultCreateOptions: CreateOptions = {
145145
v1Compatible: true,
146-
lifetimeNs: DEFAULT_TTL
146+
ttlNs: DEFAULT_TTL_NS
147147
}
148148

149149
/**
@@ -170,9 +170,9 @@ export async function create (peerId: PeerId, value: CID | PeerId | string, seq:
170170
// Validity in ISOString with nanoseconds precision and validity type EOL
171171
const expirationDate = new NanoDate(Date.now() + Number(lifetime))
172172
const validityType = IpnsEntry.ValidityType.EOL
173-
const lifetimeNs = typeof options.lifetimeNs === "bigint" ? options.lifetimeNs : DEFAULT_TTL
173+
const ttlNs = typeof options.ttlNs !== "undefined" ? BigInt(options.ttlNs) : DEFAULT_TTL_NS
174174

175-
return _create(peerId, value, seq, validityType, expirationDate.toString(), lifetimeNs, options)
175+
return _create(peerId, value, seq, validityType, expirationDate.toString(), ttlNs, options)
176176
}
177177

178178
/**
@@ -197,9 +197,9 @@ export async function createWithExpiration (peerId: PeerId, value: CID | PeerId
197197
export async function createWithExpiration (peerId: PeerId, value: CID | PeerId | string, seq: number | bigint, expiration: string, options: CreateOptions = defaultCreateOptions): Promise<IPNSRecord> {
198198
const expirationDate = NanoDate.fromString(expiration)
199199
const validityType = IpnsEntry.ValidityType.EOL
200-
const lifetimeNs = typeof options.lifetimeNs === "bigint" ? options.lifetimeNs : DEFAULT_TTL
200+
const ttlNs = typeof options.ttlNs !== "undefined" ? BigInt(options.ttlNs) : DEFAULT_TTL_NS
201201

202-
return _create(peerId, value, seq, validityType, expirationDate.toString(), lifetimeNs, options)
202+
return _create(peerId, value, seq, validityType, expirationDate.toString(), ttlNs, options)
203203
}
204204

205205
const _create = async (peerId: PeerId, value: CID | PeerId | string, seq: number | bigint, validityType: IpnsEntry.ValidityType, validity: string, ttl: bigint, options: CreateOptions = defaultCreateOptions): Promise<IPNSRecord> => {

0 commit comments

Comments
 (0)