import { PublicKey, } from '@solana/web3.js';
import { utils } from '@wormhole-foundation/connect-sdk-solana';
export function deriveEmitterSequenceKey(emitter, wormholeProgramId) {
    return utils.deriveAddress([Buffer.from('Sequence'), new PublicKey(emitter).toBytes()], wormholeProgramId);
}
export async function getSequenceTracker(connection, emitter, wormholeProgramId, commitment) {
    return connection
        .getAccountInfo(deriveEmitterSequenceKey(emitter, wormholeProgramId), commitment)
        .then((info) => SequenceTracker.deserialize(utils.getAccountData(info)));
}
export class SequenceTracker {
    sequence;
    bump;
    emitterType;
    constructor(sequence, bump, emitterType) {
        this.sequence = sequence;
        this.bump = bump;
        this.emitterType = emitterType;
    }
    static deserialize(data) {
        if (data.length !== 8 && data.length !== 10) {
            throw new Error('data.length != 8 or data.length != 10');
        }
        let bump, emitterType;
        const sequence = data.readBigUInt64LE(0);
        if (data.length === 10) {
            bump = data[8];
            emitterType = data[9];
        }
        return new SequenceTracker(sequence, bump, emitterType);
    }
    value() {
        return this.sequence;
    }
}
//# sourceMappingURL=sequence.js.map