Skip to content

Instantly share code, notes, and snippets.

@robertDurst
Last active May 29, 2018 21:24
Show Gist options
  • Save robertDurst/78df79857e3b57e89f8dec5731fea400 to your computer and use it in GitHub Desktop.
Save robertDurst/78df79857e3b57e89f8dec5731fea400 to your computer and use it in GitHub Desktop.

Revisions

  1. Robert Durst revised this gist May 29, 2018. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion SEP007.md
    Original file line number Diff line number Diff line change
    @@ -19,4 +19,6 @@ Here is the code change (works for both second and third approaches):
    if (publicKey === "00000000000000000000000000000000" || !publicKey) {
    return new this({type: 'ed25519', publicKey: "00000000000000000000000000000000"});
    }
    ```
    ```

    This code would be inserted [here](https://github.com/stellar/js-stellar-base/blob/master/src/keypair.js#L107).
  2. Robert Durst revised this gist May 29, 2018. 1 changed file with 9 additions and 2 deletions.
    11 changes: 9 additions & 2 deletions SEP007.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,14 @@
    # SEP007
    # SEP007 Stellar-JS-SDK Integration

    ## Background
    As part of the protocol outlined in SEP007, to create a uri without a known source account beforehand, you must specify the source account in the XDR as all zeros.

    > xdr (required) - A Stellar transaction in XDR format that is base64 encoded and then URL-encoded. If the source account in the xdr is all zeros then the URI handler should replace the source account and sequence number with the user's source account and sequence number before it signs it. If the source account is set and the sequence number is 0 then the URI handler should replace only the sequence number before signing.
    Currently this is not possible in the Stellar-JS-SDK.

    ## Overview
    Here I present three possible approaches for integrating SEP007 into the Stellar-JS-SDK.
    Here I present three possible approaches for integrating SEP007 into the Stellar-JS-SDK. Each approach is briefly described and then presented below.

    Regarding the **first** approach, Nikhil said the reference implementation is not correct... so disregard that.

  3. Robert Durst revised this gist May 29, 2018. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions SEP007.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,8 @@
    # SEP007

    ## Overview
    Here I present three possible approaches for integrating SEP007 into the Stellar-JS-SDK.

    Regarding the **first** approach, Nikhil said the reference implementation is not correct... so disregard that.

    From the **second** and **third** approaches, I think that the second approach may be the best. The reason here is that the changes I had to make for the third to work are a little iffy -- I had to accept an empty public key which may be added accidentally versus `"00000000000000000000000000000000"` is a more intentional addition.
  4. Robert Durst revised this gist May 29, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions SEP007.md
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    # SEP007

    Regarding the first approach, Nikhil said the reference implementation is not correct... so disregard that.
    Regarding the **first** approach, Nikhil said the reference implementation is not correct... so disregard that.

    From the second and third approaches, I think that the second approach may be the best. The reason here is that the changes I had to make for the third to work are a little iffy -- I had to accept an empty public key which may be added accidentally versus `"00000000000000000000000000000000"` is a more intentional addition.
    From the **second** and **third** approaches, I think that the second approach may be the best. The reason here is that the changes I had to make for the third to work are a little iffy -- I had to accept an empty public key which may be added accidentally versus `"00000000000000000000000000000000"` is a more intentional addition.

    Here is the code change (works for both second and third approaches):
    ```js
  5. Robert Durst revised this gist May 29, 2018. 1 changed file with 10 additions and 1 deletion.
    11 changes: 10 additions & 1 deletion SEP007.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,12 @@
    # SEP007

    Regarding the first approach, Nikhil said the reference implementation is not correct... so disregard that.

    From the second and third approaches, I think that the second approach may be the best. The reason here is that the changes I had to make for the third to work are a little iffy -- I had to accept an empty public key which may be added accidentally versus "00000000000000000000000000000000" is a more intentional addition.
    From the second and third approaches, I think that the second approach may be the best. The reason here is that the changes I had to make for the third to work are a little iffy -- I had to accept an empty public key which may be added accidentally versus `"00000000000000000000000000000000"` is a more intentional addition.

    Here is the code change (works for both second and third approaches):
    ```js
    if (publicKey === "00000000000000000000000000000000" || !publicKey) {
    return new this({type: 'ed25519', publicKey: "00000000000000000000000000000000"});
    }
    ```
  6. Robert Durst renamed this gist May 29, 2018. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  7. Robert Durst revised this gist May 29, 2018. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions Thoughts.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    Regarding the first approach, Nikhil said the reference implementation is not correct... so disregard that.

    From the second and third approaches, I think that the second approach may be the best. The reason here is that the changes I had to make for the third to work are a little iffy -- I had to accept an empty public key which may be added accidentally versus "00000000000000000000000000000000" is a more intentional addition.
  8. Robert Durst revised this gist May 29, 2018. 3 changed files with 30 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions sep007_approach_1.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,9 @@
    /*
    In the first approach, no changes need to be made to the existing stellar js sdk.
    In this approach I mimick the Go reference implementation and use the master
    keypair of the empty string network passphrase.
    */

    // 1. build the partial transaction (excludes the source account and sequence numbers
    // Define an empty address
    s.Network.use(new s.Network(""));
    12 changes: 12 additions & 0 deletions sep007_approach_2.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,15 @@
    /*
    This second approach is identical to the first, however the empty address
    keypair generation is different. Here I define an empty public key as the
    public key created from the string of 32 zeros.
    In order to make this work, I had to make one change to the js stellar sdk
    codebase. In the keypair.js file, I added a case to the fromPublicKey method
    that accepts "00000000000000000000000000000000" and returns a keypair generated
    from this string. This adds three lines of code.
    */


    // 1. build the partial transaction (excludes the source account and sequence numbers
    // Define an empty address
    const emptyAddress_a2 = s.Keypair.fromPublicKey("00000000000000000000000000000000").publicKey();
    12 changes: 12 additions & 0 deletions sep007_approach_3.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,15 @@
    /*
    This third approach is nearly identical to the second. The only difference is
    here I define an empty public key as the public key created from the empty
    string.
    In order to make this work, I had to make one change to the js stellar sdk
    codebase. In the keypair.js file, I added a case to the fromPublicKey method
    that accepts "" and returns a keypair generated from the
    "00000000000000000000000000000000" string. This adds three lines of code.
    */


    // 1. build the partial transaction (excludes the source account and sequence numbers
    // Define an empty address
    const emptyAddress_a3 = s.Keypair.fromPublicKey("").publicKey();
  9. Robert Durst created this gist May 29, 2018.
    36 changes: 36 additions & 0 deletions sep007_approach_1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    // 1. build the partial transaction (excludes the source account and sequence numbers
    // Define an empty address
    s.Network.use(new s.Network(""));
    const emptyAddress_a1 = s.Keypair.master().publicKey();

    // Define an account
    const account_a1 = new s.Account(emptyAddress_a1, "0");

    // Define a transaction object
    let tx_a1 = new s.TransactionBuilder(account_a1);

    // Add payment operation
    tx_a1.addOperation(s.Operation.payment({
    destination: "GASIA4ZTLZEF4TRLLDQCQIT43KNZKSAEU3PX3BQVNEZVNJ4FM7LBIPTK",
    asset: s.Asset.native(),
    amount: "1",
    }))

    // Add a memo if included (Optional)
    tx_a1.addMemo(s.Memo.text("SEP, SEP 007"));

    // 2. Convert to a transaction envelope
    tx_a1 = tx_a1.build().toEnvelope();

    // 3. Convert to Base64
    tx_a1 = tx_a1.toXDR('base64');

    // 4. Url encode (Optional)
    const url_a1 = encodeURIComponent(tx_a1);

    // 5. Print out ("web+stellar:tx?xdr=" + urlEncoded) (Optional)
    console.log(`web+stellar:tx?xdr=${url_a1}`);
    /*
    Result:
    web+stellar:tx?xdr=AAAAAL6Qe0ushP7lzogR2y3vyb8LKiorvD1U2KIlfs1wRBliAAAAZAAAAAAAAAABAAAAAAAAAAEAAAAMU0VQLCBTRVAgMDA3AAAAAQAAAAAAAAABAAAAACSAczNeSF5OK1jgKCJ82puVSASm332GFWkzVqeFZ9YUAAAAAAAAAAAAmJaAAAAAAAAAAAA%3D
    */
    35 changes: 35 additions & 0 deletions sep007_approach_2.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    // 1. build the partial transaction (excludes the source account and sequence numbers
    // Define an empty address
    const emptyAddress_a2 = s.Keypair.fromPublicKey("00000000000000000000000000000000").publicKey();

    // Define an account
    const account_a2 = new s.Account(emptyAddress_a2, "0");

    // Define a transaction object
    let tx_a2 = new s.TransactionBuilder(account_a2);

    // Add payment operation
    tx_a2.addOperation(s.Operation.payment({
    destination: "GASIA4ZTLZEF4TRLLDQCQIT43KNZKSAEU3PX3BQVNEZVNJ4FM7LBIPTK",
    asset: s.Asset.native(),
    amount: "1",
    }))

    // Add a memo if included (Optional)
    // tx_a2.addMemo(s.Memo.text("SEP, SEP 007"));

    // 2. Convert to a transaction envelope
    tx_a2 = tx_a2.build().toEnvelope();

    // 3. Convert to Base64
    tx_a2 = tx_a2.toXDR('base64');

    // 4. Url encode (Optional)
    const url_a2 = encodeURIComponent(tx_a2);

    // 5. Print out ("web+stellar:tx?xdr=" + urlEncoded) (Optional)
    // console.log(`web+stellar:tx?xdr=${url_a2}`);
    /*
    Result:
    web+stellar:tx?xdr=AAAAADAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwAAAAZAAAAAAAAAABAAAAAAAAAAAAAAABAAAAAAAAAAEAAAAAJIBzM15IXk4rWOAoInzam5VIBKbffYYVaTNWp4Vn1hQAAAAAAAAAAACYloAAAAAAAAAAAA%3D%3D
    */
    35 changes: 35 additions & 0 deletions sep007_approach_3.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    // 1. build the partial transaction (excludes the source account and sequence numbers
    // Define an empty address
    const emptyAddress_a3 = s.Keypair.fromPublicKey("").publicKey();

    // Define an account
    const account_a3 = new s.Account(emptyAddress_a3, "0");

    // Define a transaction object
    let tx_a3 = new s.TransactionBuilder(account_a3);

    // Add payment operation
    tx_a3.addOperation(s.Operation.payment({
    destination: "GASIA4ZTLZEF4TRLLDQCQIT43KNZKSAEU3PX3BQVNEZVNJ4FM7LBIPTK",
    asset: s.Asset.native(),
    amount: "1",
    }))

    // Add a memo if included (Optional)
    // tx_a2.addMemo(s.Memo.text("SEP, SEP 007"));

    // 2. Convert to a transaction envelope
    tx_a3 = tx_a3.build().toEnvelope();

    // 3. Convert to Base64
    tx_a3 = tx_a3.toXDR('base64');

    // 4. Url encode (Optional)
    const url_a3 = encodeURIComponent(tx_a3);

    // 5. Print out ("web+stellar:tx?xdr=" + urlEncoded) (Optional)
    // console.log(`web+stellar:tx?xdr=${url_a3}`);
    /*
    Result:
    web+stellar:tx?xdr=AAAAADAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwAAAAZAAAAAAAAAABAAAAAAAAAAAAAAABAAAAAAAAAAEAAAAAJIBzM15IXk4rWOAoInzam5VIBKbffYYVaTNWp4Vn1hQAAAAAAAAAAACYloAAAAAAAAAAAA%3D%3D
    */