feat: replace DataItem and Signer classes with warp-arbundles implementation (#434)

This commit is contained in:
Asia
2023-06-30 14:56:59 +02:00
committed by GitHub
parent 2c68d7c382
commit 0863c25554
6 changed files with 7 additions and 50 deletions

View File

@@ -402,7 +402,6 @@ export class HandlerBasedContract<State> implements Contract<State> {
await interactionDataItem.sign(bundlerSigner);
}
// TODO: for ethereum owner is set to public key and not the address!!
if (!this._evaluationOptions.internalWrites && strict) {
await this.checkInteractionInStrictMode(interactionDataItem.owner, input, tags, transfer, strict, vrf);
}

View File

@@ -2,7 +2,7 @@ import { JWKInterface } from 'arweave/node/lib/wallet';
import { WarpPluginType } from '../../core/WarpPlugin';
import { EvaluationOptions } from '../../core/modules/StateEvaluator';
import { Source } from './Source';
import { BundlerSigner } from './DataItem';
import { Signer } from 'warp-arbundles';
import { CustomSignature } from '../Signature';
import { Tag } from '../../utils/types/arweave-types';
@@ -31,13 +31,13 @@ export const BUNDLR_NODES = ['node1', 'node2'] as const;
export type BundlrNodeType = (typeof BUNDLR_NODES)[number];
export interface CommonContractData {
wallet: ArWallet | CustomSignature | BundlerSigner;
wallet: ArWallet | CustomSignature | Signer;
initState: string;
tags?: Tags;
transfer?: ArTransfer;
data?: {
'Content-Type': string;
body: string | Uint8Array;
body: string | Buffer;
};
evaluationManifest?: EvaluationManifest;
}

View File

@@ -1,41 +0,0 @@
import { Tag } from '../../utils/types/arweave-types';
/* eslint-disable */
export declare abstract class BundlerSigner {
readonly signer?: any;
readonly publicKey: Buffer;
readonly signatureType: number;
readonly signatureLength: number;
readonly ownerLength: number;
readonly pem?: string | Buffer;
abstract sign(message: Uint8Array): Promise<Uint8Array> | Uint8Array;
abstract signDataItem?(dataItem: string | Buffer | Uint8Array, tags: Tag[]): Promise<DataItem>;
static verify(_: string | Buffer): boolean;
}
type ResolvesTo<T> = T | Promise<T> | ((...args: any[]) => Promise<T>);
export abstract class DataItem {
readonly id: string;
readonly signatureType: ResolvesTo<number>;
readonly rawSignature: ResolvesTo<Buffer>;
readonly signature: ResolvesTo<string>;
readonly signatureLength: ResolvesTo<number>;
readonly rawOwner: ResolvesTo<Buffer>;
readonly owner: ResolvesTo<string>;
readonly ownerLength: ResolvesTo<number>;
readonly rawTarget: ResolvesTo<Buffer>;
readonly target: ResolvesTo<string>;
readonly rawAnchor: ResolvesTo<Buffer>;
readonly anchor: ResolvesTo<string>;
readonly rawTags: ResolvesTo<Buffer>;
readonly tags: ResolvesTo<{ name: string; value: string }[]>;
readonly rawData: ResolvesTo<Buffer>;
readonly data: ResolvesTo<string>;
abstract sign(signer: BundlerSigner): Promise<Buffer>;
abstract isValid(): Promise<boolean>;
static async verify(..._: any[]): Promise<boolean> {
throw new Error('You must implement `verify`');
}
abstract getRaw(): Buffer;
}

View File

@@ -1,7 +1,7 @@
import { ArWallet } from './CreateContract';
import { CustomSignature } from '../../contract/Signature';
import { Transaction } from '../../utils/types/arweave-types';
import { BundlerSigner, DataItem } from './DataItem';
import { Signer, DataItem } from 'warp-arbundles';
export interface SourceData {
src: string | Buffer;
@@ -23,7 +23,7 @@ export interface Source {
*/
createSource(
sourceData: SourceData,
wallet: ArWallet | CustomSignature | BundlerSigner,
wallet: ArWallet | CustomSignature | Signer,
disableBundling?: boolean
): Promise<DataItem | Transaction>;

View File

@@ -32,7 +32,7 @@ import { Transaction } from '../utils/types/arweave-types';
import { DEFAULT_LEVEL_DB_LOCATION, WARP_GW_URL } from './WarpFactory';
import { LevelDbCache } from '../cache/impl/LevelDbCache';
import { SourceData } from '../contract/deploy/Source';
import { BundlerSigner, DataItem } from '../contract/deploy/DataItem';
import { Signer, DataItem } from 'warp-arbundles';
import { BasicSortKeyCache } from '../cache/BasicSortKeyCache';
export type WarpEnvironment = 'local' | 'testnet' | 'mainnet' | 'custom';
@@ -121,7 +121,7 @@ export class Warp {
async createSource(
sourceData: SourceData,
wallet: ArWallet | CustomSignature | BundlerSigner,
wallet: ArWallet | CustomSignature | Signer,
disableBundling = false
): Promise<Transaction | DataItem> {
return await this.createContract.createSource(sourceData, wallet, disableBundling);

View File

@@ -53,7 +53,6 @@ export * from './contract/Signature';
export * from './contract/EvaluationOptionsEvaluator';
export * from './contract/deploy/Source';
export * from './contract/deploy/CreateContract';
export * from './contract/deploy/DataItem';
export * from './legacy/gqlResult';
export * from './legacy/smartweave-global';